UNPKG

generator-begcode

Version:

Spring Boot + Angular/React/Vue in one handy generator

91 lines (90 loc) 3.81 kB
import { defaults, kebabCase, upperFirst, camelCase, startCase } from 'lodash-es'; import { getDefaultAppName } from './support/index.js'; import BaseApplicationGenerator from '../base-application/index.js'; import { BASE_NAME } from './constants.js'; import { getHipster } from '../base/support/index.js'; import { validateProjectName } from './support/name-resolver.js'; export default class ProjectNameGenerator extends BaseApplicationGenerator { javaApplication; async beforeQueue() { this.sharedData.getControl().existingProject = this.options.defaults || this.options.applicationWithConfig || (this.jhipsterConfig.baseName !== undefined && this.config.existed); if (!this.fromBlueprint) { await this.composeWithBlueprints(); } } get initializing() { return this.asInitializingTaskGroup({ async parseCommand() { await this.parseCurrentJHipsterCommand(); }, parseOptions() { if (this.options.defaults) { if (!this.jhipsterConfig.baseName) { this.jhipsterConfig.baseName = getDefaultAppName({ reproducible: this.options.reproducible, javaApplication: this.javaApplication, }); } } }, }); } get [BaseApplicationGenerator.INITIALIZING]() { return this.delegateTasksToBlueprint(() => this.initializing); } get prompting() { return { async showPrompts() { await this.prompt([ { name: BASE_NAME, type: 'input', validate: input => this.validateBaseName(input), message: 'What is the base name of your application?', default: () => getDefaultAppName({ reproducible: this.options.reproducible, javaApplication: this.javaApplication }), }, ], this.config); }, }; } get [BaseApplicationGenerator.PROMPTING]() { return this.delegateTasksToBlueprint(() => this.prompting); } get loading() { return this.asLoadingTaskGroup({ load({ application }) { const { baseName, projectDescription } = this.jhipsterConfig; application.baseName = baseName; application.projectDescription = projectDescription; }, }); } get [BaseApplicationGenerator.LOADING]() { return this.delegateTasksToBlueprint(() => this.loading); } get preparing() { return this.asPreparingTaskGroup({ preparing({ application }) { const { baseName, upperFirstCamelCaseBaseName } = application; const humanizedBaseName = baseName.toLowerCase() === 'jhipster' ? 'JHipster' : startCase(baseName); defaults(application, { humanizedBaseName, camelizedBaseName: camelCase(baseName), hipster: getHipster(baseName), capitalizedBaseName: upperFirst(baseName), dasherizedBaseName: kebabCase(baseName), lowercaseBaseName: baseName.toLowerCase(), upperFirstCamelCaseBaseName, projectDescription: `Description for ${humanizedBaseName}`, }); }, }); } get [BaseApplicationGenerator.PREPARING]() { return this.delegateTasksToBlueprint(() => this.preparing); } validateBaseName(input) { return validateProjectName(input, { javaApplication: this.javaApplication }); } }