Skip to content

Commit b3fce4f

Browse files
committed
Add release script
1 parent be5b661 commit b3fce4f

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"build-umd": "webpack modules/index.js umd/react-broadcast.js",
1111
"build-min": "webpack -p modules/index.js umd/react-broadcast.min.js",
1212
"prepublish": "node ./scripts/build.js",
13+
"release": "node ./scripts/release.js",
1314
"test": "npm run lint",
1415
"lint": "eslint modules"
1516
},
@@ -35,6 +36,7 @@
3536
"gzip-size": "^3.0.0",
3637
"in-publish": "^2.0.0",
3738
"pretty-bytes": "^4.0.2",
39+
"readline-sync": "^1.4.4",
3840
"webpack": "^1.13.2"
3941
}
4042
}

scripts/release.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const resolvePath = require('path').resolve
2+
const readFileSync = require('fs').readFileSync
3+
const execSync = require('child_process').execSync
4+
const prompt = require('readline-sync').question
5+
6+
const exec = (command) =>
7+
execSync(command, { stdio: 'inherit' })
8+
9+
const getPackageVersion = () =>
10+
JSON.parse(readFileSync(resolvePath(__dirname, '../package.json'))).version
11+
12+
if (process.cwd() !== resolvePath(__dirname, '..')) {
13+
console.error('The release script must be run from the repo root')
14+
process.exit(1)
15+
}
16+
17+
// Get the next version, which may be specified as a semver
18+
// version number or anything `npm version` recognizes. This
19+
// is a "pre-release" if nextVersion is premajor, preminor,
20+
// prepatch, or prerelease
21+
const nextVersion = prompt(`Next version (current version is ${getPackageVersion()})? `)
22+
const isPrerelease = nextVersion.substr(0, 3) === 'pre' || nextVersion.indexOf('-') !== -1
23+
24+
// 1) Make sure the tests pass
25+
exec('npm test -- --single-run')
26+
27+
// 2) Increment the package version in package.json
28+
// 3) Create a new commit
29+
// 4) Create a v* tag that points to that commit
30+
exec(`npm version ${nextVersion} -m "Version %s"`)
31+
32+
// 5) Push to the same branch on the git remote (GitHub).
33+
// Do this before we publish in case anyone has pushed
34+
// since we last pulled
35+
exec('git push origin')
36+
37+
// 6) Publish to npm. Use the "next" tag for pre-releases,
38+
// "latest" for all others
39+
exec(`npm publish --tag ${isPrerelease ? 'next' : 'latest'}`)
40+
41+
// 7) Push the v* tag to GitHub
42+
exec(`git push -f origin v${getPackageVersion()}`)
43+
44+
// 8) Push the "latest" tag to GitHub
45+
if (!isPrerelease) {
46+
exec('git tag -f latest')
47+
exec('git push -f origin latest')
48+
}

0 commit comments

Comments
 (0)