generator-zionapps
Version:
Angular 9 Code Generator
93 lines (87 loc) • 3.2 kB
JavaScript
'use strict';
const Generator = require('yeoman-generator');
const { paramCase, stringUtils } = require('@zionapps/core');
const prompts = require('../../../utils/prompts');
const {
getEndpointBaseUriPrompt,
getFrameworkOptionsPrompt,
getIdPropertyName,
getIdPropertyDataType,
getNgRxStorePath,
getPluralLoginSubStoreNamePrompt,
getSingularLoginSubStoreNamePrompt
} = prompts;
module.exports = class extends Generator {
prompting() {
const prompts = [
getFrameworkOptionsPrompt(),
getIdPropertyName(),
getIdPropertyDataType(),
getSingularLoginSubStoreNamePrompt(),
getPluralLoginSubStoreNamePrompt(),
getNgRxStorePath(),
getEndpointBaseUriPrompt()
];
return this.prompt(prompts).then(props => {
// To access props later use this.props.someAnswer;
this.props = props;
this.props.singularDomainName = 'PushNotification';
this.props.pluralDomainName = 'PushNotifications';
this.destinationRoot(
`${props.storePath}/${paramCase(this.props.pluralDomainName)}`
);
});
}
writing() {
// Copy smart component
const { framework, pluralDomainName } = this.props;
this.fs.copyTpl(
this.templatePath('push-notifications.actions.ts'),
this.destinationPath(`${paramCase(pluralDomainName)}.actions.ts`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath('push-notifications.domain.ts'),
this.destinationPath(`${paramCase(pluralDomainName)}.domain.ts`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath('push-notifications.effects.ts'),
this.destinationPath(`${paramCase(pluralDomainName)}.effects.ts`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath('push-notifications.module.ts'),
this.destinationPath(`${paramCase(pluralDomainName)}.module.ts`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath('push-notifications.reducer.ts'),
this.destinationPath(`${paramCase(pluralDomainName)}.reducer.ts`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath('push-notifications.selectors.ts'),
this.destinationPath(`${paramCase(pluralDomainName)}.selectors.ts`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath(`push-notifications.service-${framework}.ts`),
this.destinationPath(`${paramCase(pluralDomainName)}.service.ts`),
{ ...stringUtils, ...this.props }
);
this.fs.copyTpl(
this.templatePath('push-notifications.utils.ts'),
this.destinationPath(`${paramCase(pluralDomainName)}.utils.ts`),
{ ...stringUtils, ...this.props }
);
}
install() {
const { framework } = this.props;
if (framework === 'ionic') {
this.npmInstall(['@ionic-native/onesignal'], { save: true });
this.log('Please run the following commands to finish your installation');
this.log('ionic cordova plugin add onesignal-cordova-plugin');
}
}
};