-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (79 loc) · 2.01 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
76
77
78
79
80
81
82
83
84
85
86
87
88
const semver = require('semver')
const inquirer = require('inquirer')
const { execSync } = require('child_process')
// const curVersion = require('../package.json').version // get package version
let curVersion = '1.0.0'
const tagInit = () => {
let msg = 'varsion init'
execSync(
`git tag -a 'v${curVersion}' -m 'curVersion v${curVersion} : ${msg}'`
)
execSync(`git push --tags`)
curVersion = execSync(`git describe --abbrev=0 --tags`, {
encoding: 'utf8'
}).trim()
}
try {
execSync(`git fetch --tags`)
curVersion = execSync(`git tag | tail -1`, {
// curVersion = execSync(`git describe --abbrev=0 --tags`, {
encoding: 'utf8'
}).trim()
} catch (error) {
tagInit()
}
const release = async () => {
console.log(`Current version: ${curVersion}`)
const bumps = ['patch', 'minor', 'major', 'prerelease']
const versions = {}
bumps.forEach(b => {
versions[b] = semver.inc(curVersion, b)
})
const bumpChoices = bumps.map(b => ({
name: `${b} (${versions[b]})`,
value: b
}))
const { bump, customVersion } = await inquirer.prompt([
{
name: 'bump',
message: 'Select release type:',
type: 'list',
choices: [...bumpChoices, { name: 'custom', value: 'custom' }]
},
{
name: 'customVersion',
message: 'Input version:',
type: 'input',
when: answers => answers.bump === 'custom'
}
])
const version = customVersion || versions[bump]
const { msg } = await inquirer.prompt([
{
name: 'msg',
message: 'Input message:',
type: 'input'
}
])
const { yes } = await inquirer.prompt([
{
name: 'yes',
message: `Confirm releasing ${version}?`,
type: 'confirm'
}
])
if (yes) {
try {
console.log('version', version)
console.log('pushing tag', version)
execSync(`git tag -a 'v${version}' -m 'version v${version} : ${msg}'`)
execSync(`git push --tags`)
} catch (e) {
console.log(e)
}
}
}
release().catch(err => {
console.error(err)
process.exit(1)
})