1
1
#!env node
2
2
"use strict" ;
3
3
4
- const COMMIT_ARTIFACTS = [ 'lib' , 'lib-esm' , 'release' , 'package.json' ] ;
4
+ const CONFIG = require ( './artifact_tagging.json' ) ;
5
+ const COMMIT_ARTIFACTS = CONFIG . COMMIT_ARTIFACTS ;
5
6
6
7
let shx = require ( 'shelljs' ) ;
7
8
let readlineSync = require ( 'readline-sync' ) ;
@@ -15,7 +16,7 @@ let version = pkg.version;
15
16
16
17
shx . cd ( path . join ( __dirname , '..' ) ) ;
17
18
18
- var widen = false ;
19
+ var widen = false , npm = false , githubtag = false ;
19
20
var coreDep = pkg . dependencies [ '@uirouter/core' ] ;
20
21
var isNarrow = / ^ [ [ = ~ ] ? ( \d .* ) / . exec ( coreDep ) ;
21
22
var widenedDep = isNarrow && '^' + isNarrow [ 1 ] ;
@@ -24,6 +25,21 @@ if (isNarrow && readlineSync.keyInYN('Widen @uirouter/core dependency from ' + c
24
25
widen = false ;
25
26
}
26
27
28
+ if ( readlineSync . keyInYN ( 'Publish to NPM' ) ) {
29
+ npm = true ;
30
+ }
31
+
32
+
33
+ if ( readlineSync . keyInYN ( 'publish to Github Tag?' ) ) {
34
+ githubtag = true ;
35
+ }
36
+
37
+ if ( ! npm && ! githubtag ) {
38
+ process . exit ( 1 ) ;
39
+ }
40
+
41
+ var label = githubtag && npm ? "npm package and github tag" : npm ? "npm package" : "github tag" ;
42
+
27
43
const YYYYMMDD = ( function ( ) {
28
44
var date = new Date ( ) ;
29
45
var year = date . getFullYear ( ) ;
@@ -38,9 +54,17 @@ const YYYYMMDD = (function() {
38
54
} ) ( ) ;
39
55
40
56
let tagname = `SNAPSHOT-${ YYYYMMDD } ` ;
41
- tagname += readlineSync . question ( `Suffix for tag ${ tagname } (optional)?` ) ;
57
+ let pkgver = `-SNAPSHOT.${ YYYYMMDD } ` ;
58
+
59
+ if ( githubtag ) {
60
+ tagname += readlineSync . question ( `Suffix for tag ${ tagname } (optional)?` ) ;
61
+ }
62
+
63
+ if ( npm ) {
64
+ pkgver += readlineSync . question ( `Suffix for package version ${ pkgver } (optional)?` ) ;
65
+ }
42
66
43
- if ( ! readlineSync . keyInYN ( `Ready to publish ${ tagname } tag ?` ) ) {
67
+ if ( ! readlineSync . keyInYN ( `Ready to publish ${ label } ?` ) ) {
44
68
process . exit ( 1 ) ;
45
69
}
46
70
@@ -50,18 +74,36 @@ util.ensureCleanMaster('master');
50
74
_exec ( `git checkout -b ${ tagname } -prep` ) ;
51
75
52
76
pkg . dependencies [ '@uirouter/core' ] = widenedDep ;
53
- // pkg.version = tagname ;
77
+ pkg . version += pkgver ;
54
78
55
79
fs . writeFileSync ( "package.json" , JSON . stringify ( pkg , undefined , 2 ) ) ;
56
- _exec ( 'git commit -m "Widening @uirouter/core dependency range to ' + widenedDep + '" package.json' ) ;
80
+ _exec ( `git commit -m "Widening @uirouter/core dependency range to ${ widenedDep } " package.json` ) ;
81
+
82
+ _exec ( `npm run package` ) ;
83
+
84
+ if ( npm ) {
85
+ let output = _exec ( `npm dist-tag ls ${ pkg . name } ` ) . stdout ;
86
+ let latest = output . split ( / [ \r \n ] / )
87
+ . map ( line => line . split ( ": " ) )
88
+ . filter ( linedata => linedata [ 0 ] === 'latest' ) [ 0 ] ;
89
+
90
+ if ( ! latest ) {
91
+ throw new Error ( `Could not determine value of "latest" dist-tag for ${ pkg . name } ` ) ;
92
+ }
93
+
94
+ _exec ( `npm publish` ) ;
95
+ _exec ( `npm dist-tag add ${ pkg . name } @${ latest } latest` ) ;
96
+ }
57
97
58
- _exec ( 'npm run package' ) ;
98
+ if ( githubtag ) {
99
+ _exec ( `git add --force ${ COMMIT_ARTIFACTS . join ( ' ' ) } ` ) ;
100
+ _exec ( `git rm yarn.lock` ) ;
59
101
60
- _exec ( `git add --force ${ COMMIT_ARTIFACTS . join ( ' ' ) } ` ) ;
61
- _exec ( `git rm yarn.lock` ) ;
102
+ _exec ( `git commit -m 'chore(*): commiting build files'` ) ;
103
+ _exec ( `git tag ${ tagname } ` ) ;
104
+ _exec ( `git push -u origin ${ tagname } ` ) ;
105
+ }
62
106
63
- _exec ( `git commit -m 'chore(*): commiting build files'` ) ;
64
- _exec ( `git tag ${ tagname } ` ) ;
65
- _exec ( `git push -u origin ${ tagname } ` ) ;
66
107
_exec ( `git checkout master` ) ;
67
108
_exec ( `git branch -D ${ tagname } -prep` ) ;
109
+
0 commit comments