Last active
March 23, 2016 23:47
-
-
Save nicoespeon/fcfff37708cec18d66a6 to your computer and use it in GitHub Desktop.
Blog - Plop — a micro-generator to ease your daily life - concrete example
This file contains 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
const modulePath = "app/modules/{{camelCase name}}.js"; | |
module.exports = ( plop ) => { | |
plop.setGenerator( "model", { | |
// … | |
actions: [ | |
// Add a new model + tests boilerplate. | |
{ | |
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" | |
}, | |
// Modify the module file to inject created model. | |
// This is basically RegExp replacement. | |
{ | |
type: "modify", | |
path: modulePath, | |
pattern: /(\/\/ IMPORT MODULE FILES)/g, | |
template: "$1\nimport Model from \"./{{camelCase name}}.model\";" | |
}, | |
{ | |
type: "modify", | |
path: modulePath, | |
pattern: /(const namespace = "\w+";)/g, | |
template: "$1\n\nModel = Model.extend( { namespace: namespace } );" | |
} | |
] | |
} ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment