Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip applications install when generating workspaces. #18869

Merged
merged 2 commits into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions cli/import-jdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function writeApplicationConfig(applicationWithEntities, basePath) {
* @param {Promise}
*/
function runGenerator(command, { cwd, fork, env }, generatorOptions = {}) {
const { workspaces } = generatorOptions;
generatorOptions = {
...generatorOptions,
// Remove jdl command exclusive options
Expand All @@ -161,6 +162,9 @@ function runGenerator(command, { cwd, fork, env }, generatorOptions = {}) {
commandName: undefined,
fromJdl: true,
};
if (workspaces) {
generatorOptions.skipInstall = true;
}
if (!generatorOptions.blueprints) {
delete generatorOptions.blueprints;
}
Expand Down Expand Up @@ -387,13 +391,10 @@ class JDLProcessor {
statistics.sendSubGenEvent('generator', 'import-jdl');
}

generateWorkspaces(options) {
if (!options.workspaces || !multiplesApplications(this)) {
return Promise.resolve();
}
generateWorkspaces(options, generateJdl) {
return EnvironmentBuilder.createDefaultBuilder()
.getEnvironment()
.run('jhipster:workspaces', { workspaces: false, ...options, importState: this.importState });
.run('jhipster:workspaces', { workspaces: false, ...options, importState: this.importState, generateJdl });
}

generateApplications() {
Expand Down Expand Up @@ -528,15 +529,25 @@ module.exports = (jdlFiles, options = {}, env) => {
jdlImporter.sendInsight();
jdlImporter.config();

return jdlImporter
.generateWorkspaces(options)
.then(() => jdlImporter.generateApplications())
.then(() => jdlImporter.generateEntities(env))
.then(() => jdlImporter.generateDeployments())
.then(() => {
printSuccess();
return jdlFiles;
});
const generateJdl = () =>
jdlImporter
.generateApplications()
.then(() => jdlImporter.generateEntities(env))
.then(() => jdlImporter.generateDeployments());

let generation;
if (!options.workspaces || !multiplesApplications(jdlImporter)) {
generation = generateJdl();
} else {
// Wrap generation inside workspaces root generation.
// generate applications after git initialization and before root npm install
generation = jdlImporter.generateWorkspaces(options, generateJdl);
}

return generation.then(() => {
printSuccess();
return jdlFiles;
});
} catch (e) {
logger.error(`Error during import-jdl: ${e}`, e);
return Promise.reject(new Error(`Error during import-jdl: ${e.message}`));
Expand Down
53 changes: 26 additions & 27 deletions generators/workspaces/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
const fs = require('fs');
const path = require('path');

const { CONFIGURING_PRIORITY, LOADING_PRIORITY, WRITING_PRIORITY, POST_WRITING_PRIORITY, INSTALL_PRIORITY } =
const { INITIALIZING_PRIORITY, CONFIGURING_PRIORITY, LOADING_PRIORITY, WRITING_PRIORITY, POST_WRITING_PRIORITY } =
require('../../lib/constants/priorities.cjs').compat;

const { GENERATOR_JHIPSTER } = require('../generator-constants');
Expand Down Expand Up @@ -60,6 +60,26 @@ module.exports = class extends BaseBlueprintGenerator {
this.loadRuntimeOptions();
}

_initializing() {
return {
initializeGit() {
if (!this.options.monorepository) return;
this.checkGit();
this.initializeGitRepository();
},

generateJdl() {
const { generateJdl } = this.options;
return generateJdl();
},
};
}

get [INITIALIZING_PRIORITY]() {
if (this.delegateToBlueprint) return {};
return this._initializing();
}

_configuring() {
return {
async configureUsingImportState() {
Expand Down Expand Up @@ -126,6 +146,11 @@ module.exports = class extends BaseBlueprintGenerator {
this.packages = this.workspacesConfig.packages;
this.env.options.nodePackageManager = this.workspacesConfig.clientPackageManager;
},
loadDependabotPackageJson() {
if (!this.generateWorkspaces) return;

this._.merge(this.dependabotPackageJson, this.fs.readJSON(this.fetchFromInstalledJHipster('common', 'templates', 'package.json')));
},
};
}

Expand Down Expand Up @@ -161,11 +186,6 @@ module.exports = class extends BaseBlueprintGenerator {

_postWriting() {
return {
loadDependabotPackageJson() {
if (!this.generateWorkspaces) return;

this._.merge(this.dependabotPackageJson, this.fs.readJSON(this.fetchFromInstalledJHipster('common', 'templates', 'package.json')));
},
generatePackageJson() {
if (!this.generateWorkspaces) return;

Expand Down Expand Up @@ -194,27 +214,6 @@ module.exports = class extends BaseBlueprintGenerator {
return this._postWriting();
}

// Public API method used by the getter and also by Blueprints
_install() {
return {
validateGit() {
if (!this.options.monorepository) return;
this.checkGit();
},

/** Initialize git repository before package manager install for commit hooks */
initGitRepo() {
if (!this.options.monorepository) return;
this.initializeGitRepository();
},
};
}

get [INSTALL_PRIORITY]() {
if (this.delegateToBlueprint) return {};
return this._install();
}

_detectNodePackageManager() {
if (this.options.clientPackageManager !== undefined) {
return this.options.clientPackageManager;
Expand Down