generator-zionapps
Version:
Angular 9 Code Generator
47 lines (42 loc) • 1.41 kB
JavaScript
;
const Generator = require('yeoman-generator');
const { paramCase, stringUtils } = require('@zionapps/core');
module.exports = class extends Generator {
// Note: arguments and options should be defined in the constructor.
constructor(args, opts) {
super(args, opts);
this.props = opts.componentProps;
}
prompting() {
// Check if a component was just generated for this module. If so, there is no need to ask anymore questions.
if (this.props) {
this.destinationRoot(`${this.props.path}/${paramCase(this.props.componentName)}`);
} else {
const prompts = [
{
type: 'input',
name: 'path',
message: 'What is the path to the folder of your components?',
default: 'app/src/pages',
store: true
},
{
type: 'input',
name: 'componentName',
message: 'What is the name of your routing component?'
}
];
return this.prompt(prompts).then(props => {
this.props = props;
this.destinationRoot(`${props.path}/${paramCase(props.componentName)}`);
});
}
}
writing() {
this.fs.copyTpl(
this.templatePath('component.module.ts'),
this.destinationPath(`${paramCase(this.props.componentName)}.module.ts`),
{ ...stringUtils, ...this.props }
);
}
};