-
Notifications
You must be signed in to change notification settings - Fork 97
/
release.js
95 lines (86 loc) · 2.5 KB
/
release.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
89
90
91
92
93
94
95
var child_process = require('child_process')
var inquirer = require('inquirer')
var semver = require('semver')
var fs = require('fs')
var pkg = require('./package.json')
var bower = require('./bower.json')
console.log('')
console.log('Wellcome to Kefir release utility!')
console.log('----------------------------------------------------------------')
console.log('')
var questions = [
{
type: 'list',
name: 'version',
message: 'Which version will it be? (current is ' + pkg.version + ')',
choices: [
semver.inc(pkg.version, 'patch'),
semver.inc(pkg.version, 'minor'),
semver.inc(pkg.version, 'major'),
semver.inc(pkg.version, 'premajor', 'rc'),
],
},
{
type: 'list',
name: 'dryRun',
message: 'Do you want to release, or just see what would happen if you do?',
choices: ['Just see', 'Release!'],
},
]
inquirer.prompt(questions).then(function(answers) {
var newVerison = answers.version
var dryRun = answers.dryRun === 'Just see'
bower.version = pkg.version = newVerison
console.log('')
if (dryRun) {
console.log('Ok, here is what would happen:')
} else {
console.log('Doing actual release:')
}
console.log('')
run('npm test', dryRun) &&
bumpVersion('package.json', pkg, dryRun) &&
bumpVersion('bower.json', bower, dryRun) &&
run('npm run build', dryRun) &&
run('git add .', dryRun) &&
run('git add -f dist', dryRun) &&
run('git add -f index.html', dryRun) &&
run('git commit -m "' + newVerison + '"', dryRun) &&
run('git push', dryRun) &&
run('git tag -a ' + newVerison + ' -m "v' + newVerison + '"', dryRun) &&
run('git push origin --tags', dryRun) &&
run('npm publish', dryRun) &&
run('git rm -r dist', dryRun) &&
run('git rm index.html', dryRun) &&
run('git commit -m "cleanup repository after release"', dryRun) &&
run('git push', dryRun)
})
function bumpVersion(fileName, obj, dry) {
console.log('Bumping version in `' + fileName + '` to ' + obj.version)
if (!dry) {
try {
fs.writeFileSync(fileName, JSON.stringify(obj, null, ' ') + '\n')
console.log('... ok')
} catch (e) {
console.error(e)
return false
}
}
return true
}
function run(cmd, dry) {
console.log('Running `' + cmd + '`')
if (!dry) {
var proc = child_process.spawnSync(cmd, {
stdio: 'inherit',
shell: true,
})
if (proc.status === 0) {
console.log('... ok')
} else {
console.error('... fail!')
return false
}
}
return true
}