Skip to content

Commit

Permalink
Merge pull request #16991 from mshima/skip_ci-esm_blueprints
Browse files Browse the repository at this point in the history
Add support to esm blueprints.
  • Loading branch information
mshima authored Nov 15, 2021
2 parents 793db97 + a8d765b commit 4825c2c
Show file tree
Hide file tree
Showing 35 changed files with 512 additions and 484 deletions.
4 changes: 2 additions & 2 deletions cli/jhipster-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ class JHipsterCommand extends Command {
* @private
* Override _parseCommand to execute a callback before parsing.
*/
_parseCommand(operands, unknown) {
async _parseCommand(operands, unknown) {
if (this._lazyBuildCommandCallBack) {
this._lazyBuildCommandCallBack(operands, unknown);
await this._lazyBuildCommandCallBack(operands, unknown);
}
return super._parseCommand(operands, unknown);
}
Expand Down
60 changes: 31 additions & 29 deletions cli/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const buildCommands = ({ program, commands = {}, envBuilder, env, loadCommand })
.excessArgumentsCallback(function (receivedArgs) {
rejectExtraArgs(program, this.name(), receivedArgs);
})
.lazyBuildCommand(function (operands) {
.lazyBuildCommand(async function (operands) {
logger.debug(`cmd: lazyBuildCommand ${cmdName} ${operands}`);
const command = this;
if (cmdName === 'run') {
Expand All @@ -103,25 +103,27 @@ const buildCommands = ({ program, commands = {}, envBuilder, env, loadCommand })
namespace => `${namespace.startsWith(JHIPSTER_NS) ? '' : `${JHIPSTER_NS}-`}${namespace}`
);
envBuilder.lookupGenerators(command.generatorNamespaces.map(namespace => `generator-${namespace.split(':')[0]}`));
command.generatorNamespaces.forEach(namespace => {
if (!env.getPackagePath(namespace)) {
logger.fatal(chalk.red(`\nGenerator ${namespace} not found.\n`));
}
const generator = env.create(namespace, { options: { help: true } });
this.addGeneratorArguments(generator._arguments).addGeneratorOptions(generator._options);
});
await Promise.all(
command.generatorNamespaces.map(async namespace => {
if (!(await env.getPackagePath(namespace))) {
logger.fatal(chalk.red(`\nGenerator ${namespace} not found.\n`));
}
const generator = await env.create(namespace, { options: { help: true } });
this.addGeneratorArguments(generator._arguments).addGeneratorOptions(generator._options);
})
);
return;
}
if (!opts.cliOnly || cmdName === 'jdl') {
if (opts.blueprint) {
// Blueprint only command.
const generator = env.create(`${packageNameToNamespace(opts.blueprint)}:${cmdName}`, { options: { help: true } });
const generator = await env.create(`${packageNameToNamespace(opts.blueprint)}:${cmdName}`, { options: { help: true } });
command.addGeneratorArguments(generator._arguments).addGeneratorOptions(generator._options);
} else {
const generatorName = cmdName === 'jdl' ? 'app' : cmdName;
// Register jhipster upstream options.
if (cmdName !== 'jdl') {
const generator = env.create(`${JHIPSTER_NS}:${cmdName}`, { options: { help: true } });
const generator = await env.create(`${JHIPSTER_NS}:${cmdName}`, { options: { help: true } });
command.addGeneratorArguments(generator._arguments).addGeneratorOptions(generator._options);

const usagePath = path.resolve(generator.sourceRoot(), '../USAGE');
Expand All @@ -130,34 +132,34 @@ const buildCommands = ({ program, commands = {}, envBuilder, env, loadCommand })
}
}
if (cmdName === 'jdl' || program.opts().fromJdl) {
const appGenerator = env.create(`${JHIPSTER_NS}:app`, { options: { help: true } });
const appGenerator = await env.create(`${JHIPSTER_NS}:app`, { options: { help: true } });
command.addGeneratorOptions(appGenerator._options, chalk.gray(' (application)'));

const workspacesGenerator = env.create(`${JHIPSTER_NS}:workspaces`, { options: { help: true } });
const workspacesGenerator = await env.create(`${JHIPSTER_NS}:workspaces`, { options: { help: true } });
command.addGeneratorOptions(workspacesGenerator._options, chalk.gray(' (workspaces)'));
}

// Register blueprint specific options.
envBuilder.getBlueprintsNamespaces().forEach(blueprintNamespace => {
const generatorNamespace = `${blueprintNamespace}:${generatorName}`;
if (!env.get(generatorNamespace)) {
return;
}
const blueprintName = blueprintNamespace.replace(/^jhipster-/, '');
try {
command.addGeneratorOptions(
env.create(generatorNamespace, { options: { help: true } })._options,
chalk.yellow(` (blueprint option: ${blueprintName})`)
);
} catch (error) {
logger.info(`Error parsing options for generator ${generatorNamespace}, error: ${error}`);
}
});
await Promise.all(
envBuilder.getBlueprintsNamespaces().map(async blueprintNamespace => {
const generatorNamespace = `${blueprintNamespace}:${generatorName}`;
if (!(await env.get(generatorNamespace))) {
return;
}
const blueprintName = blueprintNamespace.replace(/^jhipster-/, '');
const blueprintGenerator = await env.create(generatorNamespace, { options: { help: true } });
try {
command.addGeneratorOptions(blueprintGenerator._options, chalk.yellow(` (blueprint option: ${blueprintName})`));
} catch (error) {
logger.info(`Error parsing options for generator ${generatorNamespace}, error: ${error}`);
}
})
);
}
}
command.addHelpText('after', moreInfo);
})
.action((...everything) => {
.action(async (...everything) => {
logger.debug('cmd: action');
// [args, opts, command]
const command = everything.pop();
Expand All @@ -177,7 +179,7 @@ const buildCommands = ({ program, commands = {}, envBuilder, env, loadCommand })
logger.debug('Executing CLI only script');
return loadCommand(cmdName)(args, options, env, envBuilder);
}
env.composeWith('jhipster:bootstrap', options);
await env.composeWith('jhipster:bootstrap', options);

if (cmdName === 'run') {
return Promise.all(command.generatorNamespaces.map(generator => env.run(generator, options))).then(
Expand Down
55 changes: 30 additions & 25 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const prompts = require('./prompts');
const packagejs = require('../../package.json');
const statistics = require('../statistics');
const { appDefaultConfig } = require('../generator-defaults');
const { GENERATOR_APP } = require('../generator-list');
const { JHIPSTER_CONFIG_DIR, GENERATOR_JHIPSTER } = require('../generator-constants');
const { MICROSERVICE } = require('../../jdl/jhipster/application-types');
const { OptionNames } = require('../../jdl/jhipster/application-options');
Expand All @@ -39,8 +40,6 @@ const {
GENERATOR_SERVER,
} = require('../generator-list');

let useBlueprints;

module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
constructor(args, options, features) {
super(args, options, { unique: 'namespace', ...features });
Expand Down Expand Up @@ -293,8 +292,12 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
this.existingProject = this.jhipsterConfig.baseName !== undefined && this.jhipsterConfig.applicationType !== undefined;
// preserve old jhipsterVersion value for cleanup which occurs after new config is written into disk
this.jhipsterOldVersion = this.jhipsterConfig.jhipsterVersion;
}

useBlueprints = !this.fromBlueprint && this.instantiateBlueprints('app');
async _postConstruct() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_APP);
}
}

_initializing() {
Expand Down Expand Up @@ -343,7 +346,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
}

get initializing() {
if (useBlueprints) {
if (this.delegateToBlueprint) {
return;
}
return this._initializing();
Expand All @@ -358,7 +361,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
}

get prompting() {
if (useBlueprints) return;
if (this.delegateToBlueprint) return;
return this._prompting();
}

Expand All @@ -385,7 +388,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
}

get configuring() {
if (useBlueprints) return;
if (this.delegateToBlueprint) return;
return this._configuring();
}

Expand All @@ -402,16 +405,16 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
* When composing in different tasks the result would be:
* - composeCommon (app) -> initializing (common) -> prompting (common) -> ... -> composeServer (app) -> initializing (server) -> ...
*/
compose() {
this.composeWithJHipster(GENERATOR_COMMON, true);
async compose() {
await this.composeWithJHipster(GENERATOR_COMMON, true);
if (!this.jhipsterConfig.skipServer) {
this.composeWithJHipster(GENERATOR_SERVER, true);
await this.composeWithJHipster(GENERATOR_SERVER, true);
}
if (!this.jhipsterConfig.skipClient) {
this.composeWithJHipster(GENERATOR_CLIENT, true);
await this.composeWithJHipster(GENERATOR_CLIENT, true);
}
if (!this.configOptions.skipI18n) {
this.composeWithJHipster(
await this.composeWithJHipster(
GENERATOR_LANGUAGES,
{
regenerate: true,
Expand Down Expand Up @@ -441,26 +444,28 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
this.config.set(config);
},

composeEntities() {
async composeEntities() {
if (!this.options.withEntities) return;
this.composeWithJHipster(GENERATOR_ENTITIES, { skipInstall: true }, true);
await this.composeWithJHipster(GENERATOR_ENTITIES, { skipInstall: true }, true);
},

composePages() {
async composePages() {
if (!this.jhipsterConfig.pages || this.jhipsterConfig.pages.length === 0 || this.configOptions.skipComposePage) return;
this.configOptions.skipComposePage = true;
this.jhipsterConfig.pages.forEach(page => {
this.composeWithJHipster(page.generator || GENERATOR_PAGE, [page.name], {
skipInstall: true,
page,
});
});
await Promise.all(
this.jhipsterConfig.pages.map(page => {
return this.composeWithJHipster(page.generator || GENERATOR_PAGE, [page.name], {
skipInstall: true,
page,
});
})
);
},
};
}

get composing() {
if (useBlueprints) return;
if (this.delegateToBlueprint) return;
return this._composing();
}

Expand All @@ -479,7 +484,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
}

get default() {
if (useBlueprints) return;
if (this.delegateToBlueprint) return;
return this._default();
}

Expand All @@ -495,7 +500,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
}

get writing() {
if (useBlueprints) return;
if (this.delegateToBlueprint) return;
return this._writing();
}

Expand All @@ -512,7 +517,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
}

get install() {
if (useBlueprints) return;
if (this.delegateToBlueprint) return;
return this._install();
}

Expand Down Expand Up @@ -556,7 +561,7 @@ module.exports = class JHipsterAppGenerator extends BaseBlueprintGenerator {
}

get end() {
if (useBlueprints) return;
if (this.delegateToBlueprint) return;
return this._end();
}

Expand Down
16 changes: 8 additions & 8 deletions generators/aws/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ const { BUILD_TOOL, BASE_NAME, PROD_DATABASE_TYPE } = OptionNames;

const { MYSQL, POSTGRESQL, MARIADB } = require('../../jdl/jhipster/database-types');

let useBlueprints;
/* eslint-disable consistent-return */
module.exports = class extends BaseBlueprintGenerator {
constructor(args, options, features) {
super(args, options, features);
useBlueprints = !this.fromBlueprint && this.instantiateBlueprints(GENERATOR_AWS);
async _postConstruct() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints(GENERATOR_AWS);
}
}

_initializing() {
Expand Down Expand Up @@ -90,7 +90,7 @@ module.exports = class extends BaseBlueprintGenerator {
}

get initializing() {
if (useBlueprints) return;
if (this.delegateToBlueprint) return {};
return this._initializing();
}

Expand All @@ -99,7 +99,7 @@ module.exports = class extends BaseBlueprintGenerator {
}

get prompting() {
if (useBlueprints) return;
if (this.delegateToBlueprint) return {};
return this._prompting();
}

Expand Down Expand Up @@ -128,7 +128,7 @@ module.exports = class extends BaseBlueprintGenerator {
}

get configuring() {
if (useBlueprints) return;
if (this.delegateToBlueprint) return {};
return this._configuring();
}

Expand Down Expand Up @@ -286,7 +286,7 @@ module.exports = class extends BaseBlueprintGenerator {
}

get default() {
if (useBlueprints) return;
if (this.delegateToBlueprint) return {};
return this._default();
}
};
Loading

0 comments on commit 4825c2c

Please sign in to comment.