-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.js
63 lines (55 loc) · 2 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
var semver = require('semver'),
readline = require('readline'),
ShellTask = require('shell-task')
module.exports = function (grunt) {
grunt.registerTask('version', function (version) {
;['package', 'bower', 'component'].forEach(function (file) {
file = file + '.json'
var json = grunt.file.read(file)
json = json.replace(/"version"\s*:\s*"(.+?)"/, '"version": "' + version + '"')
grunt.file.write(file, json)
console.log('updated ' + blue(file))
})
})
grunt.registerTask('git', function (version) {
new ShellTask('git add -A')
.then('git commit -m Release-v' + version)
.then('git tag v' + version)
.then('git push')
.then('git push origin v' + version)
.then('npm publish')
.run(this.async(), function (err) {
grunt.fail.fatal(err)
})
})
grunt.registerTask('release', function (version) {
var done = this.async(),
current = grunt.config('version'),
next = semver.inc(current, version || 'patch') || version
if (!semver.valid(next)) {
return grunt.fail.warn('Invalid version.')
}
if (semver.lt(next, current)) {
return grunt.fail.warn('Version is older than current.')
}
readline.createInterface({
input: process.stdin,
output: process.stdout
}).question('Releasing version v' + next + '. Continue? (Y/n)', function (answer) {
if (!answer || answer.toLowerCase() === 'y') {
console.log(blue('Releasing: v' + next))
grunt.task.run([
'jshint',
'build:' + next,
'test',
'version:' + next,
'git:' + next
])
}
done()
})
})
}
function blue (str) {
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
}