-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·74 lines (62 loc) · 2.51 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env node
'use strict';
var fs = require('fs');
var execSync = require('child_process').execSync;
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
`;
function getPrefilledMessage() {
if (!isNewCommit) {
return '';
}
var currentBranch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
return '(' + currentBranch + '): ';
}
function getMaxCharsLine() {
if (!isNewCommit) {
return '';
}
return '\n' + maxCharsLine;
}
function getContentWithDoc() {
if (content.indexOf(scissorsLine) !== -1) {
// git commit -v
content = content.replace(scissorsLine, doc + scissorsLine);
} else if (content.indexOf('#') !== -1) {
// other cases where there is a prompt to display doc
content = content + doc;
}
return content;
}
var content = fs.readFileSync(commitMsgFile).toString();
content = getPrefilledMessage() + getMaxCharsLine() + getContentWithDoc();
fs.writeFileSync(commitMsgFile, content);
process.exit(0);