Skip to content

Instantly share code, notes, and snippets.

@nicoespeon
Last active March 23, 2016 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicoespeon/6ddb9334b68e155cf916 to your computer and use it in GitHub Desktop.
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
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