Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![version](https://img.shields.io/npm/v/prepare-commit-msg-angular.svg?style=flat-square)](http://npm.im/prepare-commit-msg-angular)
[![MIT License](https://img.shields.io/npm/l/prepare-commit-msg-angular.svg?style=flat-square)](http://opensource.org/licenses/MIT)

## Basic Usage
This provides you a binary that you can use as a githook to prepare a commit message following Angular guidelines and display documentation about it.

To be used in addition to [validate-commit-msg](https://github.com/kentcdodds/validate-commit-msg).
Expand All @@ -22,3 +23,17 @@ To be used in addition to [validate-commit-msg](https://github.com/kentcdodds/va
}
}
```

## Message Template
By default, the `default.tpl` will be shown in your git editor.

You can also specify your preferred message template by `-t` option.

e.g.
```
"config": {
"ghooks": {
"prepare-commit-msg": "prepare-commit-msg-angular $2 $3 -t tpl_file_path"
}
}
```
25 changes: 25 additions & 0 deletions default.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# <type>(<scope>): <subject>
# <BLANK LINE>
# <body>
# <BLANK LINE>
# <footer>
#---
# TYPE must be one of the following:
# - feat: A new feature (will appear in CHANGELOG)
# - fix: A bug fix (will appear in CHANGELOG)
# - docs: Documentation only changes
# - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
# - refactor: A code change that neither fixes a bug nor adds a feature
# - perf: A code change that improves performance (will appear in CHANGELOG)
# - test: Adding missing tests
# - chore: Changes to the build process or auxiliary tools and libraries such as documentation generation
#
# SCOPE could be anything specifying place of the commit change.
# For example $location, $browser, $compile, $rootScope, ngHref, ngClick, ngView, etc...
#
# SUBJECT contains succinct description of the change:
# - use the imperative, present tense: "change" not "changed" nor "changes"
# - do not capitalize first letter
# - no dot (.) at the end
#---
# https://github.com/ajoslin/conventional-changelog/blob/master/conventions/angular.md
46 changes: 20 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,32 @@

var fs = require('fs');
var execSync = require('child_process').execSync;
var program = require('commander');
var clc = require('cli-color');
var consoleError = clc.red.bold;

var commitMsgFile = process.argv[2] || './.git/COMMIT_EDITMSG';
var isNewCommit = (process.argv[3] === 'undefined');

var maxCharsLine = '#⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴⎴';
var scissorsLine = '# ------------------------ >8 ------------------------';
var doc = `${scissorsLine}
# <type>(<scope>): <subject>
# <BLANK LINE>
# <body>
# <BLANK LINE>
# <footer>
#---
# TYPE must be one of the following:
# - feat: A new feature (will appear in CHANGELOG)
# - fix: A bug fix (will appear in CHANGELOG)
# - docs: Documentation only changes
# - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
# - refactor: A code change that neither fixes a bug nor adds a feature
# - perf: A code change that improves performance (will appear in CHANGELOG)
# - test: Adding missing tests
# - chore: Changes to the build process or auxiliary tools and libraries such as documentation generation
#
# SCOPE could be anything specifying place of the commit change.
# For example $location, $browser, $compile, $rootScope, ngHref, ngClick, ngView, etc...
#
# SUBJECT contains succinct description of the change:
# - use the imperative, present tense: "change" not "changed" nor "changes"
# - do not capitalize first letter
# - no dot (.) at the end
#---
# https://github.com/ajoslin/conventional-changelog/blob/master/conventions/angular.md

program
.option('-t, --template [file path]', 'Set file location of template for git commit message', '')
.parse(process.argv);
var msgTplFile = !program.template ? './default.tpl' : program.template;
try {
fs.accessSync(msgTplFile, fs.R_OK)
} catch (err) {
console.error(consoleError('Invalid path: ' + msgTplFile + '\n\r' + err.toString()));
process.exit(1);
}

var msgTpl = fs.readFileSync(msgTplFile).toString();

var doc = `
${scissorsLine}
${msgTpl}
`;

function getPrefilledMessage() {
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"name": "prepare-commit-msg-angular",
"version": "0.2.0",
"version": "0.3.0",
"main": "index.js",
"bin": "index.js",
"engines" : {
"node" : ">=4.0"
"engines": {
"node": ">=4.0"
},
"dependencies": {
"cli-color": "^1.1.0",
"commander": "^2.9.0"
},
"dependencies": {},
"devDependencies": {
"ghooks": "^1.0.1",
"validate-commit-msg": "^1.0.0"
Expand Down