Skip to content

Commit

Permalink
feat(cli-options): add --noDefaults option
Browse files Browse the repository at this point in the history
Using --noDefaults option will set all the default Boolean options to false
sharvit committed Aug 2, 2019
1 parent 10106df commit 8ce294c
Showing 4 changed files with 76 additions and 7 deletions.
52 changes: 51 additions & 1 deletion src/app/index.test.js
Original file line number Diff line number Diff line change
@@ -33,7 +33,6 @@ test('default files', () => {
assert.file([
'.git',
'.babelrc',
'.commitlintrc.json',
'.editorconfig',
'.eslintignore',
'.eslintrc',
@@ -54,9 +53,49 @@ test('default files', () => {
'other/roadmap.md',
// travisCI
'.travis.yml',
// semanticRelease
'.commitlintrc.json',
]);

assert.noFile([
'_babelrc',
'_editorconfig',
'_eslintignore',
'_eslintrc',
'_gitattributes',
'_gitignore',
'_travis.yml',
'_npmignore',
'_github/issue_template.md',
'_github/pull_request_template.md',
'_commitlintrc.json',
]);
});
});

test('default files with --noDefaults', () => {
return runAppGenerator()
.withOptions({ noDefaults: true })
.withPrompts(requiredPrompts)
.then(() => {
assert.file([
'.git',
'.babelrc',
'.editorconfig',
'.eslintignore',
'.eslintrc',
'.gitattributes',
'.gitignore',
'.npmignore',
'license',
'package.json',
'readme.md',
'src/index.js',
'src/index.test.js',
]);

assert.noFile([
'.commitlintrc.json',
'_babelrc',
'_editorconfig',
'_eslintignore',
@@ -68,6 +107,17 @@ test('default files', () => {
'_github/issue_template.md',
'_github/pull_request_template.md',
'_commitlintrc.json',
// githubTemplates
'contributing.md',
'.github/issue_template.md',
'.github/pull_request_template.md',
'other/code_of_conduct.md',
'other/examples.md',
'other/roadmap.md',
// travisCI
'.travis.yml',
// semanticRelease
'.commitlintrc.json',
]);
});
});
4 changes: 4 additions & 0 deletions src/app/options.js
Original file line number Diff line number Diff line change
@@ -45,6 +45,10 @@ const options = {
desc:
'Your github-token, needed when using with --createGithubRepository or --semanticRelease (https://github.com/sharvit/generator-node-mdl#about-passwords-and-tokens)',
},
noDefaults: {
type: Boolean,
desc: 'Set all the default Boolean optins to false',
},
};

export default options;
25 changes: 19 additions & 6 deletions src/app/prompter.js
Original file line number Diff line number Diff line change
@@ -25,7 +25,9 @@ export default class Prompter {
await this._promptGeneral();
await this._promptGithub();
await this._promptTravis();
await this._promptCoveralls();
await this._promptNpm();
await this._promptSemanticRelease();
await this._promptPasswords();

return this.props;
@@ -78,7 +80,9 @@ export default class Prompter {
]);

this._updatePropsWithAnswers({ travisCI });
}

async _promptCoveralls() {
const { coveralls } = await this.generator.prompt([
this._buildPrompt('coveralls', prompts.coveralls),
]);
@@ -87,13 +91,21 @@ export default class Prompter {
}

async _promptNpm() {
const { npmDeploy, semanticRelease } = await this.generator.prompt([
const { npmDeploy } = await this.generator.prompt([
this._buildPrompt('npmDeploy', prompts.npmDeploy),
this._buildPrompt('semanticRelease', prompts.semanticRelease),
]);

this._updatePropsWithAnswers({
npmDeploy: npmDeploy || false,
});
}

async _promptSemanticRelease() {
const { semanticRelease } = await this.generator.prompt([
this._buildPrompt('semanticRelease', prompts.semanticRelease),
]);

this._updatePropsWithAnswers({
semanticRelease: semanticRelease || false,
});
}
@@ -279,20 +291,21 @@ export default class Prompter {
_buildPrompt(name, prompt) {
const result = { name, message: prompt.desc };

if (prompt.default) result.default = prompt.default;
if (prompt.store) result.store = prompt.store;
if (prompt.filter) result.filter = prompt.filter;

switch (prompt.type) {
case Boolean:
result.type = 'confirm';
result.default = this.props.noDefaults ? false : result.default;
break;
case String:
default:
result.type = 'input';
break;
}

if (prompt.default) result.default = prompt.default;
if (prompt.store) result.store = prompt.store;
if (prompt.filter) result.filter = prompt.filter;

result.when = () => {
if (this.props[name] !== undefined) return false;

2 changes: 2 additions & 0 deletions src/app/prompts.js
Original file line number Diff line number Diff line change
@@ -58,12 +58,14 @@ const prompts = {
...options.npmDeploy,
required: true,
store: true,
dependOn: ['travisCI'],
help: () => '\nNeed to have an npm account: https://www.npmjs.com/',
},
semanticRelease: {
...options.semanticRelease,
required: true,
store: true,
dependOn: ['travisCI', 'npmDeploy'],
help: () =>
'\nLearn more about semantic-release: https://semantic-release.gitbook.io/semantic-release/',
},

0 comments on commit 8ce294c

Please sign in to comment.