2
2
3
3
var baseDir , repoDir , prevVersion , newVersion , nextVersion , tagTime ,
4
4
fs = require ( "fs" ) ,
5
+ path = require ( "path" ) ,
6
+ // support: node <0.8
7
+ existsSync = fs . existsSync || path . existsSync ,
5
8
rnewline = / \r ? \n / ,
6
9
repo = "git@github.com:jquery/jquery-ui.git" ,
7
10
branch = "master" ;
@@ -17,14 +20,18 @@ walk([
17
20
getVersions ,
18
21
confirm ,
19
22
20
- section ( "tagging release" ) ,
21
- tagRelease ,
22
- confirm ,
23
+ section ( "building release" ) ,
24
+ buildRelease ,
25
+
26
+ section ( "pushing tag" ) ,
27
+ confirmReview ,
23
28
pushRelease ,
24
29
25
30
section ( "updating branch version" ) ,
26
31
updateBranchVersion ,
27
- confirm ,
32
+
33
+ section ( "pushing " + branch ) ,
34
+ confirmReview ,
28
35
pushBranch ,
29
36
30
37
section ( "generating changelog" ) ,
@@ -35,32 +42,27 @@ walk([
35
42
36
43
section ( "updating trac" ) ,
37
44
updateTrac ,
38
- confirm ,
39
-
40
- section ( "building release" ) ,
41
- buildRelease
45
+ confirm
42
46
] ) ;
43
47
44
48
45
49
46
50
47
51
48
52
function cloneRepo ( ) {
49
- if ( test ( "-d" , baseDir ) ) {
50
- abort ( "The directory '" + baseDir + "' already exists." ) ;
51
- }
52
-
53
- echo ( "Cloning " + repo + "..." ) ;
53
+ echo ( "Cloning " + repo . cyan + "..." ) ;
54
54
git ( "clone " + repo + " " + repoDir , "Error cloning repo." ) ;
55
55
cd ( repoDir ) ;
56
56
57
- echo ( "Checking out " + branch + " branch..." ) ;
57
+ echo ( "Checking out " + branch . cyan + " branch..." ) ;
58
58
git ( "checkout " + branch , "Error checking out branch." ) ;
59
+ echo ( ) ;
59
60
60
61
echo ( "Installing dependencies..." ) ;
61
62
if ( exec ( "npm install" ) . code !== 0 ) {
62
63
abort ( "Error installing dependencies." ) ;
63
64
}
65
+ echo ( ) ;
64
66
}
65
67
66
68
function checkState ( ) {
@@ -75,12 +77,12 @@ function checkState() {
75
77
lastActualAuthor = result . output . split ( rnewline ) . splice ( - 4 , 1 ) [ 0 ] ;
76
78
77
79
if ( lastListedAuthor !== lastActualAuthor ) {
78
- echo ( "Last listed author is " + lastListedAuthor + "." ) ;
79
- echo ( "Last actual author is " + lastActualAuthor + "." ) ;
80
+ echo ( "Last listed author is " + lastListedAuthor . red + "." ) ;
81
+ echo ( "Last actual author is " + lastActualAuthor . green + "." ) ;
80
82
abort ( "Please update AUTHORS.txt." ) ;
81
83
}
82
84
83
- echo ( "Last listed author (" + lastListedAuthor + ") is correct." ) ;
85
+ echo ( "Last listed author (" + lastListedAuthor . cyan + ") is correct." ) ;
84
86
}
85
87
86
88
function getVersions ( ) {
@@ -90,7 +92,7 @@ function getVersions() {
90
92
91
93
echo ( "Validating current version..." ) ;
92
94
if ( currentVersion . substr ( - 3 , 3 ) !== "pre" ) {
93
- echo ( "The current version is " + currentVersion + "." ) ;
95
+ echo ( "The current version is " + currentVersion . red + "." ) ;
94
96
abort ( "The version must be a pre version." ) ;
95
97
}
96
98
@@ -99,6 +101,10 @@ function getVersions() {
99
101
major = parseInt ( parts [ 0 ] , 10 ) ;
100
102
minor = parseInt ( parts [ 1 ] , 10 ) ;
101
103
patch = parseInt ( parts [ 2 ] , 10 ) ;
104
+ // TODO: handle 2.0.0
105
+ if ( minor === 0 ) {
106
+ abort ( "This script is not smart enough to handle the 2.0.0 release." ) ;
107
+ }
102
108
prevVersion = patch === 0 ?
103
109
[ major , minor - 1 , 0 ] . join ( "." ) :
104
110
[ major , minor , patch - 1 ] . join ( "." ) ;
@@ -108,15 +114,16 @@ function getVersions() {
108
114
}
109
115
nextVersion = [ major , minor , patch + 1 ] . join ( "." ) + "pre" ;
110
116
111
- echo ( "We are going from " + prevVersion + " to " + newVersion + "." ) ;
112
- echo ( "After the release, the version will be " + nextVersion + "." ) ;
117
+ echo ( "We are going from " + prevVersion . cyan + " to " + newVersion . cyan + "." ) ;
118
+ echo ( "After the release, the version will be " + nextVersion . cyan + "." ) ;
113
119
}
114
120
115
- function tagRelease ( ) {
121
+ function buildRelease ( ) {
116
122
var pkg ;
117
123
118
- echo ( "Creating release branch..." ) ;
124
+ echo ( "Creating " + " release" . cyan + " branch..." ) ;
119
125
git ( "checkout -b release" , "Error creating release branch." ) ;
126
+ echo ( ) ;
120
127
121
128
echo ( "Updating package.json..." ) ;
122
129
pkg = readPackage ( ) ;
@@ -130,18 +137,27 @@ function tagRelease() {
130
137
if ( exec ( "grunt manifest" ) . code !== 0 ) {
131
138
abort ( "Error generating manifest files." ) ;
132
139
}
140
+ echo ( ) ;
141
+
142
+ echo ( "Building release..." ) ;
143
+ if ( exec ( "grunt release" ) . code !== 0 ) {
144
+ abort ( "Error building release." ) ;
145
+ }
146
+ echo ( ) ;
147
+
148
+ // TODO: Build themes
133
149
150
+ // TODO: Move build out of dist/
134
151
echo ( "Committing release artifacts..." ) ;
135
152
git ( "add *.jquery.json" , "Error adding manifest files to git." ) ;
153
+ // TODO: Add built files
136
154
git ( "commit -am 'Tagging the " + newVersion + " release.'" ,
137
155
"Error committing release changes." ) ;
156
+ echo ( ) ;
138
157
139
158
echo ( "Tagging release..." ) ;
140
159
git ( "tag " + newVersion , "Error tagging " + newVersion + "." ) ;
141
160
tagTime = git ( "log -1 --format='%ad'" , "Error getting tag timestamp." ) . trim ( ) ;
142
-
143
- echo ( ) ;
144
- echo ( "Please review the output and generated files as a sanity check." ) ;
145
161
}
146
162
147
163
function pushRelease ( ) {
@@ -152,7 +168,7 @@ function pushRelease() {
152
168
function updateBranchVersion ( ) {
153
169
var pkg ;
154
170
155
- echo ( "Checking out " + branch + " branch..." ) ;
171
+ echo ( "Checking out " + branch . cyan + " branch..." ) ;
156
172
git ( "checkout " + branch , "Error checking out " + branch + " branch." ) ;
157
173
158
174
echo ( "Updating package.json..." ) ;
@@ -163,13 +179,10 @@ function updateBranchVersion() {
163
179
echo ( "Committing version update..." ) ;
164
180
git ( "commit -am 'Updating the " + branch + " version to " + nextVersion + ".'" ,
165
181
"Error committing package.json." ) ;
166
-
167
- echo ( ) ;
168
- echo ( "Please review the output and generated files as a sanity check." ) ;
169
182
}
170
183
171
184
function pushBranch ( ) {
172
- echo ( "Pushing " + branch + " to GitHub..." ) ;
185
+ echo ( "Pushing " + branch . cyan + " to GitHub..." ) ;
173
186
git ( "push" , "Error pushing to GitHub." ) ;
174
187
}
175
188
@@ -187,7 +200,6 @@ function generateChangelog() {
187
200
// Add ticket references
188
201
. map ( function ( commit ) {
189
202
var tickets = [ ] ;
190
- // TODO: Don't use .replace() since we're not actually replacing
191
203
commit . replace ( / F i x e [ s d ] # ( \d + ) / g, function ( match , ticket ) {
192
204
tickets . push ( ticket ) ;
193
205
} ) ;
@@ -207,7 +219,7 @@ function generateChangelog() {
207
219
"&col=id&col=component&col=summary&order=component" ) + "\n" ;
208
220
209
221
fs . writeFileSync ( changelogPath , changelog ) ;
210
- echo ( "Stored changelog in " + changelogPath + "." ) ;
222
+ echo ( "Stored changelog in " + changelogPath . cyan + "." ) ;
211
223
}
212
224
213
225
function gatherContributors ( ) {
@@ -221,6 +233,7 @@ function gatherContributors() {
221
233
contributors = contributors . concat (
222
234
trac ( "/report/22?V=" + newVersion + "&max=-1" )
223
235
. split ( rnewline )
236
+ // Remove header and trailing newline
224
237
. slice ( 1 , - 1 ) ) ;
225
238
226
239
echo ( "Sorting contributors..." ) ;
@@ -235,26 +248,16 @@ function gatherContributors() {
235
248
} ) ) ;
236
249
237
250
fs . writeFileSync ( contributorsPath , contributors . join ( "\n" ) ) ;
238
- echo ( "Stored contributors in " + contributorsPath + "." ) ;
251
+ echo ( "Stored contributors in " + contributorsPath . cyan + "." ) ;
239
252
}
240
253
241
254
function updateTrac ( ) {
242
- echo ( newVersion + " was tagged at " + tagTime + "." ) ;
243
- echo ( "Close the " + newVersion + " Milestone with the above date and time." ) ;
244
- echo ( "Create the " + newVersion + " Version with the above date and time." ) ;
255
+ echo ( newVersion . cyan + " was tagged at " + tagTime . cyan + "." ) ;
256
+ echo ( "Close the " + newVersion . cyan + " Milestone with the above date and time." ) ;
257
+ echo ( "Create the " + newVersion . cyan + " Version with the above date and time." ) ;
245
258
echo ( "Create a Milestone for the next minor release." ) ;
246
259
}
247
260
248
- function buildRelease ( ) {
249
- echo ( "Checking out " + newVersion + "..." ) ;
250
- git ( "checkout " + newVersion , "Error checking out " + newVersion + "." ) ;
251
-
252
- echo ( "Building release..." ) ;
253
- if ( exec ( "grunt release" ) . code !== 0 ) {
254
- abort ( "Error building release." ) ;
255
- }
256
- }
257
-
258
261
259
262
260
263
@@ -316,30 +319,41 @@ function writePackage( pkg ) {
316
319
}
317
320
318
321
function bootstrap ( fn ) {
319
- require ( "child_process" ) . exec ( "npm root -g" , function ( error , stdout ) {
322
+ console . log ( "Determining directories..." ) ;
323
+ baseDir = process . cwd ( ) + "/__release" ;
324
+ repoDir = baseDir + "/repo" ;
325
+
326
+ if ( existsSync ( baseDir ) ) {
327
+ console . log ( "The directory '" + baseDir + "' already exists." ) ;
328
+ console . log ( "Aborting." ) ;
329
+ process . exit ( 1 ) ;
330
+ }
331
+
332
+ console . log ( "Creating directory..." ) ;
333
+ fs . mkdirSync ( baseDir ) ;
334
+
335
+ console . log ( "Installing dependencies..." ) ;
336
+ require ( "child_process" ) . exec ( "npm install shelljs colors" , {
337
+ cwd : baseDir
338
+ } , function ( error ) {
320
339
if ( error ) {
321
340
console . log ( error ) ;
322
341
return process . exit ( 1 ) ;
323
342
}
324
343
325
- var rootDir = stdout . trim ( ) ;
326
- require ( rootDir + "/shelljs/global" ) ;
327
-
328
- baseDir = pwd ( ) + "/__release" ;
329
- repoDir = baseDir + "/repo" ;
344
+ require ( baseDir + "/node_modules/shelljs/global" ) ;
345
+ require ( baseDir + "/node_modules/colors" ) ;
330
346
331
347
fn ( ) ;
332
348
} ) ;
333
349
}
334
350
335
351
function section ( name ) {
336
- var line = new Array ( name . length + 5 ) . join ( "-" ) ;
337
352
return function ( ) {
338
353
echo ( ) ;
339
- // https://github.com/arturadib/shelljs/issues/20
340
- console . log ( line ) ;
341
- echo ( "| " + name . toUpperCase ( ) + " |" ) ;
342
- console . log ( line ) ;
354
+ echo ( "##" ) ;
355
+ echo ( "## " + name . toUpperCase ( ) . magenta ) ;
356
+ echo ( "##" ) ;
343
357
echo ( ) ;
344
358
} ;
345
359
}
@@ -353,13 +367,18 @@ function prompt( fn ) {
353
367
}
354
368
355
369
function confirm ( fn ) {
356
- echo ( "Press enter to continue, or ctrl+c to cancel." ) ;
370
+ echo ( "Press enter to continue, or ctrl+c to cancel." . yellow ) ;
357
371
prompt ( fn ) ;
358
372
}
359
373
374
+ function confirmReview ( fn ) {
375
+ echo ( "Please review the output and generated files as a sanity check." . yellow ) ;
376
+ confirm ( fn ) ;
377
+ }
378
+
360
379
function abort ( msg ) {
361
- echo ( msg ) ;
362
- echo ( "Aborting." ) ;
380
+ echo ( msg . red ) ;
381
+ echo ( "Aborting." . red ) ;
363
382
exit ( 1 ) ;
364
383
}
365
384
0 commit comments