-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGruntfile.js
172 lines (165 loc) · 5.34 KB
/
Gruntfile.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
module.exports = function (grunt) {
'use strict'
require('load-grunt-tasks')(grunt, {
pattern: 'grunt-*',
config: './package.json',
scope: 'devDependencies'
})
var skipBuild = grunt.option('skip-build') // helpful when testing the release process
var dir = null
var basePath = grunt.option('basePath') || './'
var packageJson = grunt.file.readJSON('package.json')
var versions = packageJson.version.match(/^(\d+)\.(\d+)\.(\d+)(\-pre\.(\d+))?$/)
var major = versions[ 1 ]
var minor = versions[ 2 ]
var patch = versions[ 3 ]
var preVersion = packageJson.version
var patchVersion = [ major, minor, patch ].join('.')
var minorVersion = [ major, minor ].join('.')
var tagPrefix = 'v'
var preTag = tagPrefix + preVersion
var patchTag = tagPrefix + patchVersion
var minorTag = tagPrefix + minorVersion
var latestTag = 'latest'
var maintenanceBranch = 'v' + minorVersion + '.x'
var origin = grunt.option('remote') || 'origin'
var master = grunt.option('source-branch') || 'master'
var releaseMinor = [
'shell:confirmOnMasterBranch',
'shell:confirmNoUntrackedFiles',
'shell:confirmNoModifiedFiles',
'gitfetch:tags',
'gitpull:origin',
'bump:minor',
'shell:test',
'gitadd:all',
'gitcommit:releaseMinor',
'gittag:patch',
'gitcheckout:maintenance',
'bump:prepatch',
'gitadd:all',
'gitcommit:vnext',
'gitpush:maintenance',
'gitcheckout:master',
'bump:preminor',
'gitadd:all',
'gitcommit:vnext',
'gitpush:master',
'gitpush:patchTag'
]
var releasePatch = [
'shell:confirmOnMaintenanceBranch',
'shell:confirmNoUntrackedFiles',
'shell:confirmNoModifiedFiles',
'gitfetch:tags',
'gitpull:origin',
'bump:patch',
'shell:test',
'gitadd:all',
'gitcommit:releasePatch',
'gittag:patch',
'bump:prepatch',
'gitadd:all',
'gitcommit:vnext',
'gitpush:maintenance',
'gitpush:patchTag'
]
var config = {
pkg: packageJson,
basePath: basePath,
dir: dir,
bump: {
options: {
files: './package.json',
commit: false,
push: false,
pushTo: origin,
prereleaseName: 'pre',
createTag: false,
pushTags: false
}
},
gitpush: {
master: { options: { remote: origin, branch: master } },
maintenance: { options: { remote: origin, branch: maintenanceBranch, upstream: true } },
current: { options: { remote: origin } },
preTag: { options: { remote: origin, branch: preTag } },
patchTag: { options: { remote: origin, branch: patchTag } },
minorTag: { options: { remote: origin, branch: minorTag, force: true } },
latestTag: { options: { remote: origin, branch: latestTag, force: true } }
},
gittag: {
pre: { options: { tag: preTag } },
patch: { options: { tag: patchTag } },
minor: { options: { tag: minorTag, force: true } },
latest: { options: { tag: latestTag, force: true } }
},
gitpull: {
origin: { options: { remote: origin } }
},
gitfetch: {
tags: { options: { remote: origin, tags: true } }
},
gitcheckout: {
master: { options: { branch: master } },
maintenance: { options: { branch: maintenanceBranch, create: true } }
},
gitadd: {
all: { options: { all: true } }
},
gitcommit: {
releaseMinor: { options: { message: 'release ' + patchTag } },
releasePatch: { options: { message: 'release ' + patchTag } },
vnext: { options: { message: 'prepare for next dev iteration' } }
},
shell: {
confirmOnMasterBranch: {
command: "[ $(git status | head -n 1 | awk '{ print $3 }') == '" + master + "' ]"
},
confirmOnMaintenanceBranch: {
command: "[[ $(git status | head -n 1 | awk '{ print $3 }') =~ ^v[0-9]+\\.[0-9]+\\.x$ ]]"
},
confirmNoUntrackedFiles: {
command: '[ -z "$(git status -s)" ]'
},
confirmNoModifiedFiles: {
command: 'git diff --cached --exit-code --no-patch'
},
test: {
command: skipBuild
? 'echo "Skipping build because --skip-build=' + skipBuild + '"'
: 'npm test'
}
},
coveralls: {
ci: {
src: 'coverage/lcov.info'
}
}
}
grunt.initConfig(config)
grunt.registerTask('release-patch', 'Creates patch-level tag & advances minor tag, and, optionally, the latest tag', releasePatch)
grunt.registerTask('release-minor', 'Creates maintenance branch, patch- & minor-level tags, and advances latest tag', releaseMinor)
for (var s in config.shell) {
if (config.shell[ s ].usage) {
grunt.registerTask(s, config.shell[ s ].usage, 'shell:' + s)
}
}
grunt.registerTask('help', 'Prints this help message.', function () {
console.log('\n Usage: grunt command ... # Issues grunt command(s).\n ')
console.log(' A management script for running a grunt tasks.\n')
console.log(' Commands:\n')
var tasks = Object.keys(grunt.task._tasks).filter(function (name) {
return name !== 'shell'
})
var usageMax = tasks.reduce(function (max, v) {
return Math.max(max, v.length)
}, 0)
var pad = new Array(usageMax).join(' ')
tasks.forEach(function (taskName) {
var task = grunt.task._tasks[ taskName ]
var name = (taskName + pad).substr(0, usageMax)
console.log(' ' + name + ' ' + task.info)
})
})
}