Skip to content

Commit

Permalink
feat: question support other type from inquirer (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
popomore authored and atian25 committed Apr 17, 2019
1 parent c9dbae2 commit 36f2d86
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/init_command.js
Expand Up @@ -247,11 +247,12 @@ module.exports = class Command {
return yield inquirer.prompt(keys.map(key => {
const question = questions[key];
return {
type: 'input',
type: question.type || 'input',
name: key,
message: question.description || question.desc,
default: question.default,
filter: question.filter,
choices: question.choices,
};
}));
}
Expand Down
2 changes: 1 addition & 1 deletion test/category.test.js
Expand Up @@ -44,7 +44,7 @@ describe('test/category.test', () => {
});

it('should work with prompt', function* () {
helper.mock([[ 'simple-app', 'this is xxx', 'TZ', helper.KEY_ENTER, 'test' ]]);
helper.mock([[ 'simple-app', 'this is xxx', 'TZ', helper.KEY_ENTER, 'test', helper.KEY_ENTER ]]);
const boilerplatePath = path.join(__dirname, 'fixtures/simple-test');
yield command.run(tmp, [ 'simple-app', '--force', '--template=' + boilerplatePath ]);

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/simple-test/boilerplate/README.md
Expand Up @@ -6,6 +6,8 @@

{{filterFn}}

{{list}}

## QuickStart

### Development
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/simple-test/index.js
Expand Up @@ -23,4 +23,9 @@ module.exports = {
return 'filter-' + v;
},
},
list: {
type: 'list',
desc: 'choose',
choices: [ 'listA', 'listB' ],
},
};
3 changes: 2 additions & 1 deletion test/init.test.js
Expand Up @@ -42,7 +42,7 @@ describe('test/init.test.js', () => {
});

it('should work with prompt', function* () {
helper.mock([[ 'simple-app', 'this is xxx', 'TZ', helper.KEY_ENTER, 'test' ]]);
helper.mock([[ 'simple-app', 'this is xxx', 'TZ', helper.KEY_ENTER, 'test', helper.KEY_ENTER ]]);
const boilerplatePath = path.join(__dirname, 'fixtures/simple-test');
yield command.run(tmp, [ 'simple-app', '--force', '--template=' + boilerplatePath ]);

Expand All @@ -55,6 +55,7 @@ describe('test/init.test.js', () => {
const content = fs.readFileSync(path.join(command.targetDir, 'README.md'), 'utf-8');
assert(/default-simple-app/.test(content));
assert(/filter-test/.test(content));
assert(/listA/.test(content));
});

it('should prompt', function* () {
Expand Down

0 comments on commit 36f2d86

Please sign in to comment.