1
- const resolvePath = require ( "path" ) . resolve ;
2
- const readFileSync = require ( "fs" ) . readFileSync ;
1
+ const fs = require ( "fs" ) ;
2
+ const path = require ( "path" ) ;
3
3
const execSync = require ( "child_process" ) . execSync ;
4
4
const prompt = require ( "readline-sync" ) . question ;
5
5
6
+ process . chdir ( path . resolve ( __dirname , ".." ) ) ;
7
+
6
8
const exec = command => execSync ( command , { stdio : "inherit" } ) ;
7
9
8
10
const 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 ;
15
13
16
14
// Get the next version, which may be specified as a semver
17
15
// version number or anything `npm version` recognizes. This
@@ -20,26 +18,20 @@ if (process.cwd() !== resolvePath(__dirname, "..")) {
20
18
const nextVersion = prompt (
21
19
`Next version (current version is ${ getPackageVersion ( ) } )? `
22
20
) ;
23
- const isPrerelease = nextVersion . substring ( 0 , 3 ) === "pre" ;
21
+ const isPrerelease =
22
+ nextVersion . substr ( 0 , 3 ) === "pre" || nextVersion . indexOf ( "-" ) !== - 1 ;
24
23
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" ) ;
29
26
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"` ) ;
33
31
34
32
// 5) Publish to npm. Use the "next" tag for pre-releases,
35
33
// "latest" for all others
36
34
exec ( `npm publish --tag ${ isPrerelease ? "next" : "latest" } ` ) ;
37
35
38
36
// 6) Push the v* tag to GitHub
39
37
exec ( `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