diff --git a/commands/init/lib/index.js b/commands/init/lib/index.js index b67bf0c..78db3e7 100644 --- a/commands/init/lib/index.js +++ b/commands/init/lib/index.js @@ -35,7 +35,7 @@ class InitCommand extends Command { } downloadTemplate() { - console.log(this.projectInfo, templates); + console.log(this.projectInfo); } async prepare() { @@ -70,6 +70,13 @@ class InitCommand extends Command { return this.getProjectInfo(); } + createTemplateChoice() { + return templates.map(item => ({ + value: item.npmName, + name: item.name + })); + } + async getProjectInfo() { let projectInfo = {}; const { type } = await inquirer.prompt({ @@ -92,7 +99,6 @@ class InitCommand extends Command { type: 'input', name: 'projectName', message: 'Please enter the project name', - default: '', validate: function(v) { const done = this.async(); setTimeout(function () { @@ -128,6 +134,11 @@ class InitCommand extends Command { return v; } } + }, { + type: 'list', + name: 'projectTemplate', + message: 'Please select a project template', + choices: this.createTemplateChoice() }]); projectInfo = { type, diff --git a/commands/init/lib/templates.js b/commands/init/lib/templates.js index 93fa224..a96b739 100644 --- a/commands/init/lib/templates.js +++ b/commands/init/lib/templates.js @@ -1,7 +1,7 @@ module.exports = [ { id: 1, - name: 'normal', + name: 'Normal', npmName: 'dapp-cli-template-normal', version: '1.0.0', disabled: false