Skip to content

Commit

Permalink
[#121] Refactor usage of then callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
bterone committed Oct 23, 2023
1 parent ebbea7e commit 9f8df06
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions packages/cli-tool/src/template/fetchingStrategy/copyStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ class CopyStrategy implements FetchStrategy {
}

async fetchTemplateFiles(options: InitTemplateOptions): Promise<void> {
return this.copyTemplateFiles(options)
.then(() => this.renameFolder(options));
await this.copyTemplateFiles(options);
return this.renameFolder(options);
}

private async copyTemplateFiles(options: InitTemplateOptions): Promise<void> {
CliUx.ux.info('Copying template source files...');
private copyTemplateFiles(options: InitTemplateOptions): Promise<void> {
CliUx.ux.info(`Copying ${this.selectedTemplate} source files...`);

return runCommand(
'cp',
['-r', `../${this.selectedTemplate}`, options.dest],
);
}

private async renameFolder(options: InitTemplateOptions): Promise<void> {
private renameFolder(options: InitTemplateOptions): Promise<void> {
CliUx.ux.info('Rename your app folder...');

return runCommand(
Expand Down
26 changes: 13 additions & 13 deletions packages/cli-tool/src/template/fetchingStrategy/downloadStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class DownloadStrategy implements FetchStrategy {
}

async fetchTemplateFiles(options: InitTemplateOptions): Promise<void> {
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(
Expand Down Expand Up @@ -57,19 +57,19 @@ class DownloadStrategy implements FetchStrategy {
);
}

private cleanTemporaryFiles(options: InitTemplateOptions): Promise<void> {
private async cleanTemporaryFiles(options: InitTemplateOptions): Promise<void> {
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,
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/cli-tool/src/template/initialize-vite-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ const npmInstall = (options: InitTemplateOptions): Promise<void> => {
};

const initializeViteApp = async(options: InitTemplateOptions): Promise<void> => {
return fetchTemplateFiles(options)
.then(() => replaceAppName(options))
.then(() => npmInstall(options));
await fetchTemplateFiles(options);
await replaceAppName(options);
return npmInstall(options);
};

export default initializeViteApp;

0 comments on commit 9f8df06

Please sign in to comment.