-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·75 lines (66 loc) · 1.64 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
75
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const inquirer = require('inquirer');
const { execSync } = require('child_process');
function readGitConfig() {
const local = execSync('git config --local --get semantic.scope');
if (local) {
return local.toString('utf8').split(' ');
}
const global = execSync('git config --global --get semantic.scope');
if (global) {
return global.toString('utf8').split(' ');
}
const system = execSync('git config --system --get semantic.scope');
if (system) {
return system.toString('utf8').split(' ');
}
return [];
}
function promptUser(callback) {
const scopes = readGitConfig().map(s => s.trim());
scopes.push('None');
const questions = [
{
name: 'commitType',
type: 'list',
message: 'What type of commit is this:',
choices: [
'feat',
'fix',
'style',
'test',
'refactor',
'chore',
'docs',
],
},
{
name: 'scope',
type: 'list',
message: 'What is the scope of this commit:',
choices: scopes,
},
{
name: 'message',
type: 'input',
message: 'Enter your commit message:',
validate: function(value) {
if (!value.length) {
return 'Please enter a commit message';
}
return true;
}
},
];
inquirer.prompt(questions).then(callback);
}
function run() {
promptUser(function() {
const { commitType, scope, message } = arguments['0'];
const result = execSync(`git commit -m '${commitType}(${scope}): ${message}'`);
console.info(result.toString('utf8'));
});
}
run();