From f0bb437699003e64a1b2c3a6bb9538a7fc4d7b88 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Tue, 5 Mar 2024 18:28:19 +0100 Subject: [PATCH] chore: split commands by pre/post file creation --- src/generator.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/generator.ts b/src/generator.ts index 34d24c1..02fe449 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -55,11 +55,16 @@ export class Generator { async run() { this._printPrologue(); const answers = await this._askQuestions(); - const { files, commands } = await this._identifyChanges(answers); - executeCommands(this.rootDir, commands); + const { files, commands: allCommands } = await this._identifyChanges(answers); + const [preCommands, postCommands] = allCommands.reduce((acc, command) => { + acc[command.phase === 'pre' ? 0 : 1].push(command); + return acc; + }, [[] as Command[], [] as Command[]]); + executeCommands(this.rootDir, preCommands); await createFiles(this.rootDir, files); this._patchGitIgnore(); await this._patchPackageJSON(answers); + executeCommands(this.rootDir, postCommands); if (answers.framework) this._printEpilogueCT(); else @@ -144,7 +149,7 @@ export class Generator { } private async _identifyChanges(answers: PromptOptions) { - const commands: Command[] = []; + const commands: (Command & { phase: 'pre' | 'post' })[] = []; const files = new Map(); const fileExtension = languageToFileExtension(answers.language); @@ -185,6 +190,7 @@ export class Generator { commands.push({ name: `Initializing ${this.packageManager.name} project`, command: this.packageManager.init(), + phase: 'pre', }); } @@ -198,6 +204,7 @@ export class Generator { commands.push({ name: 'Installing Playwright Test', command: this.packageManager.installDevDependency(`@playwright/test${packageTag}`), + phase: 'pre', }); } @@ -205,6 +212,7 @@ export class Generator { commands.push({ name: 'Installing Playwright Component Testing', command: this.packageManager.installDevDependency(`${ctPackageName}${packageTag}`), + phase: 'pre', }); const extension = getFileExtensionCT(answers.language, answers.framework); @@ -219,6 +227,7 @@ export class Generator { commands.push({ name: 'Installing Types', command: this.packageManager.installDevDependency(`@types/node`), + phase: 'pre', }); } @@ -227,6 +236,7 @@ export class Generator { commands.push({ name: 'Downloading browsers', command: this.packageManager.npx('playwright', 'install') + (answers.installPlaywrightDependencies ? ' --with-deps' : '') + browsersSuffix, + phase: 'post', }); }