From 2abace0cc6303d351a05c3ec39049aa9a3c86847 Mon Sep 17 00:00:00 2001 From: Shawn Allen Date: Mon, 11 Sep 2017 15:23:49 -0700 Subject: [PATCH] tidy up category logic --- modules/generator-primer-module/app/index.js | 12 ++++++++---- modules/generator-primer-module/app/options.js | 7 ++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/modules/generator-primer-module/app/index.js b/modules/generator-primer-module/app/index.js index 9fdeba44..1e85351e 100644 --- a/modules/generator-primer-module/app/index.js +++ b/modules/generator-primer-module/app/index.js @@ -45,8 +45,9 @@ module.exports = class PrimerModule extends Generator { // have options set, then add back the "name" key to each const prompts = Object.entries(OPTIONS) .filter(([name, {prompt}]) => { - return prompt && - (prompt.when === true || !(name in this.options)) + return prompt && ( + prompt.when === true || typeof this.options[name] === "undefined" + ) }) .map(([name, {prompt}]) => { // bind functions to the generator as `this` @@ -123,10 +124,13 @@ module.exports = class PrimerModule extends Generator { ) // this.log("package:", pkg.name, "@", pkg.version) - if (Array.isArray(this.options.dependents)) { - this.options.dependents.forEach(dependent => { + const dependents = this.options.dependents + if (Array.isArray(dependents)) { + dependents.forEach(dependent => { this._addAsDependencyTo(pkg, dependent) }) + } else { + this.log(chalk.red("No dependents!"), dependents) } } diff --git a/modules/generator-primer-module/app/options.js b/modules/generator-primer-module/app/options.js index 8c6e2574..fbe6768f 100644 --- a/modules/generator-primer-module/app/options.js +++ b/modules/generator-primer-module/app/options.js @@ -101,7 +101,7 @@ module.exports = { "category": { option: {type: String}, prompt: { - message: "Which meta-package does this belong to?", + message: "What category of package is this?", type: "list", choices: [ "core", @@ -120,7 +120,7 @@ module.exports = { alias: "m", }, prompt: { - message: "What type of module is this?", + message: "What type/kind of module is this?", type: "list", choices: MODULE_TYPES, default: 0 @@ -142,8 +142,9 @@ module.exports = { return this.options.dependents !== false }, choices: META_PACKAGES, - default: ({category}) => { + default: function({category}) { const pkgs = ["primer-css"] + category = category || this.options.category return (category === "meta") ? pkgs : pkgs.concat(`primer-${category}`)