Skip to content

Commit 97ec1dd

Browse files
committed
Build: Remove need to install shelljs globally for release script. Colorized output.
1 parent 7f07f93 commit 97ec1dd

File tree

1 file changed

+79
-60
lines changed

1 file changed

+79
-60
lines changed

build/release/release.js

+79-60
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
var baseDir, repoDir, prevVersion, newVersion, nextVersion, tagTime,
44
fs = require( "fs" ),
5+
path = require( "path" ),
6+
// support: node <0.8
7+
existsSync = fs.existsSync || path.existsSync,
58
rnewline = /\r?\n/,
69
repo = "git@github.com:jquery/jquery-ui.git",
710
branch = "master";
@@ -17,14 +20,18 @@ walk([
1720
getVersions,
1821
confirm,
1922

20-
section( "tagging release" ),
21-
tagRelease,
22-
confirm,
23+
section( "building release" ),
24+
buildRelease,
25+
26+
section( "pushing tag" ),
27+
confirmReview,
2328
pushRelease,
2429

2530
section( "updating branch version" ),
2631
updateBranchVersion,
27-
confirm,
32+
33+
section( "pushing " + branch ),
34+
confirmReview,
2835
pushBranch,
2936

3037
section( "generating changelog" ),
@@ -35,32 +42,27 @@ walk([
3542

3643
section( "updating trac" ),
3744
updateTrac,
38-
confirm,
39-
40-
section( "building release" ),
41-
buildRelease
45+
confirm
4246
]);
4347

4448

4549

4650

4751

4852
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 + "..." );
5454
git( "clone " + repo + " " + repoDir, "Error cloning repo." );
5555
cd( repoDir );
5656

57-
echo( "Checking out " + branch + " branch..." );
57+
echo( "Checking out " + branch.cyan + " branch..." );
5858
git( "checkout " + branch, "Error checking out branch." );
59+
echo();
5960

6061
echo( "Installing dependencies..." );
6162
if ( exec( "npm install" ).code !== 0 ) {
6263
abort( "Error installing dependencies." );
6364
}
65+
echo();
6466
}
6567

6668
function checkState() {
@@ -75,12 +77,12 @@ function checkState() {
7577
lastActualAuthor = result.output.split( rnewline ).splice( -4, 1 )[ 0 ];
7678

7779
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 + "." );
8082
abort( "Please update AUTHORS.txt." );
8183
}
8284

83-
echo( "Last listed author (" + lastListedAuthor + ") is correct." );
85+
echo( "Last listed author (" + lastListedAuthor.cyan + ") is correct." );
8486
}
8587

8688
function getVersions() {
@@ -90,7 +92,7 @@ function getVersions() {
9092

9193
echo( "Validating current version..." );
9294
if ( currentVersion.substr( -3, 3 ) !== "pre" ) {
93-
echo( "The current version is " + currentVersion + "." );
95+
echo( "The current version is " + currentVersion.red + "." );
9496
abort( "The version must be a pre version." );
9597
}
9698

@@ -99,6 +101,10 @@ function getVersions() {
99101
major = parseInt( parts[ 0 ], 10 );
100102
minor = parseInt( parts[ 1 ], 10 );
101103
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+
}
102108
prevVersion = patch === 0 ?
103109
[ major, minor - 1, 0 ].join( "." ) :
104110
[ major, minor, patch - 1 ].join( "." );
@@ -108,15 +114,16 @@ function getVersions() {
108114
}
109115
nextVersion = [ major, minor, patch + 1 ].join( "." ) + "pre";
110116

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 + "." );
113119
}
114120

