Repository navigation
Expand file tree
/
Copy pathsmart-commit.js
More file actions
74 lines (66 loc) · 1.74 KB
/
Copy pathsmart-commit.js
File metadata and controls
74 lines (66 loc) · 1.74 KB
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
/* eslint-disable @typescript-eslint/no-var-requires */
const inquirer = require('inquirer')
const commitlintConfig = require('./commitlint.config')
/**
* For the responses to match the Conventional Commits format
*/
function formatCommit(commit, answers) {
commit(`
${answers.type}(${answers.scope}): ${answers.title}
`)
}
function prompter(cz, commit) {
const scopes = commitlintConfig.rules['scope-enum'][2]
// the 'release' scope should only be used by lerna/CI
scopes.splice(scopes.indexOf('release', 1))
const types = [
{ value: 'wip', name: '🚧 wip: Work in progress' },
{ value: 'docs', name: '📚 docs: Documentation updates' },
{ value: 'feat', name: '✨ feat: A new feature' },
{ value: 'fix', name: '🐛 fix: A bug fix' },
{ value: 'test', name: '✅ test: Adding/updating tests' },
{
value: 'chore',
name: '🔧 chore: Changes to the build process, tools or libraries',
},
]
inquirer
.prompt([
{
type: 'list',
name: 'type',
message: 'What type of update are you making? (required)\n',
choices: types,
pageSize: 8,
validate: (type) => types.includes(type),
},
{
type: 'list',
name: 'scope',
message: 'Where are you making the update? (required)\n',
choices: scopes,
validate: (scope) => scopes.includes(scope),
},
{
type: 'input',
name: 'title',
message: 'Git commit title (required):\n',
validate: (input) => {
if (!input) {
return 'You must provide a commit title'
}
if (input.length > 100) {
return 'Commit titles are limited to 100 characters in length'
}
return true
},
},
])
.then((answers) => {
formatCommit(commit, answers)
})
}
module.exports = {
prompter,
formatCommit,
}