Skip to content

Commit

Permalink
fix: await generators
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Jul 27, 2022
1 parent 6c9f53b commit 4470a81
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/commands/dev/generate/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class GenerateCommand extends SfCommand<void> {
public async run(): Promise<void> {
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,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dev/generate/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class GenerateHook extends SfCommand<void> {
public async run(): Promise<void> {
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,
});
Expand Down
3 changes: 1 addition & 2 deletions src/commands/dev/generate/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export default class GenerateLibrary extends SfCommand<void> {

public static flags = {};

// eslint-disable-next-line @typescript-eslint/require-await
public async run(): Promise<void> {
generate('library', { force: true });
await generate('library', { force: true });
}
}
3 changes: 1 addition & 2 deletions src/commands/dev/generate/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export default class GeneratePlugin extends SfCommand<void> {

public static flags = {};

// eslint-disable-next-line @typescript-eslint/require-await
public async run(): Promise<void> {
generate('plugin', { force: true });
await generate('plugin', { force: true });
}
}
12 changes: 7 additions & 5 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown> = {}): void {
export async function generate(type: string, generatorOptions: Record<string, unknown> = {}): Promise<void> {
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<T>(filePath: string): T {
Expand Down

0 comments on commit 4470a81

Please sign in to comment.