generator-zionapps
Version:
Angular 9 Code Generator
102 lines (95 loc) • 3.06 kB
JavaScript
'use strict';
const Generator = require('yeoman-generator');
// Const esprima = require('esprima');
const { paramCase, stringUtils } = require('@zionapps/core');
const prompts = require('../../../utils/prompts');
const {
getPageNamePrompt,
getIdPropertyName,
getIonicPagesPathPrompt,
getPluralSubStoreNamePrompt,
getSingularSubStoreNamePrompt,
getSignaturePadPrompt
} = prompts;
module.exports = class extends Generator {
prompting() {
const prompts = [
getPageNamePrompt(),
getSingularSubStoreNamePrompt(),
getPluralSubStoreNamePrompt(),
getIdPropertyName(),
getIonicPagesPathPrompt(),
getSignaturePadPrompt()
];
return this.prompt(prompts).then(props => {
this.props = props;
this.destinationRoot(`${props.ionicPagesPath}/${paramCase(props.pageName)}`);
});
}
writing() {
const { pageName, singularDomainName } = this.props;
const pagePath = `${paramCase(pageName)}`;
const formPath = `${paramCase(singularDomainName)}-form/${paramCase(
singularDomainName
)}-form`;
const widgetPath = `${paramCase(singularDomainName)}-widget/${paramCase(
singularDomainName
)}-widget`;
this.fs.copyTpl(
this.templatePath(`page.html`),
this.destinationPath(`${pagePath}.html`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath(`page.module.ts`),
this.destinationPath(`${pagePath}.module.ts`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath(`page.scss`),
this.destinationPath(`${pagePath}.scss`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath(`page.ts`),
this.destinationPath(`${pagePath}.ts`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath(`form/form.html`),
this.destinationPath(`${formPath}.html`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath(`form/form.scss`),
this.destinationPath(`${formPath}.scss`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath(`form/form.ts`),
this.destinationPath(`${formPath}.ts`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath(`widget/widget.html`),
this.destinationPath(`${widgetPath}.html`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath(`widget/widget.scss`),
this.destinationPath(`${widgetPath}.scss`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath(`widget/widget.ts`),
this.destinationPath(`${widgetPath}.ts`),
{ ...stringUtils, ...this.props }
);
}
install() {
const { npmInstallSignaturePad } = this.props;
if (npmInstallSignaturePad) {
this.npmInstall(['angular2-signaturepad'], { save: true });
}
}
};