Skip to content

Commit 0ad7e22

Browse files
committed
Util: Release.exec() aborts on failure
Removed Release.git() as it no longer provides much value. Fixes gh-22 Closes jquerygh-39
1 parent c707fc0 commit 0ad7e22

File tree

6 files changed

+67
-68
lines changed

6 files changed

+67
-68
lines changed

lib/cdn.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = function( Release ) {
3131

3232
console.log( "Cloning " + remote.cyan + "..." );
3333
Release.chdir( Release.dir.base );
34-
Release.git( "clone " + remote + " " + local, "Error cloning CDN repo." );
34+
Release.exec( "git clone " + remote + " " + local, "Error cloning CDN repo." );
3535
console.log();
3636

3737
return local;
@@ -49,13 +49,13 @@ module.exports = function( Release ) {
4949

5050
console.log( "Adding files..." );
5151
Release.chdir( targetCdn );
52-
Release.git( "add ." , "Error adding files." );
53-
Release.git( "commit -m '" + commitMessage + "'" , "Error commiting files." );
52+
Release.exec( "git add ." , "Error adding files." );
53+
Release.exec( "git commit -m '" + commitMessage + "'" , "Error commiting files." );
5454
},
5555

5656
_pushToCdn: function() {
5757
Release.chdir( projectCdn() );
58-
Release.git( "push", "Error pushing to CDN." );
58+
Release.exec( "git push", "Error pushing to CDN." );
5959
console.log();
6060
}
6161
});

