@@ -55,11 +55,16 @@ export class Generator {
55
55
async run ( ) {
56
56
this . _printPrologue ( ) ;
57
57
const answers = await this . _askQuestions ( ) ;
58
- const { files, commands } = await this . _identifyChanges ( answers ) ;
59
- executeCommands ( this . rootDir , commands ) ;
58
+ const { files, commands : allCommands } = await this . _identifyChanges ( answers ) ;
59
+ const [ preCommands , postCommands ] = allCommands . reduce ( ( acc , command ) => {
60
+ acc [ command . phase === 'pre' ? 0 : 1 ] . push ( command ) ;
61
+ return acc ;
62
+ } , [ [ ] as Command [ ] , [ ] as Command [ ] ] ) ;
63
+ executeCommands ( this . rootDir , preCommands ) ;
60
64
await createFiles ( this . rootDir , files ) ;
61
65
this . _patchGitIgnore ( ) ;
62
66
await this . _patchPackageJSON ( answers ) ;
67
+ executeCommands ( this . rootDir , postCommands ) ;
63
68
if ( answers . framework )
64
69
this . _printEpilogueCT ( ) ;
65
70
else
@@ -144,7 +149,7 @@ export class Generator {
144
149
}
145
150
146
151
private async _identifyChanges ( answers : PromptOptions ) {
147
- const commands : Command [ ] = [ ] ;
152
+ const commands : ( Command & { phase : 'pre' | 'post' } ) [ ] = [ ] ;
148
153
const files = new Map < string , string > ( ) ;
149
154
const fileExtension = languageToFileExtension ( answers . language ) ;
150
155
@@ -185,6 +190,7 @@ export class Generator {
185
190
commands . push ( {
186
191
name : `Initializing ${ this . packageManager . name } project` ,
187
192
command : this . packageManager . init ( ) ,
193
+ phase : 'pre' ,
188
194
} ) ;
189
195
}
190
196
@@ -198,13 +204,15 @@ export class Generator {
198
204
commands . push ( {
199
205
name : 'Installing Playwright Test' ,
200
206
command : this . packageManager . installDevDependency ( `@playwright/test${ packageTag } ` ) ,
207
+ phase : 'pre' ,
201
208
} ) ;
202
209
}
203
210
204
211
if ( this . options . ct ) {
205
212
commands . push ( {
206
213
name : 'Installing Playwright Component Testing' ,
207
214
command : this . packageManager . installDevDependency ( `${ ctPackageName } ${ packageTag } ` ) ,
215
+ phase : 'pre' ,
208
216
} ) ;
209
217
210
218
const extension = getFileExtensionCT ( answers . language , answers . framework ) ;
@@ -219,6 +227,7 @@ export class Generator {
219
227
commands . push ( {
220
228
name : 'Installing Types' ,
221
229
command : this . packageManager . installDevDependency ( `@types/node` ) ,
230
+ phase : 'pre' ,
222
231
} ) ;
223
232
}
224
233
@@ -227,6 +236,7 @@ export class Generator {
227
236
commands . push ( {
228
237
name : 'Downloading browsers' ,
229
238
command : this . packageManager . npx ( 'playwright' , 'install' ) + ( answers . installPlaywrightDependencies ? ' --with-deps' : '' ) + browsersSuffix ,
239
+ phase : 'post' ,
230
240
} ) ;
231
241
}
232
242
0 commit comments