17
17
18
18
import { spawn , exec } from 'child-process-promise' ;
19
19
import ora from 'ora' ;
20
+ import { createPromptModule } from 'inquirer' ;
20
21
import { projectRoot , readPackageJson } from '../utils' ;
21
22
import simpleGit from 'simple-git/promise' ;
22
23
23
24
import { mapWorkspaceToPackages } from '../release/utils/workspace' ;
24
25
import { inc } from 'semver' ;
25
- import { writeFile as _writeFile } from 'fs' ;
26
+ import { writeFile as _writeFile , rmdirSync , existsSync } from 'fs' ;
27
+ import { resolve } from 'path' ;
26
28
import { promisify } from 'util' ;
27
29
import chalk from 'chalk' ;
28
30
import Listr from 'listr' ;
29
31
import { prepare as prepareFirestoreForRelease } from './prepare-firestore-for-exp-release' ;
30
32
import * as yargs from 'yargs' ;
31
33
34
+ const prompt = createPromptModule ( ) ;
32
35
const argv = yargs
33
36
. options ( {
34
37
dryRun : {
@@ -79,36 +82,79 @@ async function publishExpPackages({ dryRun }: { dryRun: boolean }) {
79
82
*/
80
83
const versions = await updatePackageNamesAndVersions ( packagePaths ) ;
81
84
85
+ let versionCheckMessage =
86
+ '\r\nAre you sure these are the versions you want to publish?\r\n' ;
87
+ for ( const [ pkgName , version ] of versions ) {
88
+ versionCheckMessage += `${ pkgName } : ${ version } \n` ;
89
+ }
90
+ const { versionCheck } = await prompt ( [
91
+ {
92
+ type : 'confirm' ,
93
+ name : 'versionCheck' ,
94
+ message : versionCheckMessage ,
95
+ default : false
96
+ }
97
+ ] ) ;
98
+
99
+ if ( ! versionCheck ) {
100
+ throw new Error ( 'Version check failed' ) ;
101
+ }
102
+
82
103
/**
83
- * Do not publish to npm and create tags if it's a dryrun
104
+ * Release packages to NPM
84
105
*/
85
- if ( ! dryRun ) {
86
- /**
87
- * Release packages to NPM
88
- */
89
- await publishToNpm ( packagePaths ) ;
106
+ await publishToNpm ( packagePaths , dryRun ) ;
90
107
91
- /**
92
- * reset the working tree to recover package names with -exp in the package.json files,
93
- * then bump patch version of firebase-exp (the umbrella package) only
94
- */
95
- const firebaseExpVersion = new Map < string , string > ( ) ;
96
- firebaseExpVersion . set (
97
- FIREBASE_UMBRELLA_PACKAGE_NAME ,
98
- versions . get ( FIREBASE_UMBRELLA_PACKAGE_NAME )
99
- ) ;
100
- const firebaseExpPath = packagePaths . filter ( p =>
101
- p . includes ( FIREBASE_UMBRELLA_PACKAGE_NAME )
102
- ) ;
108
+ /**
109
+ * reset the working tree to recover package names with -exp in the package.json files,
110
+ * then bump patch version of firebase-exp (the umbrella package) only
111
+ */
112
+ const firebaseExpVersion = new Map < string , string > ( ) ;
113
+ firebaseExpVersion . set (
114
+ FIREBASE_UMBRELLA_PACKAGE_NAME ,
115
+ versions . get ( FIREBASE_UMBRELLA_PACKAGE_NAME )
116
+ ) ;
117
+ const firebaseExpPath = packagePaths . filter ( p =>
118
+ p . includes ( FIREBASE_UMBRELLA_PACKAGE_NAME )
119
+ ) ;
120
+
121
+ const { resetWorkingTree } = await prompt ( [
122
+ {
123
+ type : 'confirm' ,
124
+ name : 'resetWorkingTree' ,
125
+ message : 'Do you want to reset the working tree?' ,
126
+ default : true
127
+ }
128
+ ] ) ;
129
+
130
+ if ( resetWorkingTree ) {
103
131
await resetWorkingTreeAndBumpVersions (
104
132
firebaseExpPath ,
105
133
firebaseExpVersion
106
134
) ;
135
+ } else {
136
+ process . exit ( 0 ) ;
137
+ }
107
138
139
+ /**
140
+ * Do not push to remote if it's a dryrun
141
+ */
142
+ if ( ! dryRun ) {
143
+ const { commitAndPush } = await prompt ( [
144
+ {
145
+ type : 'confirm' ,
146
+ name : 'commitAndPush' ,
147
+ message :
148
+ 'Do you want to commit and push the exp version update to remote?' ,
149
+ default : true
150
+ }
151
+ ] ) ;
108
152
/**
109
153
* push to github
110
154
*/
111
- await commitAndPush ( versions ) ;
155
+ if ( commitAndPush ) {
156
+ await commitAndPush ( versions ) ;
157
+ }
112
158
}
113
159
} catch ( err ) {
114
160
/**
@@ -199,6 +245,16 @@ async function buildPackages() {
199
245
}
200
246
) ;
201
247
248
+ // remove packages/installations/dist, otherwise packages that depend on packages-exp/installations-exp (e.g. Perf, FCM)
249
+ // will incorrectly reference packages/installations.
250
+ const installationsDistDirPath = resolve (
251
+ projectRoot ,
252
+ 'packages/installations/dist'
253
+ ) ;
254
+ if ( existsSync ( installationsDistDirPath ) ) {
255
+ rmdirSync ( installationsDistDirPath , { recursive : true } ) ;
256
+ }
257
+
202
258
// Build firebase-exp
203
259
await spawn (
204
260
'yarn' ,
@@ -242,13 +298,13 @@ async function updatePackageNamesAndVersions(packagePaths: string[]) {
242
298
return versions ;
243
299
}
244
300
245
- async function publishToNpm ( packagePaths : string [ ] ) {
301
+ async function publishToNpm ( packagePaths : string [ ] , dryRun = false ) {
246
302
const taskArray = await Promise . all (
247
303
packagePaths . map ( async pp => {
248
304
const { version, name } = await readPackageJson ( pp ) ;
249
305
return {
250
306
title : `📦 ${ name } @${ version } ` ,
251
- task : ( ) => publishPackage ( pp )
307
+ task : ( ) => publishPackage ( pp , dryRun )
252
308
} ;
253
309
} )
254
310
) ;
@@ -262,8 +318,11 @@ async function publishToNpm(packagePaths: string[]) {
262
318
return tasks . run ( ) ;
263
319
}
264
320
265
- async function publishPackage ( packagePath : string ) {
321
+ async function publishPackage ( packagePath : string , dryRun : boolean ) {
266
322
const args = [ 'publish' , '--access' , 'public' , '--tag' , 'exp' ] ;
323
+ if ( dryRun ) {
324
+ args . push ( '--dry-run' ) ;
325
+ }
267
326
await spawn ( 'npm' , args , { cwd : packagePath } ) ;
268
327
}
269
328
0 commit comments