├── templates
└── _gitattributes
├── index.js
├── docs
├── demo.gif
└── demo-dest.gif
├── .gitattributes
├── .travis.yml
├── .editorconfig
├── .gitignore
├── generator.js
├── LICENSE
├── package.json
├── .verb.md
├── .eslintrc.json
├── test.js
└── README.md
/templates/_gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | module.exports = require('./generator');
2 |
--------------------------------------------------------------------------------
/docs/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/generate/generate-gitattributes/HEAD/docs/demo.gif
--------------------------------------------------------------------------------
/docs/demo-dest.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/generate/generate-gitattributes/HEAD/docs/demo-dest.gif
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Enforce Unix newlines
2 | * text eol=lf
3 |
4 | # binaries
5 | *.ai binary
6 | *.psd binary
7 | *.jpg binary
8 | *.gif binary
9 | *.png binary
10 | *.jpeg binary
11 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: node_js
3 | node_js:
4 | - '6'
5 | - '5'
6 | - '4'
7 | - '0.12'
8 | - '0.10'
9 | matrix:
10 | fast_finish: true
11 | allow_failures:
12 | - node_js: '4'
13 | - node_js: '0.10'
14 | - node_js: '0.12'
15 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = space
5 | end_of_line = lf
6 | charset = utf-8
7 | indent_size = 2
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
11 | [{**/{actual,fixtures,expected,templates}/**,*.md}]
12 | trim_trailing_whitespace = false
13 | insert_final_newline = false
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # always ignore files
2 | *.DS_Store
3 | *.sublime-*
4 |
5 | # test related, or directories generated by tests
6 | test/actual
7 | actual
8 | coverage
9 |
10 | # npm
11 | node_modules
12 | npm-debug.log
13 |
14 | # misc
15 | _gh_pages
16 | benchmark
17 | bower_components
18 | vendor
19 | temp
20 | tmp
21 | TODO.md
22 |
--------------------------------------------------------------------------------
/generator.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var isValid = require('is-valid-app');
4 |
5 | module.exports = function(app) {
6 | // return if the generator is already registered
7 | if (!isValid(app, 'generate-gitattributes')) return;
8 |
9 | /**
10 | * Generates a `.gitattributes` file to the current working directory. The
11 | * built-in template can be [overridden](#customization).
12 | *
13 | * ```sh
14 | * $ gen gitattributes
15 | * ```
16 | * @name gitattributes
17 | * @api public
18 | */
19 |
20 | app.task('default', ['gitattributes']);
21 | app.task('gitattributes', function(cb) {
22 | return app.src('templates/_gitattributes', { cwd: __dirname })
23 | .pipe(app.conflicts(app.cwd))
24 | .pipe(app.dest(function(file) {
25 | file.basename = '.gitattributes';
26 | return app.cwd;
27 | }))
28 | });
29 | };
30 |
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016, Jon Schlinkert.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "generate-gitattributes",
3 | "description": "Generate a .gitattributes file from the command line when Generate's CLI is installed globally, or use as a plugin or sub-generator in your own generator to make it a continuous part of the build workflow when scaffolding out a new project.",
4 | "version": "0.1.2",
5 | "homepage": "https://github.com/generate/generate-gitattributes",
6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)",
7 | "repository": "generate/generate-gitattributes",
8 | "bugs": {
9 | "url": "https://github.com/generate/generate-gitattributes/issues"
10 | },
11 | "license": "MIT",
12 | "files": [
13 | "generator.js",
14 | "index.js",
15 | "LICENSE",
16 | "README.md",
17 | "templates"
18 | ],
19 | "main": "index.js",
20 | "engines": {
21 | "node": ">=0.10.0"
22 | },
23 | "scripts": {
24 | "test": "mocha"
25 | },
26 | "dependencies": {
27 | "is-valid-app": "^0.2.0"
28 | },
29 | "devDependencies": {
30 | "delete": "^0.3.2",
31 | "generate": "^0.8.3",
32 | "gulp-format-md": "^0.1.9",
33 | "mocha": "^2.5.3",
34 | "npm-install-global": "^0.1.2"
35 | },
36 | "keywords": [
37 | "boilerplate",
38 | "build",
39 | "cli",
40 | "cli-app",
41 | "command-line",
42 | "create",
43 | "dev",
44 | "development",
45 | "framework",
46 | "front",
47 | "frontend",
48 | "generate",
49 | "generate-generator",
50 | "generate-plugin",
51 | "generategenerator",
52 | "generateplugin",
53 | "generator",
54 | "gitattributes",
55 | "init",
56 | "initialize",
57 | "new",
58 | "plugin",
59 | "project",
60 | "projects",
61 | "scaffold",
62 | "scaffolder",
63 | "scaffolding",
64 | "template",
65 | "templates",
66 | "webapp",
67 | "yeoman",
68 | "yo"
69 | ],
70 | "verb": {
71 | "toc": false,
72 | "layout": "generator",
73 | "tasks": [
74 | "readme"
75 | ],
76 | "plugins": [
77 | "gulp-format-md"
78 | ],
79 | "reflinks": [
80 | "assemble",
81 | "base",
82 | "generate",
83 | "generate-dest",
84 | "generate-install",
85 | "gulp",
86 | "verb",
87 | "verb-readme-generator"
88 | ],
89 | "lint": {
90 | "reflinks": true
91 | },
92 | "related": {
93 | "list": []
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/.verb.md:
--------------------------------------------------------------------------------
1 | **Example**
2 |
3 | Templates are [customizable](#customization) and can be overridden.
4 |
5 | 
6 |
7 |
8 |
9 |
10 | ## What is "{%= platform.proper %}"?
11 | {%= include(platform.name + "/what-is-" + platform.name) %}
12 |
13 |
14 |
15 |
16 | ## Command line usage
17 |
18 | ### Install globally
19 | {%= include(platform.name + "/" + platform.configname + "-install") %}
20 |
21 | ### Running {%= name %}
22 |
23 | You should now be able to run `{%= name %}` with the following command:
24 |
25 | ```sh
26 | $ {%= platform.command %} {%= strip(platform.name + '-', name) %}
27 | ```
28 |
29 | **What will happen?**
30 |
31 | Running `$ gen {%= strip(platform.name + '-', name) %}` will run the generator's [default task](#default), which writes a `.gitattributes` file to the current working directory, or the [specified directory](#customization).
32 |
33 | **What you should see in the terminal**
34 |
35 | If completed successfully, you should see both `starting` and `finished` events in the terminal, like the following:
36 |
37 | ```sh
38 | [00:44:21] starting ...
39 | ...
40 | [00:44:22] finished ✔
41 | ```
42 |
43 | If you do not see one or both of those events, please [let us know about it](../../issues).
44 |
45 | ### Help
46 |
47 | To see a general help menu and available commands for {%= platform.proper %}'s CLI, run:
48 |
49 | ```sh
50 | $ {%= platform.command %} help
51 | ```
52 |
53 | ## Running multiple generators
54 |
55 | [generate][] supports running multiple generators at once. Here is an example of a generator that works well with `{%= name %}`.
56 |
57 | ### generate-dest
58 |
59 | Run [generate-dest][] **before** this generator to prompt for the destination directory to use for generated files.
60 |
61 | **Example**
62 |
63 | 
64 |
65 | ## API usage
66 |
67 | Use `{%= name %}` as a [plugin][docs]{plugins.md} in your own [generator][docs]{generators.md}.
68 |
69 | ### Install locally
70 |
71 | {%= include("install-npm", {save: true}) %}
72 |
73 | ### Register as a plugin
74 |
75 | Inside your own [generator][docs]{generators.md}:
76 |
77 | ```js
78 | module.exports = function(app) {
79 | // register {%= name %} as a plugin to add the {%= strip(platform.name + '-', name) %}
80 | // task to your own generator
81 | app.use(require('{%= name %}'));
82 | };
83 | ```
84 |
85 | ### Run tasks
86 |
87 | Programmatically run tasks from `{%= name %}`.
88 |
89 | ```js
90 | module.exports = function(app) {
91 | // adds the `{%= strip(platform.name + '-', name) %}` task to your generator
92 | app.use(require('{%= name %}'));
93 |
94 | // run the `{%= strip(platform.name + '-', name) %}` task
95 | app.task('default', '{%= strip(platform.name + "-", name) %}');
96 | };
97 | ```
98 |
99 | Visit the [generator docs][docs]{generators.md} to learn more about creating, installing, using and publishing generators.
100 |
101 |
102 |
103 |
104 | ## Customization
105 |
106 | The following instructions can be used to override settings in `{%= name %}`. Visit the [Generate documentation][docs]{overriding-defaults.md} to learn about other ways to override defaults.
107 |
108 | ### Destination directory
109 |
110 | To customize the destination directory, install [generate-dest][] globally, then in the command line prefix `dest` before any other {%= platform.configname %} names.
111 |
112 | For example, the following will prompt you for the destination path to use, then pass the result to `{%= name %}`:
113 |
114 | ```sh
115 | $ {%= platform.command %} dest {%= strip(platform.name + '-', name) %}
116 | ```
117 |
118 | ### Overriding templates
119 |
120 | You can override a template by adding a template of the same name to the `templates` directory in user home. For example, to override the `.gitattributes` template, add a template at the following path `~/generate/{%= name %}/templates/.gitattributes`, where `~/` is the user-home directory that `os.homedir()` resolves to on your system.
121 |
122 |
123 | [docs]: {%= platform.docs %}/
124 |
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "ecmaFeatures": {
3 | "modules": true,
4 | "experimentalObjectRestSpread": true
5 | },
6 |
7 | "env": {
8 | "browser": false,
9 | "es6": true,
10 | "node": true,
11 | "mocha": true
12 | },
13 |
14 | "globals": {
15 | "document": false,
16 | "navigator": false,
17 | "window": false
18 | },
19 |
20 | "rules": {
21 | "accessor-pairs": 2,
22 | "arrow-spacing": [2, { "before": true, "after": true }],
23 | "block-spacing": [2, "always"],
24 | "brace-style": [2, "1tbs", { "allowSingleLine": true }],
25 | "comma-dangle": [2, "never"],
26 | "comma-spacing": [2, { "before": false, "after": true }],
27 | "comma-style": [2, "last"],
28 | "constructor-super": 2,
29 | "curly": [2, "multi-line"],
30 | "dot-location": [2, "property"],
31 | "eol-last": 2,
32 | "eqeqeq": [2, "allow-null"],
33 | "generator-star-spacing": [2, { "before": true, "after": true }],
34 | "handle-callback-err": [2, "^(err|error)$" ],
35 | "indent": [2, 2, { "SwitchCase": 1 }],
36 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }],
37 | "keyword-spacing": [2, { "before": true, "after": true }],
38 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }],
39 | "new-parens": 2,
40 | "no-array-constructor": 2,
41 | "no-caller": 2,
42 | "no-class-assign": 2,
43 | "no-cond-assign": 2,
44 | "no-const-assign": 2,
45 | "no-control-regex": 2,
46 | "no-debugger": 2,
47 | "no-delete-var": 2,
48 | "no-dupe-args": 2,
49 | "no-dupe-class-members": 2,
50 | "no-dupe-keys": 2,
51 | "no-duplicate-case": 2,
52 | "no-empty-character-class": 2,
53 | "no-eval": 2,
54 | "no-ex-assign": 2,
55 | "no-extend-native": 2,
56 | "no-extra-bind": 2,
57 | "no-extra-boolean-cast": 2,
58 | "no-extra-parens": [2, "functions"],
59 | "no-fallthrough": 2,
60 | "no-floating-decimal": 2,
61 | "no-func-assign": 2,
62 | "no-implied-eval": 2,
63 | "no-inner-declarations": [2, "functions"],
64 | "no-invalid-regexp": 2,
65 | "no-irregular-whitespace": 2,
66 | "no-iterator": 2,
67 | "no-label-var": 2,
68 | "no-labels": 2,
69 | "no-lone-blocks": 2,
70 | "no-mixed-spaces-and-tabs": 2,
71 | "no-multi-spaces": 2,
72 | "no-multi-str": 2,
73 | "no-multiple-empty-lines": [2, { "max": 1 }],
74 | "no-native-reassign": 0,
75 | "no-negated-in-lhs": 2,
76 | "no-new": 2,
77 | "no-new-func": 2,
78 | "no-new-object": 2,
79 | "no-new-require": 2,
80 | "no-new-wrappers": 2,
81 | "no-obj-calls": 2,
82 | "no-octal": 2,
83 | "no-octal-escape": 2,
84 | "no-proto": 0,
85 | "no-redeclare": 2,
86 | "no-regex-spaces": 2,
87 | "no-return-assign": 2,
88 | "no-self-compare": 2,
89 | "no-sequences": 2,
90 | "no-shadow-restricted-names": 2,
91 | "no-spaced-func": 2,
92 | "no-sparse-arrays": 2,
93 | "no-this-before-super": 2,
94 | "no-throw-literal": 2,
95 | "no-trailing-spaces": 0,
96 | "no-undef": 2,
97 | "no-undef-init": 2,
98 | "no-unexpected-multiline": 2,
99 | "no-unneeded-ternary": [2, { "defaultAssignment": false }],
100 | "no-unreachable": 2,
101 | "no-unused-vars": [2, { "vars": "all", "args": "none" }],
102 | "no-useless-call": 0,
103 | "no-with": 2,
104 | "one-var": [0, { "initialized": "never" }],
105 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
106 | "padded-blocks": [0, "never"],
107 | "quotes": [2, "single", "avoid-escape"],
108 | "radix": 2,
109 | "semi": [2, "always"],
110 | "semi-spacing": [2, { "before": false, "after": true }],
111 | "space-before-blocks": [2, "always"],
112 | "space-before-function-paren": [2, "never"],
113 | "space-in-parens": [2, "never"],
114 | "space-infix-ops": 2,
115 | "space-unary-ops": [2, { "words": true, "nonwords": false }],
116 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
117 | "use-isnan": 2,
118 | "valid-typeof": 2,
119 | "wrap-iife": [2, "any"],
120 | "yoda": [2, "never"]
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | require('mocha');
4 | var fs = require('fs');
5 | var path = require('path');
6 | var assert = require('assert');
7 | var generate = require('generate');
8 | var npm = require('npm-install-global');
9 | var del = require('delete');
10 | var generator = require('./');
11 | var app;
12 |
13 | var cwd = path.resolve.bind(path, __dirname, 'actual');
14 |
15 | function exists(name, cb) {
16 | return function(err) {
17 | if (err) return cb(err);
18 | var filepath = cwd(name);
19 | fs.stat(filepath, function(err, stat) {
20 | if (err) return cb(err);
21 | assert(stat);
22 | del(path.dirname(filepath), cb);
23 | });
24 | };
25 | }
26 |
27 | describe('generate-gitattributes', function() {
28 | if (!process.env.CI && !process.env.TRAVIS) {
29 | before(function(cb) {
30 | npm.maybeInstall('generate', cb);
31 | });
32 | }
33 |
34 | beforeEach(function() {
35 | app = generate({silent: true});
36 | app.option('dest', cwd());
37 | });
38 |
39 | describe('plugin', function() {
40 | it('should only register the plugin once', function(cb) {
41 | var count = 0;
42 | app.on('plugin', function(name) {
43 | if (name === 'generate-gitattributes') {
44 | count++;
45 | }
46 | });
47 | app.use(generator);
48 | app.use(generator);
49 | app.use(generator);
50 | assert.equal(count, 1);
51 | cb();
52 | });
53 |
54 | it('should extend tasks onto the instance', function() {
55 | app.use(generator);
56 | assert(app.tasks.hasOwnProperty('default'));
57 | assert(app.tasks.hasOwnProperty('gitattributes'));
58 | });
59 |
60 | it('should run the `default` task with .build', function(cb) {
61 | app.use(generator);
62 | app.build('default', exists('.gitattributes', cb));
63 | });
64 |
65 | it('should run the `default` task with .generate', function(cb) {
66 | app.use(generator);
67 | app.generate('default', exists('.gitattributes', cb));
68 | });
69 |
70 | it('should run the `gitattributes` task with .build', function(cb) {
71 | app.use(generator);
72 | app.build('gitattributes', exists('.gitattributes', cb));
73 | });
74 |
75 | it('should run the `gitattributes` task with .generate', function(cb) {
76 | app.use(generator);
77 | app.generate('gitattributes', exists('.gitattributes', cb));
78 | });
79 | });
80 |
81 | if (!process.env.CI && !process.env.TRAVIS) {
82 | describe('generator (CLI)', function() {
83 | it('should run the default task using the `generate-gitattributes` name', function(cb) {
84 | app.use(generator);
85 | app.generate('generate-gitattributes', exists('.gitattributes', cb));
86 | });
87 |
88 | it('should run the default task using the `gitattributes` generator alias', function(cb) {
89 | app.use(generator);
90 | app.generate('gitattributes', exists('.gitattributes', cb));
91 | });
92 | });
93 | }
94 |
95 | describe('generator (API)', function() {
96 | it('should run the default task on the generator', function(cb) {
97 | app.register('gitattributes', generator);
98 | app.generate('gitattributes', exists('.gitattributes', cb));
99 | });
100 |
101 | it('should run the `gitattributes` task', function(cb) {
102 | app.register('gitattributes', generator);
103 | app.generate('gitattributes:gitattributes', exists('.gitattributes', cb));
104 | });
105 |
106 | it('should run the `default` task when defined explicitly', function(cb) {
107 | app.register('gitattributes', generator);
108 | app.generate('gitattributes:default', exists('.gitattributes', cb));
109 | });
110 | });
111 |
112 | describe('sub-generator', function() {
113 | it('should work as a sub-generator', function(cb) {
114 | app.register('foo', function(foo) {
115 | foo.register('gitattributes', generator);
116 | });
117 | app.generate('foo.gitattributes', exists('.gitattributes', cb));
118 | });
119 |
120 | it('should run the `default` task by default', function(cb) {
121 | app.register('foo', function(foo) {
122 | foo.register('gitattributes', generator);
123 | });
124 | app.generate('foo.gitattributes', exists('.gitattributes', cb));
125 | });
126 |
127 | it('should run the `gitattributes:default` task when defined explicitly', function(cb) {
128 | app.register('foo', function(foo) {
129 | foo.register('gitattributes', generator);
130 | });
131 | app.generate('foo.gitattributes:default', exists('.gitattributes', cb));
132 | });
133 |
134 | it('should run the `gitattributes:gitattributes` task', function(cb) {
135 | app.register('foo', function(foo) {
136 | foo.register('gitattributes', generator);
137 | });
138 | app.generate('foo.gitattributes:gitattributes', exists('.gitattributes', cb));
139 | });
140 |
141 | it('should work with nested sub-generators', function(cb) {
142 | app
143 | .register('foo', generator)
144 | .register('bar', generator)
145 | .register('baz', generator)
146 |
147 | app.generate('foo.bar.baz', exists('.gitattributes', cb));
148 | });
149 | });
150 | });
151 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |