UNPKG

generator-zionapps

Version:

Angular 9 Code Generator

105 lines (97 loc) 3.58 kB
'use strict'; const Generator = require('yeoman-generator'); // Const esprima = require('esprima'); const { paramCase, stringUtils } = require('@zionapps/core'); const prompts = require('../../../utils/prompts'); const { getApplicationType, getDatabaseNamePrompt, getEndpointBaseUriPrompt, getExtendDomainCode, getIdPropertyDataType, getIdPropertyName, getNgRxStorePath, getPluralSubStoreNamePrompt, getSingularSubStoreNamePrompt } = prompts; module.exports = class extends Generator { // Arguments should be defined in the constructor constructor(args, opts) { super(args, opts); // Pass along props from a parent generator this.props = opts.props || {}; } prompting() { const prompts = [ getSingularSubStoreNamePrompt(), getPluralSubStoreNamePrompt(), getDatabaseNamePrompt(), getEndpointBaseUriPrompt(), getIdPropertyName(), getIdPropertyDataType(), getApplicationType(), getExtendDomainCode(), getNgRxStorePath() ]; return this.prompt(prompts).then(props => { this.props = { ...this.props, ...props }; this.destinationRoot(`${props.storePath}/${paramCase(props.pluralDomainName)}`); }); } writing() { const { databaseName, extendDomainCode, pluralDomainName, singularDomainName } = this.props; const useExtendedCode = extendDomainCode ? '-extended' : ''; const databasePath = '../../../../../shared/domain/src/lib/'; this.fs.copyTpl( this.templatePath(`sub-store.actions${useExtendedCode}.ts`), this.destinationPath(`${paramCase(pluralDomainName)}.actions.ts`), { ...stringUtils, ...this.props } ); this.fs.copyTpl( this.templatePath(`sub-store.constants.ts`), this.destinationPath(`${paramCase(pluralDomainName)}.constants.ts`), { ...stringUtils, ...this.props } ); this.fs.copyTpl( this.templatePath('sub-store.domain.ts'), this.destinationPath(`${paramCase(pluralDomainName)}.domain.ts`), { ...stringUtils, ...this.props } ); this.fs.copyTpl( this.templatePath('sub-store.effects.ts'), this.destinationPath(`${paramCase(pluralDomainName)}.effects.ts`), { ...stringUtils, ...this.props } ); this.fs.copyTpl( this.templatePath('sub-store.module.ts'), this.destinationPath(`${paramCase(pluralDomainName)}.module.ts`), { ...stringUtils, ...this.props } ); this.fs.copyTpl( this.templatePath(`sub-store.reducer${useExtendedCode}.ts`), this.destinationPath(`${paramCase(pluralDomainName)}.reducer.ts`), { ...stringUtils, ...this.props } ); this.fs.copyTpl( this.templatePath(`sub-store.selectors.ts`), this.destinationPath(`${paramCase(pluralDomainName)}.selectors.ts`), { ...stringUtils, ...this.props } ); this.fs.copyTpl( this.templatePath(`sub-store.service.ts`), this.destinationPath(`${paramCase(pluralDomainName)}.service.ts`), { ...stringUtils, ...this.props } ); this.fs.copyTpl( this.templatePath('sub-store.utils.ts'), this.destinationPath(`${paramCase(pluralDomainName)}.utils.ts`), { ...stringUtils, ...this.props } ); this.fs.copyTpl( this.templatePath('sub-store.interface.ts'), this.destinationPath(`${databasePath}${paramCase(databaseName)}/interfaces/${paramCase(singularDomainName)}.ts`), { ...stringUtils, ...this.props } ); } install() {} };