├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── README.md ├── generators └── app │ └── index.js ├── package.json └── test └── test-app.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - v5 4 | - v4 5 | - '0.12' 6 | - '0.10' 7 | before_script: 8 | - 'git config --global user.email "you@example.com"' 9 | - 'git config --global user.name "Your Name"' 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # generator-git-init 2 | 3 | [![NPM version][npm-image]][npm-url] 4 | [![Build Status][travis-image]][travis-url] 5 | [![Dependency Status][depstat-image]][depstat-url] 6 | 7 | > [Yeoman][yo] generator for simply `git init` and optional `init` commit. 8 | > [Works great with other generators too](#composability). 9 | 10 | [yo]: http://yeoman.io/ 11 | 12 | ## Install 13 | 14 | npm install --global yo generator-git-init 15 | 16 | ## Usage 17 | 18 | yo git-init 19 | 20 | # standard `init` commit message 21 | yo git-init -c 22 | yo git-init --commit 23 | 24 | # custom `init` commit message 25 | yo git-init --commit='Awesome project start' 26 | 27 | ## Composability 28 | 29 | > Composability is a way to combine smaller parts to make one large thing. Sort of [like Voltron®][voltron] 30 | > — [Yeoman docs](http://yeoman.io/authoring/composability.html) 31 | 32 | Just plug in _git-init_ into your generator and let it initialize git for you. Everybody wins. 33 | 34 | ### Install 35 | 36 | npm install --save generator-git-init 37 | 38 | #### Compose 39 | 40 | ```js 41 | this.composeWith('git-init', {}, { 42 | local: require.resolve('generator-git-init') 43 | }); 44 | ``` 45 | 46 | Or with custom initial commit message: 47 | 48 | ```js 49 | this.composeWith('git-init', { 50 | options: { commit: 'your awesome project' } 51 | }, { 52 | local: require.resolve('generator-git-init') 53 | }); 54 | ``` 55 | 56 | Add this lines to your `.travis.yml` to calm down your Travis builds: 57 | 58 | ```yml 59 | before_script: 60 | - 'git config --global user.email "you@example.com"' 61 | - 'git config --global user.name "Your Name"' 62 | ``` 63 | 64 | [voltron]: http://25.media.tumblr.com/tumblr_m1zllfCJV21r8gq9go11_250.gif 65 | 66 | 67 | ## License 68 | 69 | MIT © [Vladimir Starkov](https://iamstarkov.com) 70 | 71 | [npm-url]: https://npmjs.org/package/generator-git-init 72 | [npm-image]: https://img.shields.io/npm/v/generator-git-init.svg?style=flat-square 73 | 74 | [travis-url]: https://travis-ci.org/iamstarkov/generator-git-init 75 | [travis-image]: https://img.shields.io/travis/iamstarkov/generator-git-init.svg?style=flat-square 76 | 77 | [depstat-url]: https://david-dm.org/iamstarkov/generator-git-init 78 | [depstat-image]: https://david-dm.org/iamstarkov/generator-git-init.svg?style=flat-square 79 | 80 | [travis]: https://travis-ci.org/ 81 | -------------------------------------------------------------------------------- /generators/app/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | var generators = require('yeoman-generator'); 3 | var isString = require('lodash.isstring'); 4 | 5 | module.exports = generators.Base.extend({ 6 | constructor: function () { 7 | generators.Base.apply(this, arguments); 8 | this.option('commit', { type: String, required: false, alias: 'c', 9 | desc: 'Commit message, optional', 10 | }); 11 | }, 12 | initializing: function () { 13 | this.spawnCommandSync('git', ['init', '--quiet']); 14 | }, 15 | conflicts: function () { 16 | if (this.options.commit) { 17 | this._addCommit(this.options.commit); 18 | } 19 | }, 20 | _addCommit: function (message) { 21 | var commitMessage = isString(message) ? message : 'init'; 22 | this.spawnCommandSync('git', ['add', '--all']); 23 | this.spawnCommandSync('git', ['commit', '-m', commitMessage, '--quiet']); 24 | } 25 | }); 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-git-init", 3 | "version": "1.1.3", 4 | "description": "Yeoman generator for simply `git init` and optional `init` commit", 5 | "license": "MIT", 6 | "main": "generators/app/index.js", 7 | "repository": "iamstarkov/generator-git-init", 8 | "author": { 9 | "name": "Vladimir Starkov", 10 | "email": "iamstarkov@gmail.com", 11 | "url": "https://github.com/iamstarkov" 12 | }, 13 | "scripts": { 14 | "test": "mocha", 15 | "tdd": "npm run test -- --watch", 16 | "postpublish": "git push --follow-tags" 17 | }, 18 | "files": [ 19 | "generators" 20 | ], 21 | "keywords": [ 22 | "yeoman-generator", 23 | "git", 24 | "init", 25 | "git-init" 26 | ], 27 | "dependencies": { 28 | "lodash.isstring": "^4.0.0", 29 | "yeoman-generator": "^0.22.5" 30 | }, 31 | "devDependencies": { 32 | "mocha": "^2.4.5", 33 | "spawn-sync": "^1.0.15", 34 | "yeoman-assert": "^2.1.1", 35 | "yeoman-test": "^1.0.0" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/test-app.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var path = require('path'); 4 | var fs = require('fs'); 5 | var assert = require('yeoman-assert'); 6 | var helpers = require('yeoman-test'); 7 | var spawnSync = require('spawn-sync'); 8 | 9 | 10 | function makeGenerator() { 11 | return helpers.run(path.join(__dirname, '../generators/app')) 12 | .withOptions({ skipInstall: true }); 13 | } 14 | 15 | function exec(command, args) { 16 | args = args.split(' '); 17 | var execResult = spawnSync(command, args); 18 | return execResult.stdout.toString(); 19 | } 20 | 21 | function addFile(dir, done) { 22 | var fileName = path.join(dir, 'index.html'); 23 | fs.writeFile(fileName, '', done); 24 | } 25 | 26 | 27 | describe('git-init:app', function () { 28 | it('should initialize git repository', function (done) { 29 | makeGenerator().on('end', function () { 30 | assert.file('.git'); 31 | done(); 32 | }); 33 | }); 34 | 35 | it('should do initial commit if option --commit was set', function (done) { 36 | makeGenerator() 37 | .inTmpDir(addFile) 38 | .withOptions({ commit: true }) 39 | .on('end', function () { 40 | var execResult = exec('git', 'log --pretty=oneline'); 41 | assert(execResult.match(/init/)); 42 | done(); 43 | }); 44 | }); 45 | 46 | it('should take custom commit message', function (done) { 47 | makeGenerator() 48 | .inTmpDir(addFile) 49 | .withOptions({ commit: 'Great commit for project init' }) 50 | .on('end', function () { 51 | var execResult = exec('git', 'log --pretty=oneline'); 52 | assert(execResult.match(/Great commit for project init/)); 53 | done(); 54 | }); 55 | }); 56 | }); 57 | --------------------------------------------------------------------------------