Skip to content

Commit fffc56b

Browse files
authored
chore: split commands by pre/post file creation (#115)
1 parent 18fd656 commit fffc56b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/generator.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,16 @@ export class Generator {
5555
async run() {
5656
this._printPrologue();
5757
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);
6064
await createFiles(this.rootDir, files);
6165
this._patchGitIgnore();
6266
await this._patchPackageJSON(answers);
67+
executeCommands(this.rootDir, postCommands);
6368
if (answers.framework)
6469
this._printEpilogueCT();
6570
else
@@ -144,7 +149,7 @@ export class Generator {
144149
}
145150

146151
private async _identifyChanges(answers: PromptOptions) {
147-
const commands: Command[] = [];
152+
const commands: (Command & { phase: 'pre' | 'post' })[] = [];
148153
const files = new Map<string, string>();
149154
const fileExtension = languageToFileExtension(answers.language);
150155

@@ -185,6 +190,7 @@ export class Generator {
185190
commands.push({
186191
name: `Initializing ${this.packageManager.name} project`,
187192
command: this.packageManager.init(),
193+
phase: 'pre',
188194
});
189195
}
190196

@@ -198,13 +204,15 @@ export class Generator {
198204
commands.push({
199205
name: 'Installing Playwright Test',
200206
command: this.packageManager.installDevDependency(`@playwright/test${packageTag}`),
207+
phase: 'pre',
201208
});
202209
}
203210

204211
if (this.options.ct) {
205212
commands.push({
206213
name: 'Installing Playwright Component Testing',
207214
command: this.packageManager.installDevDependency(`${ctPackageName}${packageTag}`),
215+
phase: 'pre',
208216
});
209217

210218
const extension = getFileExtensionCT(answers.language, answers.framework);
@@ -219,6 +227,7 @@ export class Generator {
219227
commands.push({
220228
name: 'Installing Types',
221229
command: this.packageManager.installDevDependency(`@types/node`),
230+
phase: 'pre',
222231
});
223232
}
224233

@@ -227,6 +236,7 @@ export class Generator {
227236
commands.push({
228237
name: 'Downloading browsers',
229238
command: this.packageManager.npx('playwright', 'install') + (answers.installPlaywrightDependencies ? ' --with-deps' : '') + browsersSuffix,
239+
phase: 'post',
230240
});
231241
}
232242

0 commit comments

Comments
 (0)