@@ -7,20 +7,19 @@ const execa = require('execa');
77const inquirer = require ( 'inquirer' ) ;
88const Listr = require ( 'listr' ) ;
99const fs = require ( 'fs-extra' ) ;
10- const path = require ( 'path' ) ;
1110const semver = require ( 'semver' ) ;
11+ const common = require ( './common' ) ;
12+ const path = require ( 'path' ) ;
1213
13- const rootDir = path . join ( __dirname , '../' ) ;
1414
1515async function main ( ) {
1616 try {
17- await checkGit ( ) ;
17+ await common . checkGit ( ) ;
1818
1919 const version = await askVersion ( ) ;
2020 await checkTagVersion ( version ) ;
2121 await prepareProject ( 'core' , version ) ;
22- await link ( 'core' , 'angular' ) ;
23- await prepareProject ( 'angular' , version ) ;
22+ await prepareProject ( 'angular' , version , [ '@ionic/core' ] ) ;
2423
2524 await generateChangeLog ( version ) ;
2625 process . exit ( 0 ) ;
@@ -30,46 +29,6 @@ async function main() {
3029 }
3130}
3231
33- async function checkGit ( ) {
34- const listr = new Listr ( [
35- {
36- title : 'Check npm version' ,
37- skip : ( ) => isVersionLower ( '6.0.0' , process . version ) ,
38- task : ( ) => execa . stdout ( 'npm' , [ 'version' , '--json' ] ) . then ( json => {
39- const versions = JSON . parse ( json ) ;
40- if ( ! satisfies ( versions . npm , '>=2.15.8 <3.0.0 || >=3.10.1' ) ) {
41- throw new Error ( `npm@${ versions . npm } has known issues publishing when running Node.js 6. Please upgrade npm or downgrade Node and publish again. https://github.com/npm/npm/issues/5082` ) ;
42- }
43- } )
44- } ,
45- {
46- title : 'Check current branch' ,
47- task : ( ) => execa . stdout ( 'git' , [ 'symbolic-ref' , '--short' , 'HEAD' ] ) . then ( branch => {
48- if ( branch !== 'master' && branch !== 'core' ) {
49- throw new Error ( 'Not on `master` or `core` branch' ) ;
50- }
51- } )
52- } ,
53- {
54- title : 'Check local working tree' ,
55- task : ( ) => execa . stdout ( 'git' , [ 'status' , '--porcelain' ] ) . then ( status => {
56- if ( status !== '' ) {
57- throw new Error ( 'Unclean working tree. Commit or stash changes first.' ) ;
58- }
59- } )
60- } ,
61- {
62- title : 'Check remote history' ,
63- task : ( ) => execa . stdout ( 'git' , [ 'rev-list' , '--count' , '--left-only' , '@{u}...HEAD' ] ) . then ( result => {
64- if ( result !== '0' ) {
65- throw new Error ( 'Remote history differs. Please pull changes.' ) ;
66- }
67- } )
68- }
69- ] ) ;
70- await listr . run ( ) ;
71- }
72-
7332async function checkTagVersion ( version ) {
7433 const listr = new Listr ( [
7534 {
@@ -106,7 +65,7 @@ async function checkTagVersion(version) {
10665
10766
10867async function askVersion ( ) {
109- const pkg = readPkg ( 'core' ) ;
68+ const pkg = common . readPkg ( 'core' ) ;
11069 const oldVersion = pkg . version ;
11170
11271 const prompts = [
@@ -158,15 +117,14 @@ async function askVersion() {
158117 return version ;
159118}
160119
161- async function prepareProject ( project , version ) {
162- const projectRoot = path . join ( rootDir , project ) ;
163- const pkg = readPkg ( project ) ;
120+ async function prepareProject ( project , version , dependencies ) {
121+ const projectRoot = common . projectPath ( project ) ;
122+ const pkg = common . readPkg ( project ) ;
164123 const oldVersion = pkg . version ;
165124
166- console . log ( `\nPrepare to publish a new version of ${ chalk . bold . magenta ( pkg . name ) } ${ chalk . dim ( `(${ oldVersion } )` ) } \n` ) ;
167-
125+ console . log ( `\nPrepare to publish a new version of ${ chalk . bold . magenta ( pkg . name ) } ${ chalk . dim ( `(${ oldVersion } ) => (${ version } )` ) } \n` ) ;
168126
169- const listr = new Listr ( [
127+ const tasks = [
170128 {
171129 title : 'Validate version' ,
172130 task : ( ) => {
@@ -177,12 +135,28 @@ async function prepareProject(project, version) {
177135 } ,
178136 {
179137 title : 'Cleanup' ,
180- task : ( ) => fs . remove ( 'node_modules' )
138+ task : ( ) => fs . remove ( path . join ( projectRoot , 'node_modules' ) )
181139 } ,
182140 {
183141 title : 'Install npm dependencies' ,
184142 task : ( ) => execa ( 'npm' , [ 'install' ] , { cwd : projectRoot } ) ,
185- } ,
143+ } ] ;
144+
145+ if ( dependencies && dependencies . length > 0 ) {
146+ tasks . push (
147+ {
148+ title : 'Linking local dependencies' ,
149+ task : ( ) => {
150+ return new Listr ( dependencies . map ( dep => ( {
151+ title : dep ,
152+ task : ( ) => execa ( 'npm' , [ 'link' , dep ] , { cwd : projectRoot } ) ,
153+ } ) ) ) ;
154+ }
155+ }
156+ ) ;
157+ }
158+
159+ tasks . push (
186160 {
187161 title : 'Run lint' ,
188162 task : ( ) => execa ( 'npm' , [ 'run' , 'lint' ] , { cwd : projectRoot } )
@@ -196,15 +170,22 @@ async function prepareProject(project, version) {
196170 task : ( ) => execa ( 'npm' , [ 'test' ] , { cwd : projectRoot } )
197171 } ,
198172 {
199- title : 'Set package.json version' ,
173+ title : 'Linking' ,
174+ task : ( ) => execa ( 'npm' , [ 'link' ] , { cwd : projectRoot } )
175+ } ,
176+ {
177+ title : `Updating ${ project } /package.json version ${ chalk . dim ( `(${ version } )` ) } ` ,
200178 task : ( ) => execa ( 'npm' , [ 'version' , version ] , { cwd : projectRoot } ) ,
201179 } ,
202- ] , { showSubtasks : false } ) ;
180+ ) ;
181+
182+ const listr = new Listr ( tasks , { showSubtasks : false } ) ;
203183 await listr . run ( ) ;
204184}
205185
206186
207187async function generateChangeLog ( ) {
188+ const rootDir = common . rootPath ( ) ;
208189 const listr = new Listr ( [ {
209190 title : 'Generate CHANGELOG' ,
210191 task : ( ) => execa ( 'npm' , [ 'run' , 'changelog' ] , { cwd : rootDir } ) ,
@@ -218,7 +199,7 @@ const PRERELEASE_VERSIONS = ['prepatch', 'preminor', 'premajor', 'prerelease'];
218199
219200const isValidVersion = input => Boolean ( semver . valid ( input ) ) ;
220201
221- const isValidVersionInput = input => SEMVER_INCREMENTS . indexOf ( input ) !== - 1 || isValidVersion ( input ) ;
202+ const isValidVersionInput = input => SEMVER_INCREMENTS . indexOf ( input ) !== - 1 || common . isValidVersion ( input ) ;
222203
223204const isPrereleaseVersion = version => PRERELEASE_VERSIONS . indexOf ( version ) !== - 1 || Boolean ( semver . prerelease ( version ) ) ;
224205
@@ -231,23 +212,13 @@ function getNewVersion(oldVersion, input) {
231212} ;
232213
233214const isVersionGreater = ( oldVersion , newVersion ) => {
234- if ( ! isValidVersion ( newVersion ) ) {
215+ if ( ! common . isValidVersion ( newVersion ) ) {
235216 throw new Error ( 'Version should be a valid semver version.' ) ;
236217 }
237218
238219 return semver . gt ( newVersion , oldVersion ) ;
239220} ;
240221
241- const isVersionLower = ( oldVersion , newVersion ) => {
242- if ( ! isValidVersion ( newVersion ) ) {
243- throw new Error ( 'Version should be a valid semver version.' ) ;
244- }
245-
246- return semver . lt ( newVersion , oldVersion ) ;
247- } ;
248-
249- const satisfies = ( version , range ) => semver . satisfies ( version , range ) ;
250-
251222
252223function prettyVersionDiff ( oldVersion , inc ) {
253224 const newVersion = getNewVersion ( oldVersion , inc ) . split ( '.' ) ;
@@ -270,11 +241,4 @@ function prettyVersionDiff(oldVersion, inc) {
270241 return output . join ( chalk . reset . dim ( '.' ) ) ;
271242}
272243
273-
274- function readPkg ( project ) {
275- const packageJsonPath = path . join ( rootDir , project , 'package.json' ) ;
276- return JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf-8' ) ) ;
277- }
278-
279-
280244main ( ) ;
0 commit comments