gen-jhipster
Version:
VHipster - Spring Boot + Angular/React/Vue in one handy generator
124 lines (123 loc) • 4.87 kB
JavaScript
/**
* Copyright 2013-2026 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import chalk from 'chalk';
import { camelCase } from 'lodash-es';
import BaseApplicationGenerator from "../base-application/index.js";
import { getDefaultAppName } from "../project-name/support/index.js";
import cleanupOldFilesTask from "./cleanup.js";
import { checkNode } from "./support/index.js";
export default class AppGenerator extends BaseApplicationGenerator {
async beforeQueue() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints();
}
if (!this.delegateToBlueprint) {
await this.dependsOnBootstrap('app');
}
}
get initializing() {
return this.asInitializingTaskGroup({
validateNode() {
if (this.skipChecks) {
return;
}
checkNode(this.logger);
},
async checkForNewJHVersion() {
if (!this.skipChecks) {
await this.checkForNewVersion();
}
},
validate() {
if (!this.skipChecks && this.jhipsterConfig.skipServer && this.jhipsterConfig.skipClient) {
throw new Error(`You can not pass both ${chalk.yellow('--skip-client')} and ${chalk.yellow('--skip-server')} together`);
}
},
});
}
get [BaseApplicationGenerator.INITIALIZING]() {
return this.delegateTasksToBlueprint(() => this.initializing);
}
get configuring() {
return this.asConfiguringTaskGroup({
fixConfig() {
if (this.jhipsterConfig.jhiPrefix) {
this.jhipsterConfig.jhiPrefix = camelCase(this.jhipsterConfig.jhiPrefix);
}
},
defaults() {
if (!this.options.reproducible) {
this.config.defaults({
baseName: getDefaultAppName({ cwd: this.destinationPath() }),
creationTimestamp: Date.now(),
});
}
},
loadGlobalConfig() {
if (!this.options.reproducible) {
const globalConfig = this._globalConfig.getAll();
if (Object.keys(globalConfig).length > 0) {
this.log.warn('Using global configuration values:', globalConfig);
this.config.defaults(globalConfig);
}
}
},
});
}
get [BaseApplicationGenerator.CONFIGURING]() {
return this.delegateTasksToBlueprint(() => this.configuring);
}
get composingComponent() {
return this.asComposingComponentTaskGroup({
/**
* Composing with others generators, must be executed after `configuring` priority to let others
* generators `configuring` priority to run.
*
* Composing in different tasks the result would be:
* - composeCommon (app) -> initializing (common) -> prompting (common) -> ... -> composeServer (app) -> initializing (server) -> ...
*
* This behaviour allows a more consistent blueprint support.
*/
async composeCommon() {
await this.composeWithJHipster('common');
},
async composeServer() {
if (!this.jhipsterConfigWithDefaults.skipServer) {
await this.composeWithJHipster('server');
}
},
async composeClient() {
if (!this.jhipsterConfigWithDefaults.skipClient) {
await this.composeWithJHipster('client');
}
},
});
}
get [BaseApplicationGenerator.COMPOSING_COMPONENT]() {
return this.delegateTasksToBlueprint(() => this.composingComponent);
}
get writing() {
return this.asWritingTaskGroup({
cleanupOldFilesTask,
});
}
get [BaseApplicationGenerator.WRITING]() {
return this.delegateTasksToBlueprint(() => this.writing);
}
}