generator-zionapps
Version:
Angular 9 Code Generator
134 lines (123 loc) • 4.54 kB
JavaScript
'use strict';
const Generator = require('yeoman-generator');
const { paramCase, stringUtils } = require('@zionapps/core');
module.exports = class extends Generator {
// Your initialization methods (checking current project state, getting configs, etc)
initializing() {
this.log('Initializing Angular Detail View');
}
// Where you prompt users for options (where you’d call this.prompt())
prompting() {
const prompts = [
{
type: 'input',
name: 'componentName',
message: 'What is the NAME of your component?'
},
{
type: 'input',
name: 'path',
message: 'What is the PATH to the folder of your routing components?',
default: 'app/src/pages',
store: true
},
{
type: 'input',
name: 'actionName',
message: 'What is the SINGULAR class name of the sub store?'
},
{
type: 'input',
name: 'pluralActionName',
message: 'What is the PLURAL class name of the sub store?'
},
{
type: 'input',
name: 'storePath',
message: 'What is the PATH to your NgRx Store?',
default: 'src/app/store',
store: true
},
{
type: 'input',
name: 'notFoundUrl',
message: 'What url should the page load if the item is not found (e.g /home)?'
},
{
type: 'confirm',
name: 'routingModule',
message: 'Do you want this component to have a routing module?'
}
];
return this.prompt(prompts).then(props => {
this.props = props;
this.destinationRoot(`${props.path}/${paramCase(props.componentName)}`);
});
}
// Saving configurations and configure the project (creating .editorconfig files and other metadata files)
configuring() {}
// If the method name doesn’t match a priority, it will be pushed to this group.
default() {}
// Where you write the generator specific files (routes, controllers, etc)
writing() {
// Copy smart component
const { actionName, componentName, routingModule } = this.props;
this.fs.copyTpl(
this.templatePath('component.component.html'),
this.destinationPath(`${paramCase(componentName)}.component.html`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath('component.component.scss'),
this.destinationPath(`${paramCase(componentName)}.component.scss`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath('component.component.spec.ts'),
this.destinationPath(`${paramCase(componentName)}.component.spec.ts`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath('component.component.ts'),
this.destinationPath(`${paramCase(componentName)}.component.ts`),
{ ...stringUtils, ...this.props }
);
if (!routingModule) {
// Use a standard module
this.fs.copyTpl(
this.templatePath('component.module.ts'),
this.destinationPath(`${paramCase(componentName)}.module.ts`),
{ ...stringUtils, ...this.props }
);
}
// Copy presentation component
// eslint-disable-next-line prettier/prettier
const destinationFileName = `components/${paramCase(actionName)}-detail/${paramCase(actionName)}-detail`;
this.fs.copyTpl(
this.templatePath('components/item-detail/item-detail.component.html'),
this.destinationPath(`${destinationFileName}.component.html`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath('components/item-detail/item-detail.component.scss'),
this.destinationPath(`${destinationFileName}.component.scss`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath('components/item-detail/item-detail.component.spec.ts'),
this.destinationPath(`${destinationFileName}.component.spec.ts`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath('components/item-detail/item-detail.component.ts'),
this.destinationPath(`${destinationFileName}.component.ts`),
{ ...stringUtils, ...this.props }
);
}
// Where conflicts are handled (used internally)
conflicts() {}
// Where installations are run (npm, bower)
install() {}
// Called last, cleanup, say good bye, etc
end() {}
};