UNPKG

2.47 kBJavaScriptView Raw
1var inquirer = require('inquirer')
2var semver = require('semver')
3var shell = require('shelljs')
4var fs = require('fs')
5
6var pkg = require('./package.json')
7var bower = require('./bower.json')
8
9console.log('')
10console.log('Wellcome to Kefir release utility!')
11console.log('----------------------------------------------------------------')
12console.log('')
13
14var questions = [
15 {
16 type: 'list',
17 name: 'version',
18 message: 'Which version will it be? (current is ' + pkg.version + ')',
19 choices: [
20 semver.inc(pkg.version, 'patch'),
21 semver.inc(pkg.version, 'minor'),
22 semver.inc(pkg.version, 'major'),
23 semver.inc(pkg.version, 'premajor', 'rc'),
24 ],
25 },
26 {
27 type: 'list',
28 name: 'dryRun',
29 message: 'Do you want to release, or just see what would happen if you do?',
30 choices: ['Just see', 'Release!'],
31 },
32]
33
34inquirer.prompt(questions, function(answers) {
35 var newVerison = answers.version
36 var dryRun = answers.dryRun === 'Just see'
37
38 bower.version = pkg.version = newVerison
39
40 console.log('')
41 if (dryRun) {
42 console.log('Ok, here is what would happen:')
43 } else {
44 console.log('Doing actual release:')
45 }
46 console.log('')
47
48 run('npm test', dryRun) &&
49 bumpVersion('package.json', pkg, dryRun) &&
50 bumpVersion('bower.json', bower, dryRun) &&
51 run('npm run build', dryRun) &&
52 run('git add .', dryRun) &&
53 run('git add -f dist', dryRun) &&
54 run('git add -f index.html', dryRun) &&
55 run('git commit -m "' + newVerison + '"', dryRun) &&
56 run('git push', dryRun) &&
57 run('git tag -a ' + newVerison + ' -m "v' + newVerison + '"', dryRun) &&
58 run('git push origin --tags', dryRun) &&
59 run('npm publish', dryRun) &&
60 run('git rm -r dist', dryRun) &&
61 run('git rm index.html', dryRun) &&
62 run('git commit -m "cleanup repository after release"', dryRun) &&
63 run('git push', dryRun)
64})
65
66function bumpVersion(fileName, obj, dry) {
67 console.log('Bumping version in `' + fileName + '` to ' + obj.version)
68 if (!dry) {
69 try {
70 fs.writeFileSync(fileName, JSON.stringify(obj, null, ' ') + '\n')
71 console.log('... ok')
72 } catch (e) {
73 console.error(e)
74 return false
75 }
76 }
77 return true
78}
79
80function run(cmd, dry) {
81 console.log('Running `' + cmd + '`')
82 if (!dry) {
83 if (shell.exec(cmd, {silent: false}).code === 0) {
84 console.log('... ok')
85 } else {
86 console.error('... fail!')
87 return false
88 }
89 }
90 return true
91}