From 9f8df06823d65a3a35a3c0206a745da96169353b Mon Sep 17 00:00:00 2001 From: Terone Date: Mon, 23 Oct 2023 09:20:52 +0700 Subject: [PATCH] [#121] Refactor usage of then callbacks --- .../template/fetchingStrategy/copyStrategy.ts | 10 +++---- .../fetchingStrategy/downloadStrategy.ts | 26 +++++++++---------- .../src/template/initialize-vite-app.ts | 6 ++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/cli-tool/src/template/fetchingStrategy/copyStrategy.ts b/packages/cli-tool/src/template/fetchingStrategy/copyStrategy.ts index bc9630a..7635641 100644 --- a/packages/cli-tool/src/template/fetchingStrategy/copyStrategy.ts +++ b/packages/cli-tool/src/template/fetchingStrategy/copyStrategy.ts @@ -10,12 +10,12 @@ class CopyStrategy implements FetchStrategy { } async fetchTemplateFiles(options: InitTemplateOptions): Promise { - return this.copyTemplateFiles(options) - .then(() => this.renameFolder(options)); + await this.copyTemplateFiles(options); + return this.renameFolder(options); } - private async copyTemplateFiles(options: InitTemplateOptions): Promise { - CliUx.ux.info('Copying template source files...'); + private copyTemplateFiles(options: InitTemplateOptions): Promise { + CliUx.ux.info(`Copying ${this.selectedTemplate} source files...`); return runCommand( 'cp', @@ -23,7 +23,7 @@ class CopyStrategy implements FetchStrategy { ); } - private async renameFolder(options: InitTemplateOptions): Promise { + private renameFolder(options: InitTemplateOptions): Promise { CliUx.ux.info('Rename your app folder...'); return runCommand( diff --git a/packages/cli-tool/src/template/fetchingStrategy/downloadStrategy.ts b/packages/cli-tool/src/template/fetchingStrategy/downloadStrategy.ts index 8b0b3b4..bf0fe88 100644 --- a/packages/cli-tool/src/template/fetchingStrategy/downloadStrategy.ts +++ b/packages/cli-tool/src/template/fetchingStrategy/downloadStrategy.ts @@ -14,10 +14,10 @@ class DownloadStrategy implements FetchStrategy { } async fetchTemplateFiles(options: InitTemplateOptions): Promise { - return this.downloadTemplateRepository(options) - .then(() => this.extractDownloadedTemplateFolder(options)) - .then(() => this.renameFolder(options)) - .then(() => this.cleanTemporaryFiles(options)); + await this.downloadTemplateRepository(options); + await this.extractDownloadedTemplateFolder(options); + await this.renameFolder(options); + return this.cleanTemporaryFiles(options); } private downloadTemplateRepository( @@ -57,19 +57,19 @@ class DownloadStrategy implements FetchStrategy { ); } - private cleanTemporaryFiles(options: InitTemplateOptions): Promise { + private async cleanTemporaryFiles(options: InitTemplateOptions): Promise { CliUx.ux.info('Remove zip and unwanted files...'); const branchPath = options.templateReference.replace('/', '-'); // Remove the archive - return runCommand('rm', [`${options.appName}.gz`], options.dest).then(() => { - // Remove the extracted folder - return runCommand( - 'rm', - ['-rf', `${TEMPLATE_REPO}-${branchPath}`], - options.dest, - ); - }); + await runCommand('rm', [`${options.appName}.gz`], options.dest); + + // Remove the extracted folder + return runCommand( + 'rm', + ['-rf', `${TEMPLATE_REPO}-${branchPath}`], + options.dest, + ); } } diff --git a/packages/cli-tool/src/template/initialize-vite-app.ts b/packages/cli-tool/src/template/initialize-vite-app.ts index d74364c..c044723 100644 --- a/packages/cli-tool/src/template/initialize-vite-app.ts +++ b/packages/cli-tool/src/template/initialize-vite-app.ts @@ -47,9 +47,9 @@ const npmInstall = (options: InitTemplateOptions): Promise => { }; const initializeViteApp = async(options: InitTemplateOptions): Promise => { - return fetchTemplateFiles(options) - .then(() => replaceAppName(options)) - .then(() => npmInstall(options)); + await fetchTemplateFiles(options); + await replaceAppName(options); + return npmInstall(options); }; export default initializeViteApp;