1
1
mirror of https://github.com/primer/css.git synced 2024-11-29 14:14:26 +03:00

tidy up category logic

This commit is contained in:
Shawn Allen 2017-09-11 15:23:49 -07:00
parent be9185e1d4
commit 2abace0cc6
2 changed files with 12 additions and 7 deletions

View File

@ -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)
}
}

View File

@ -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}`)