From 4470a812c2219adf97f59bb116617d747ac78225 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Wed, 27 Jul 2022 10:33:53 -0600 Subject: [PATCH] fix: await generators --- src/commands/dev/generate/command.ts | 2 +- src/commands/dev/generate/hook.ts | 2 +- src/commands/dev/generate/library.ts | 3 +-- src/commands/dev/generate/plugin.ts | 3 +-- src/util.ts | 12 +++++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/commands/dev/generate/command.ts b/src/commands/dev/generate/command.ts index 7ff0e1a5..e9ad0bb1 100644 --- a/src/commands/dev/generate/command.ts +++ b/src/commands/dev/generate/command.ts @@ -41,7 +41,7 @@ export default class GenerateCommand extends SfCommand { public async run(): Promise { const { flags } = await this.parse(GenerateCommand); if (!fileExists('package.json')) throw messages.createError('errors.InvalidDir'); - generate('command', { + await generate('command', { name: flags.name, force: flags.force, nuts: flags.nuts, diff --git a/src/commands/dev/generate/hook.ts b/src/commands/dev/generate/hook.ts index 961ba416..b7cc2786 100644 --- a/src/commands/dev/generate/hook.ts +++ b/src/commands/dev/generate/hook.ts @@ -33,7 +33,7 @@ export default class GenerateHook extends SfCommand { public async run(): Promise { const { flags } = await this.parse(GenerateHook); if (!fileExists('package.json')) throw messages.createError('errors.InvalidDir'); - generate('hook', { + await generate('hook', { force: flags.force, event: flags.event, }); diff --git a/src/commands/dev/generate/library.ts b/src/commands/dev/generate/library.ts index be75ae4c..89f5023b 100644 --- a/src/commands/dev/generate/library.ts +++ b/src/commands/dev/generate/library.ts @@ -19,8 +19,7 @@ export default class GenerateLibrary extends SfCommand { public static flags = {}; - // eslint-disable-next-line @typescript-eslint/require-await public async run(): Promise { - generate('library', { force: true }); + await generate('library', { force: true }); } } diff --git a/src/commands/dev/generate/plugin.ts b/src/commands/dev/generate/plugin.ts index 3f3ee42e..1524bdae 100644 --- a/src/commands/dev/generate/plugin.ts +++ b/src/commands/dev/generate/plugin.ts @@ -19,8 +19,7 @@ export default class GeneratePlugin extends SfCommand { public static flags = {}; - // eslint-disable-next-line @typescript-eslint/require-await public async run(): Promise { - generate('plugin', { force: true }); + await generate('plugin', { force: true }); } } diff --git a/src/util.ts b/src/util.ts index daa41516..0331ec46 100644 --- a/src/util.ts +++ b/src/util.ts @@ -8,13 +8,15 @@ import * as fs from 'fs'; import { createEnv } from 'yeoman-environment'; import { Hook, PackageJson } from './types'; -/* eslint-disable @typescript-eslint/ban-ts-comment */ - -export function generate(type: string, generatorOptions: Record = {}): void { +export async function generate(type: string, generatorOptions: Record = {}): Promise { const env = createEnv(); env.register(require.resolve(`./generators/${type}`), `sf:${type}`); - // @ts-ignore - env.run(`sf:${type}`, generatorOptions); + return new Promise((resolve, reject) => { + env.run(`sf:${type}`, generatorOptions, (err: Error) => { + if (err) reject(err); + else resolve(); + }); + }); } export function readJson(filePath: string): T {