forked from dgiot/dgiot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
push.js
80 lines (80 loc) · 2.49 KB
/
push.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
76
77
78
79
80
#!/usr/bin/env node
// install: yarn global add rimraf chalk shelljs inquirer
// use: node push.js or ./push.js
const rimraf = require('rimraf')
const logs = console.log
const path = require('path')
const chalk = require('chalk')
const shell = require('shelljs')
const inquirer = require('inquirer')
let commitType,
commitMsg = ''
function rimLog(file) {
const dirPath = path.resolve(__dirname, `${file}`)
rimraf(dirPath, (err) => {
if (err) {
throw err
} else logs(chalk.red(`${dirPath} File has been deleted`))
})
funCommitType()
}
function funCommitType() {
const promptList = [
{
type: 'list',
message: '请选择commit类型:',
name: 'env',
choices: [
{ value: 'feat', name: 'feat: 新功能' },
{ value: 'fix', name: 'fix: 修复bug' },
{ value: 'style', name: 'style: 代码格式(空格、分号等)' },
{ value: 'refactor', name: 'refactor: 重构(非feat、非fix)' },
{ value: 'perf', name: 'perf: 提高性能' },
{ value: 'test', name: 'test: 添加缺少的测试' },
{ value: 'docs', name: 'docs: 文档修改' },
{
value: 'chore',
name: 'chore: 杂务(对生成过程或辅助工具和库(如文档生成)的更改)',
},
{ value: 'revert', name: 'revert: 还原到提交' },
{ value: 'WIP', name: 'WIP: 进行中的工作' },
{ value: 'workflow', name: 'workflow: 工作流相关文件修改' },
{ value: 'build', name: 'build: 构建过程或辅助工具的变动' },
{ value: 'ci', name: 'ci: 修改项目持续集成流程' },
{ value: 'release', name: 'release: 发布新版本' },
],
},
]
inquirer.prompt(promptList).then(({ env }) => {
logs(chalk.blue('commit类型:' + env))
commitType = env
funCommitMessage()
})
}
function funCommitMessage() {
const promptList = [
{
type: 'input',
message: '请输入提交message信息:',
name: 'msg',
},
]
inquirer.prompt(promptList).then(({ msg }) => {
commitMsg = msg
logs(chalk.blue('message信息:' + msg))
funShell()
})
}
function funShell() {
shell.exec('git pull')
try {
shell.exec('rimraf CHANGELOG.md && conventional-changelog -p angular -i CHANGELOG.md -r 0 -s')
}catch{
console.log(e.toString())
}
shell.exec('git add -A .')
shell.exec(`git commit -m ${commitType}: &{commitMsg}`)
shell.exec('git push')
shell.exec('git status')
}
rimLog('CHANGELOG.md')