lib/git.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
11
module.exports = function( Release ) {
22

33
Release.define({
4-
git: function( command, errorMessage ) {
5-
var result = Release.exec( "git " + command );
6-
if ( result.code !== 0 ) {
7-
Release.abort( errorMessage );
8-
}
9-
10-
return result.output;
11-
},
12-
134
gitLog: function( format ) {
14-
var result = Release.exec(
15-
"git log " + Release.prevVersion + ".." + Release.newVersion + " " +
16-
"--format='" + format + "'",
17-
{ silent: true }
18-
);
19-
20-
if ( result.code !== 0 ) {
21-
Release.abort( "Error getting git log." );
22-
}
5+
var result = Release.exec({
6+
command: "git log " + Release.prevVersion + ".." + Release.newVersion + " " +
7+
"--format='" + format + "'",
8+
silent: true
9+
}, "Error getting git log." );
2310

24-
result = result.output.split( /\r?\n/ );
11+
result = result.split( /\r?\n/ );
2512
if ( result[ result.length - 1 ] === "" ) {
2613
result.pop();
2714
}

lib/npm.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
module.exports = function( Release ) {
22
Release.define({
33
_getNpmUser: function() {
4-
var user = Release.exec( "npm whoami", { silent: true } );
4+
var user = Release.exec({
5+
command: "npm whoami",
6+
silent: true
7+
}, "Error getting npm user." );
58

6-
if ( user.code !== 0 ) {
7-
Release.abort( "Error getting npm user." );
8-
}
9-
10-
if ( /^Not authed/.test( user.output ) ) {
9+
if ( /^Not authed/.test( user ) ) {
1110
Release.abort( "You are not registered with npm." );
1211
}
1312

14-
return user.output.trim();
13+
return user.trim();
1514
},
1615

1716
_getNpmOwners: function( npmPackage ) {
18-
var owners = Release.exec( "npm owner ls " + npmPackage, { silent: true } );
19-
20-
if ( owners.code !== 0 ) {
21-
Release.abort( "Error getting npm owners." );
22-
}
17+
var owners = Release.exec({
18+
command: "npm owner ls " + npmPackage,
19+
silent: true
20+
}, "Error getting npm owners." );
2321

24-
return owners.output.trim().split( "\n" ).map(function( owner ) {
22+
return owners.trim().split( "\n" ).map(function( owner ) {
2523
return owner.split( " " )[ 0 ];
2624
});
2725
},

lib/repo.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,25 @@ Release.define({
99

1010
Release.chdir( Release.dir.base );
1111
console.log( "Cloning " + Release.remote.cyan + "..." );
12-
Release.git( "clone " + Release.remote + " " + Release.dir.repo, "Error cloning repo." );
12+
Release.exec( "git clone " + Release.remote + " " + Release.dir.repo,
13+
"Error cloning repo." );
1314
Release.chdir( Release.dir.repo );
1415

1516
console.log( "Checking out " + Release.branch.cyan + " branch..." );
16-
Release.git( "checkout " + Release.branch, "Error checking out branch." );
17+
Release.exec( "git checkout " + Release.branch, "Error checking out branch." );
1718
console.log();
1819

1920
console.log( "Installing dependencies..." );
20-
if ( Release.exec( "npm install" ).code !== 0 ) {
21-
Release.abort( "Error installing dependencies." );
22-
}
21+
Release.exec( "npm install", "Error installing dependencies." );
2322
console.log();
2423

2524
projectRelease = require( Release.dir.repo + "/build/release" );
2625

2726
if ( projectRelease.dependencies ) {
2827
console.log( "Installing release dependencies..." );
2928
releaseDependencies = projectRelease.dependencies.join( " " );
30-
if ( Release.exec( "npm install " + releaseDependencies ).code !== 0 ) {
31-
Release.abort( "Error installing release dependencies." );
32-
}
29+
Release.exec( "npm install " + releaseDependencies,
30+
"Error installing release dependencies." );
3331
console.log();
3432
}
3533

@@ -67,11 +65,11 @@ Release.define({
6765
.pop();
6866

6967
Release.chdir( Release.dir.repo );
70-
result = Release.exec( "grunt authors", { silent: true } );
71-
if ( result.code !== 0 ) {
72-
Release.abort( "Error getting list of authors." );
73-
}
74-
lastActualAuthor = result.output.split( /\r?\n/ ).splice( -4, 1 )[ 0 ];
68+
result = Release.exec({
69+
command: "grunt authors",
70+
silent: true
71+
}, "Error getting list of authors." );
72+
lastActualAuthor = result.split( /\r?\n/ ).splice( -4, 1 )[ 0 ];
7573

7674
if ( lastListedAuthor !== lastActualAuthor ) {
7775
console.log( "Last listed author is " + lastListedAuthor.red + "." );
@@ -145,8 +143,8 @@ Release.define({
145143
Release.abort(
146144
"This script is not smart enough to handle major release (eg. 2.0.0)." );
147145
} else if ( patch === 0 ) {
148-
Release.prevVersion = Release.git(
149-
"for-each-ref --count=1 --sort=-authordate --format='%(refname:short)' " +
146+
Release.prevVersion = Release.exec(
147+
"git for-each-ref --count=1 --sort=-authordate --format='%(refname:short)' " +
150148
"refs/tags/" + [ major, minor - 1 ].join( "." ) + "*"
151149
).trim();
152150
} else {
@@ -166,7 +164,7 @@ Release.define({
166164

167165
Release.chdir( Release.dir.repo );
168166
console.log( "Creating " + "release".cyan + " branch..." );
169-
Release.git( "checkout -b release", "Error creating release branch." );
167+
Release.exec( "git checkout -b release", "Error creating release branch." );
170168
console.log();
171169

172170
Release._setVersion( Release.newVersion );
@@ -199,14 +197,15 @@ Release.define({
199197

200198
Release.chdir( Release.dir.repo );
201199
console.log( "Committing release artifacts..." );
202-
Release.git( "add -f " + paths.join( " " ), "Error adding release artifacts to git." );
203-
Release.git( "commit -m '" + Release.newVersion + "'",
200+
Release.exec( "git add -f " + paths.join( " " ), "Error adding release artifacts to git." );
201+
Release.exec( "git commit -m '" + Release.newVersion + "'",
204202
"Error committing release changes." );
205203
console.log();
206204

207205
console.log( "Tagging release..." );
208-
Release.git( "tag " + Release.newVersion, "Error tagging " + Release.newVersion + "." );
209-
Release.tagTime = Release.git( "log -1 --format='%ad'",
206+
Release.exec( "git tag " + Release.newVersion,
207+
"Error tagging " + Release.newVersion + "." );
208+
Release.tagTime = Release.exec( "git log -1 --format='%ad'",
210209
"Error getting tag timestamp." ).trim();
211210
},
212211

@@ -217,28 +216,28 @@ Release.define({
217216
_pushRelease: function() {
218217
Release.chdir( Release.dir.repo );
219218
console.log( "Pushing release to git repo..." );
220-
Release.git( "push --tags", "Error pushing tags to git repo." );
219+
Release.exec( "git push --tags", "Error pushing tags to git repo." );
221220
},
222221

223222
_updateBranchVersion: function() {
224223
Release.chdir( Release.dir.repo );
225224
console.log( "Checking out " + Release.branch.cyan + " branch..." );
226-
Release.git( "checkout " + Release.branch,
225+
Release.exec( "git checkout " + Release.branch,
227226
"Error checking out " + Release.branch + " branch." );
228227

229228
// Update all JSON versions
230229
Release._setVersion( Release.nextVersion );
231230

232231
console.log( "Committing version update..." );
233-
Release.git( "commit -am 'Build: Updating the " + Release.branch +
232+
Release.exec( "git commit -am 'Build: Updating the " + Release.branch +
234233
" version to " + Release.nextVersion + ".'",
235234
"Error committing package.json." );
236235
},
237236

238237
_pushBranch: function() {
239238
Release.chdir( Release.dir.repo );
240239
console.log( "Pushing " + Release.branch.cyan + " to GitHub..." );
241-
Release.git( "push", "Error pushing to GitHub." );
240+
Release.exec( "git push", "Error pushing to GitHub." );
242241
}
243242
});
244243

lib/trac.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ module.exports = function( Release ) {
22

33
Release.define({
44
trac: function( path ) {
5-
var tracUrl = "http://bugs." + Release.project + ".com",
6-
result = Release.exec( "curl -s '" + tracUrl + path + "&format=tab'", { silent: true });
5+
var tracUrl = "http://bugs." + Release.project + ".com";
76

8-
if ( result.code !== 0 ) {
9-
Release.abort( "Error getting Trac data." );
10-
}
11-
12-
return result.output;
7+
return Release.exec({
8+
command: "curl -s '" + tracUrl + path + "&format=tab'",
9+
silent: true
10+
}, "Error getting Trac data." );
1311
}
1412
});
1513

lib/util.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,24 @@ require( "colors" );
55
module.exports = function( Release ) {
66

77
Release.define({
8-
exec: shell.exec,
8+
exec: function( _options, errorMessage ) {
9+
var result,
10+
command = _options.command || _options,
11+
options = {};
12+
13+
if ( _options.silent ) {
14+
options.silent = true;
15+
}
16+
17+
errorMessage = errorMessage || "Error executing command: " + command;
18+
19+
result = shell.exec( command, options );
20+
if ( result.code !== 0 ) {
21+
Release.abort( errorMessage );
22+
}
23+
24+
return result.output;
25+
},
926

1027
chdir: function( directory ) {
1128
console.log( "Changing working directory to " + directory.cyan + "." );

0 commit comments

Comments
 (0)