1- const resolvePath = require ( "path" ) . resolve ;
2- const readFileSync = require ( "fs" ) . readFileSync ;
1+ const fs = require ( "fs" ) ;
2+ const path = require ( "path" ) ;
33const execSync = require ( "child_process" ) . execSync ;
44const prompt = require ( "readline-sync" ) . question ;
55
6+ process . chdir ( path . resolve ( __dirname , ".." ) ) ;
7+
68const exec = command => execSync ( command , { stdio : "inherit" } ) ;
79
810const getPackageVersion = ( ) =>
9- JSON . parse ( readFileSync ( resolvePath ( __dirname , "../package.json" ) ) ) . version ;
10-
11- if ( process . cwd ( ) !== resolvePath ( __dirname , ".." ) ) {
12- console . error ( "The release script must be run from the repo root" ) ;
13- process . exit ( 1 ) ;
14- }
11+ JSON . parse ( fs . readFileSync ( path . resolve ( __dirname , "../package.json" ) ) )
12+ . version ;
1513
1614// Get the next version, which may be specified as a semver
1715// version number or anything `npm version` recognizes. This
@@ -20,26 +18,20 @@ if (process.cwd() !== resolvePath(__dirname, "..")) {
2018const nextVersion = prompt (
2119 `Next version (current version is ${ getPackageVersion ( ) } )? `
2220) ;
23- const isPrerelease = nextVersion . substring ( 0 , 3 ) === "pre" ;
21+ const isPrerelease =
22+ nextVersion . substr ( 0 , 3 ) === "pre" || nextVersion . indexOf ( "-" ) !== - 1 ;
2423
25- // 1) Increment the package version in package.json
26- // 2) Create a new commit
27- // 3) Create a v* tag that points to that commit
28- exec ( `npm version ${ nextVersion } -m "Version %s"` ) ;
24+ // 1) Make sure the tests pass
25+ exec ( "npm test" ) ;
2926
30- // 4) Push to GitHub master. Do this before we publish in
31- // case anyone has pushed to GitHub since we last pulled
32- exec ( "git push origin master" ) ;
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"` ) ;
3331
3432// 5) Publish to npm. Use the "next" tag for pre-releases,
3533// "latest" for all others
3634exec ( `npm publish --tag ${ isPrerelease ? "next" : "latest" } ` ) ;
3735
3836// 6) Push the v* tag to GitHub
3937exec ( `git push -f origin v${ getPackageVersion ( ) } ` ) ;
40-
41- // 7) Push the "latest" tag to GitHub
42- if ( ! isPrerelease ) {
43- exec ( "git tag -f latest" ) ;
44- exec ( "git push -f origin latest" ) ;
45- }
0 commit comments