提交标准笔记
利用 inquirer 抉择配置好的提交类型,以及配合 commitlint 实现 commit 查看 npm i inquirer shelljs @commitlint/{cli,config-conventional} -D
增加 package.json 的 script
"commitlint": "commitlint -e",
"commit": "node commit/git-commit.js"
创立 commit/git-commit.js 文件
const shell = require('shelljs')
const inquirer = require('inquirer')
const prompsConfig = {
ciType: [
{
type: 'list',
name: 'type',
message: '请抉择本次提交的类型:',
choices: [
{
name: '引入新个性',
value: 'feat',
},
{
name: '改良代码的构造格局 / 款式',
value: 'style',
},
{
name: '修复 bug',
value: 'fix',
},
{
name: '晋升性能',
value: 'perf',
},
{
name: '删除代码或文件',
value: 'delete',
},
{
name: '其余批改, 比方扭转构建流程、或者减少依赖库、工具等',
value: 'chore',
},
{
name: '重构',
value: 'refactor',
},
{
name: '撰写文档',
value: 'docs',
},
{
name: '减少测试',
value: 'test',
},
{
name: '更新打包文件',
value: 'build',
},
{
name: '首次提交',
value: 'init',
},
{
name: '公布 / 版本标签',
value: 'release',
},
{
name: '部署性能',
value: 'deploy',
},
{
name: '代码回滚',
value: 'revert',
},
{
name: 'CI 继续集成批改',
value: 'ci',
},
],
},
],
ciMsg: {
type: 'input',
name: 'msg',
message: '请输出提交文本:',
validate: function (value) {if (value) {return true}
return '文本必须输出!'
},
},
}
async function gitCommit() {let { type} = await inquirer.prompt(prompsConfig.ciType)
let {msg} = await inquirer.prompt(prompsConfig.ciMsg)
shell.exec(`git commit -m "${type}: ${msg}"`, function () {console.log(`\n 提交脚本: git commit -m "${type}: ${msg}"`)
})
}
gitCommit()
配置 commitlint 类型,创立 commitlint.config.js 文件
module.exports = {extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [2, 'always', ['build', 'chore', 'ci', 'feat', 'docs', 'fix', 'perf', 'revert', 'refactor', 'style', 'test', 'init', 'build', 'release', 'delete']],
}
};