115-
function tagRelease() {
121+
function buildRelease() {
116122
var pkg;
117123

118-
echo( "Creating release branch..." );
124+
echo( "Creating " + "release".cyan + " branch..." );
119125
git( "checkout -b release", "Error creating release branch." );
126+
echo();
120127

121128
echo( "Updating package.json..." );
122129
pkg = readPackage();
@@ -130,18 +137,27 @@ function tagRelease() {
130137
if ( exec( "grunt manifest" ).code !== 0 ) {
131138
abort( "Error generating manifest files." );
132139
}
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
133149

150+
// TODO: Move build out of dist/
134151
echo( "Committing release artifacts..." );
135152
git( "add *.jquery.json", "Error adding manifest files to git." );
153+
// TODO: Add built files
136154
git( "commit -am 'Tagging the " + newVersion + " release.'",
137155
"Error committing release changes." );
156+
echo();
138157

139158
echo( "Tagging release..." );
140159
git( "tag " + newVersion, "Error tagging " + newVersion + "." );
141160
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." );
145161
}
146162

147163
function pushRelease() {
@@ -152,7 +168,7 @@ function pushRelease() {
152168
function updateBranchVersion() {
153169
var pkg;
154170

155-
echo( "Checking out " + branch + " branch..." );
171+
echo( "Checking out " + branch.cyan + " branch..." );
156172
git( "checkout " + branch, "Error checking out " + branch + " branch." );
157173

158174
echo( "Updating package.json..." );
@@ -163,13 +179,10 @@ function updateBranchVersion() {
163179
echo( "Committing version update..." );
164180
git( "commit -am 'Updating the " + branch + " version to " + nextVersion + ".'",
165181
"Error committing package.json." );
166-
167-
echo();
168-
echo( "Please review the output and generated files as a sanity check." );
169182
}
170183

171184
function pushBranch() {
172-
echo( "Pushing " + branch + " to GitHub..." );
185+
echo( "Pushing " + branch.cyan + " to GitHub..." );
173186
git( "push", "Error pushing to GitHub." );
174187
}
175188

@@ -187,7 +200,6 @@ function generateChangelog() {
187200
// Add ticket references
188201
.map(function( commit ) {
189202
var tickets = [];
190-
// TODO: Don't use .replace() since we're not actually replacing
191203
commit.replace( /Fixe[sd] #(\d+)/g, function( match, ticket ) {
192204
tickets.push( ticket );
193205
});
@@ -207,7 +219,7 @@ function generateChangelog() {
207219
"&col=id&col=component&col=summary&order=component" ) + "\n";
208220

209221
fs.writeFileSync( changelogPath, changelog );
210-
echo( "Stored changelog in " + changelogPath + "." );
222+
echo( "Stored changelog in " + changelogPath.cyan + "." );
211223
}
212224

213225
function gatherContributors() {
@@ -221,6 +233,7 @@ function gatherContributors() {
221233
contributors = contributors.concat(
222234
trac( "/report/22?V=" + newVersion + "&max=-1" )
223235
.split( rnewline )
236+
// Remove header and trailing newline
224237
.slice( 1, -1 ) );
225238

226239
echo( "Sorting contributors..." );
@@ -235,26 +248,16 @@ function gatherContributors() {
235248
}));
236249

237250
fs.writeFileSync( contributorsPath, contributors.join( "\n" ) );
238-
echo( "Stored contributors in " + contributorsPath + "." );
251+
echo( "Stored contributors in " + contributorsPath.cyan + "." );
239252
}
240253

241254
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." );
245258
echo( "Create a Milestone for the next minor release." );
246259
}
247260

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-
258261

259262

260263

@@ -316,30 +319,41 @@ function writePackage( pkg ) {
316319
}
317320

318321
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 ) {
320339
if ( error ) {
321340
console.log( error );
322341
return process.exit( 1 );
323342
}
324343

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" );
330346

331347
fn();
332348
});
333349
}
334350

335351
function section( name ) {
336-
var line = new Array( name.length + 5 ).join( "-" );
337352
return function() {
338353
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( "##" );
343357
echo();
344358
};
345359
}
@@ -353,13 +367,18 @@ function prompt( fn ) {
353367
}
354368

355369
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 );
357371
prompt( fn );
358372
}
359373

374+
function confirmReview( fn ) {
375+
echo( "Please review the output and generated files as a sanity check.".yellow );
376+
confirm( fn );
377+
}
378+
360379
function abort( msg ) {
361-
echo( msg );
362-
echo( "Aborting." );
380+
echo( msg.red );
381+
echo( "Aborting.".red );
363382
exit( 1 );
364383
}
365384

0 commit comments

Comments
 (0)