1
1
#!env node
2
2
"use strict" ;
3
3
4
- let pkg = require ( '../package.json' ) ;
5
- let version = pkg . version ;
6
- let hybridVersion = require ( '../../angular-hybrid/package.json' ) . version ;
4
+ const CONFIG = require ( './artifact_tagging.json' ) ;
5
+ const COMMIT_ARTIFACTS = CONFIG . COMMIT_ARTIFACTS ;
7
6
8
7
let shx = require ( 'shelljs' ) ;
9
8
let readlineSync = require ( 'readline-sync' ) ;
@@ -12,9 +11,12 @@ let path = require('path');
12
11
let util = require ( './util' ) ;
13
12
let _exec = util . _exec ;
14
13
14
+ let pkg = require ( '../package.json' ) ;
15
+ let version = pkg . version ;
16
+
15
17
shx . cd ( path . join ( __dirname , '..' ) ) ;
16
18
17
- var widen = false ;
19
+ var widen = false , npm = false , githubtag = false ;
18
20
var coreDep = pkg . dependencies [ '@uirouter/core' ] ;
19
21
var isNarrow = / ^ [ [ = ~ ] ? ( \d .* ) / . exec ( coreDep ) ;
20
22
var widenedDep = isNarrow && '^' + isNarrow [ 1 ] ;
@@ -23,6 +25,21 @@ if (isNarrow && readlineSync.keyInYN('Widen @uirouter/core dependency from ' + c
23
25
widen = false ;
24
26
}
25
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
+
26
43
const YYYYMMDD = ( function ( ) {
27
44
var date = new Date ( ) ;
28
45
var year = date . getFullYear ( ) ;
@@ -37,9 +54,17 @@ const YYYYMMDD = (function() {
37
54
} ) ( ) ;
38
55
39
56
let tagname = `SNAPSHOT-${ YYYYMMDD } ` ;
40
- 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
+ }
41
62
42
- if ( ! readlineSync . keyInYN ( `Ready to publish ${ tagname } tag?` ) ) {
63
+ if ( npm ) {
64
+ pkgver += readlineSync . question ( `Suffix for package version ${ pkgver } (optional)?` ) ;
65
+ }
66
+
67
+ if ( ! readlineSync . keyInYN ( `Ready to publish ${ label } ?` ) ) {
43
68
process . exit ( 1 ) ;
44
69
}
45
70
@@ -49,18 +74,36 @@ util.ensureCleanMaster('master');
49
74
_exec ( `git checkout -b ${ tagname } -prep` ) ;
50
75
51
76
pkg . dependencies [ '@uirouter/core' ] = widenedDep ;
52
- // pkg.version = tagname ;
77
+ pkg . version += pkgver ;
53
78
54
79
fs . writeFileSync ( "package.json" , JSON . stringify ( pkg , undefined , 2 ) ) ;
55
- _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
+ }
56
97
57
- _exec ( 'npm run package' ) ;
98
+ if ( githubtag ) {
99
+ _exec ( `git add --force ${ COMMIT_ARTIFACTS . join ( ' ' ) } ` ) ;
100
+ _exec ( `git rm yarn.lock` ) ;
58
101
59
- _exec ( `git add --force lib _bundles package.json` ) ;
60
- _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
+ }
61
106
62
- _exec ( `git commit -m 'chore(*): commiting build files'` ) ;
63
- _exec ( `git tag ${ tagname } ` ) ;
64
- _exec ( `git push -u origin ${ tagname } ` ) ;
65
107
_exec ( `git checkout master` ) ;
66
108
_exec ( `git branch -D ${ tagname } -prep` ) ;
109
+
0 commit comments