Last active
March 23, 2016 23:45
-
-
Save nicoespeon/6ddb9334b68e155cf916 to your computer and use it in GitHub Desktop.
Blog - Plop — a micro-generator to ease your daily life - adapt actions to answers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = ( plop ) => { | |
plop.setGenerator( "module", { | |
prompts: [ | |
{ | |
type: "input", | |
name: "name", | |
message: "What is the name of your module?", | |
validate: isNotEmptyFor( "name" ), | |
filter: ensurePlural | |
}, | |
{ | |
type: "list", | |
name: "dataConfig", | |
message: "Tell me about the data, what do you need?", | |
default: "none", | |
choices: [ | |
{ name: "Nothing", value: "none" }, | |
{ name: "A Model", value: "model" } | |
] | |
} | |
], | |
actions: ( data ) => { | |
// Add a new module, whatever happens. | |
let actions = [ | |
{ | |
type: "add", | |
path: "app/modules/{{camelCase name}}/{{camelCase name}}.js", | |
templateFile: "plop-templates/module.js" | |
}, | |
{ | |
type: "add", | |
path: "app/modules/{{camelCase name}}/tests/{{camelCase name}}.tests.js", | |
templateFile: "plop-templates/module.tests.js" | |
} | |
]; | |
// If you wish a Model, then we add a Model. | |
if ( data.dataConfig === "model" ) { | |
actions = actions.concat( [ | |
{ | |
type: "add", | |
path: "app/modules/{{camelCase name}}.model.js", | |
templateFile: "plop-templates/model.js" | |
}, | |
{ | |
type: "add", | |
path: "app/tests/{{camelCase name}}.model.tests.js", | |
templateFile: "plop-templates/model.tests.js" | |
}, | |
] ); | |
} | |
// Return the array of actions to take. | |
return actions; | |
} | |
} ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment