scaffander
Code generator with support for structure templates
Example template for scaffander-cli can be found here: https://github.com/ikatun/scaffander-example
Example of a code generator (from examples/ directory)
.
├── index.js
├── templates
| └── test-template
| ├── template-init.js
| └── {{directoryName}}
| └── {{myFileName}}.js
{{myFileName}}.js
export class {{className}} {
constructor() {
console.log('Thank you very much for constructing me!');
}
}
export default {{className}};
template-init.js
// don't worry, this file will not be part of the generated code :) // called before template is parsed// variables added to context here can be used within the templateexports { contextdirectoryName = 'MyTestDirectory';}; // called after template is parsed// postRunActions can be added to the postRunActions array// these are executed after user accepts the new diffexports { contextpostRunActions; //you can also call scaffander() function here if you want to generate a template within another template };
index.js
const path = ;const scaffander = default;// or better yet: import scaffander from 'scaffander'; const argv = processargv;if argvlength !== 4 console; process;const templateName = argv2;const destinationPath = argv3; const context = myFileName: 'index' className: 'MyBeautifulClass' ;const templatePath = path;;
running the example (from the examples/scaffander-test directory)
npm install
node index.js test-template generated-template
# generated-template directory is created