Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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
48 changes: 21 additions & 27 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
var scissorsLine = '# ---------- Message Formatting Convention ----------';
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scissors line is a default in Git and displayed when you do a git commit -v.
I use it to insert the message after any existing commit message and before the diff of changes.
You should not change it, but you can add Message Formatting Convention to the template :-)


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 for template file: ' + msgTplFile));
process.exit(1);
}

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

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

function getPrefilledMessage() {
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
"version": "0.2.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