-
Notifications
You must be signed in to change notification settings - Fork 200
/
index.js
executable file
·48 lines (43 loc) · 1.6 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
#!/usr/bin/env node
/* eslint-disable global-require */
// Inspired by: https://github.com/commitizen/cz-conventional-changelog and https://github.com/commitizen/cz-cli
const editor = require('editor');
const temp = require('temp').track();
const fs = require('fs');
const log = require('./lib/logger');
const buildCommit = require('./lib/build-commit');
const readConfigFile = require('./lib/read-config-file');
module.exports = {
prompter(cz, commit) {
const config = readConfigFile();
config.subjectLimit = config.subjectLimit || 100;
log.info('All lines except first will be wrapped after 100 characters.');
const questions = require('./lib/questions').getQuestions(config, cz);
cz.prompt(questions).then((answers) => {
if (answers.confirmCommit === 'edit') {
temp.open(null, (err, info) => {
/* istanbul ignore else */
if (!err) {
fs.writeSync(info.fd, buildCommit(answers, config));
fs.close(info.fd, () => {
editor(info.path, (code) => {
if (code === 0) {
const commitStr = fs.readFileSync(info.path, {
encoding: 'utf8',
});
commit(commitStr);
} else {
log.info(`Editor returned non zero value. Commit message was:\n${buildCommit(answers, config)}`);
}
});
});
}
});
} else if (answers.confirmCommit === 'yes') {
commit(buildCommit(answers, config));
} else {
log.info('Commit has been canceled.');
}
});
},
};