From fff9b244c8b3e44c6d659d1558551465d996aeb6 Mon Sep 17 00:00:00 2001 From: MrBear Date: Thu, 27 Feb 2020 14:39:03 +0800 Subject: [PATCH 1/2] feat(init): support initialize project with selected generator --- packages/feflow-cli/src/core/native/generator.ts | 14 +++++++++++++- packages/feflow-cli/types/index.d.ts | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/feflow-cli/src/core/native/generator.ts b/packages/feflow-cli/src/core/native/generator.ts index 5879c925..ce9fc6aa 100644 --- a/packages/feflow-cli/src/core/native/generator.ts +++ b/packages/feflow-cli/src/core/native/generator.ts @@ -51,11 +51,23 @@ const run = (ctx: any, name: string) => { module.exports = (ctx: any) => { ctx.commander.register('init', 'Create a new project', () => { - const { root, rootPkg } = ctx; + const { root, rootPkg, args } = ctx; + const { g, generator } = args; + const chooseGenerator = g || generator; + let chooseGeneratorIsValid = false; + loadGenerator(root, rootPkg).then((generators: any) => { const options = generators.map((item: any) => { + if (item.name === chooseGenerator) { + chooseGeneratorIsValid = true + } return item.desc }); + + if(chooseGeneratorIsValid) { + return run(ctx, chooseGenerator); + } + if (generators.length) { inquirer.prompt([{ type: 'list', diff --git a/packages/feflow-cli/types/index.d.ts b/packages/feflow-cli/types/index.d.ts index 9b7b05b5..fc8cf9ee 100644 --- a/packages/feflow-cli/types/index.d.ts +++ b/packages/feflow-cli/types/index.d.ts @@ -1 +1,2 @@ -declare module '@feflow/report'; \ No newline at end of file +declare module '@feflow/report'; +declare module "request-promise" \ No newline at end of file From 1d91a3201949f660f22d34810a6f6e0d11335c74 Mon Sep 17 00:00:00 2001 From: MrBear Date: Fri, 28 Feb 2020 10:17:17 +0800 Subject: [PATCH 2/2] feat(init): remove -g param --- packages/feflow-cli/src/core/native/generator.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/feflow-cli/src/core/native/generator.ts b/packages/feflow-cli/src/core/native/generator.ts index ce9fc6aa..1f60a209 100644 --- a/packages/feflow-cli/src/core/native/generator.ts +++ b/packages/feflow-cli/src/core/native/generator.ts @@ -52,19 +52,19 @@ const run = (ctx: any, name: string) => { module.exports = (ctx: any) => { ctx.commander.register('init', 'Create a new project', () => { const { root, rootPkg, args } = ctx; - const { g, generator } = args; - const chooseGenerator = g || generator; - let chooseGeneratorIsValid = false; + const { generator } = args; + const chooseGenerator = generator; + let isValidGenerator = false; loadGenerator(root, rootPkg).then((generators: any) => { const options = generators.map((item: any) => { if (item.name === chooseGenerator) { - chooseGeneratorIsValid = true + isValidGenerator = true } return item.desc }); - if(chooseGeneratorIsValid) { + if(isValidGenerator) { return run(ctx, chooseGenerator); }