-
Notifications
You must be signed in to change notification settings - Fork 96
/
release
executable file
·99 lines (71 loc) · 2.9 KB
/
release
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
#!/usr/bin/env node
var path = require('path');
var CoreUtil = require('oae-release-tools').CoreUtil;
var PackageUtil = require('oae-release-tools').PackageUtil;
var ReleaseUtil = require('oae-release-tools').ReleaseUtil;
//////////////////////
// HANDLE ARGUMENTS //
//////////////////////
var argv = require('optimist')
.usage('Usage: $0 [-s] [-p] -r <remote repository> -v <release version>')
.alias('h', 'help')
.describe('h', 'Show this help information')
.alias('r', 'remote')
.describe('r', 'The remote repository to push the release commits into (e.g., origin)')
.demand('r')
.alias('s', 'skip-tests')
.describe('s', 'Skip the unit tests in the release process')
.alias('p', 'package')
.describe('p', 'Generate a package tarball (tar.gz) of the tag before erasing npm-shrinkwrap from master')
.alias('v', 'version')
.describe('v', 'Which version to release (e.g., 0.4.1)')
.demand('v')
.argv;
/////////////////////
// PERFORM RELEASE //
/////////////////////
var packageJsonPath = path.resolve('package.json');
var packageDest = 'dist';
var remoteName = argv.r;
var version = argv.v;
// Display the help if requested
if (argv.h) {
require('optimist').showHelp();
return process.exit(0);
}
// Ensure everything is OK to do a release
ReleaseUtil.validateRelease(remoteName, 3);
// If they specified to package after the tag, verify everything is OK to package before doing anything
if (argv.p) {
PackageUtil.validatePackage(packageDest, 3);
}
// Load and validate the package.json
var packageJson = CoreUtil.loadPackageJson(packageJsonPath, 'Hilary', 4);
// Ensure our target version is a valid jump from where we are
ReleaseUtil.validateTargetVersion(packageJson, argv.v, remoteName, 5);
// Optionally, run the tests right now
if (!argv.s) {
CoreUtil.runUnitTests(6);
} else {
CoreUtil.logWarn('Skipping unit tests because of -s parameter');
}
// Bump the version in package.json to the target version
ReleaseUtil.bumpPackageJsonVersion(packageJsonPath, packageJson.version, argv.v, 7);
// Shrinkwrap our dependencies
ReleaseUtil.shrinkwrap(8);
// Commit the shrinkwrap, version and tag the release
CoreUtil.exec('git add npm-shrinkwrap.json', 'Failed to add npm-shrinkwrap.json to the git index', 9);
ReleaseUtil.gitCommitVersionAndTag(argv.v, remoteName, 9);
// Optionally package up the release on the tag
if (argv.p || argv.u) {
var packageCmd = 'bin/package -s';
// Pass along the upload argument if specified
if (argv.u) {
packageCmd += 'u';
}
// Skip the tests and just use the version from package.json
CoreUtil.exec(packageCmd, 'Error distributing the release', 10, true);
}
// Remove the shrinkwrap and commit it for master
ReleaseUtil.gitRemoveShrinkwrapAndCommit(argv.v, remoteName, 11);
CoreUtil.logSuccess('Successfully released Hilary '.text + argv.v.white + ' to the remote repository '.text + remoteName.white);