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

move npmw install task to java:node #27360

Merged
merged 1 commit into from
Sep 23, 2024
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
37 changes: 37 additions & 0 deletions generators/java/generators/node/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import chalk from 'chalk';
import type { ExecaError } from 'execa';
import BaseApplicationGenerator from '../../../base-application/index.js';

export default class NodeGenerator extends BaseApplicationGenerator {
Expand Down Expand Up @@ -47,6 +49,20 @@ export default class NodeGenerator extends BaseApplicationGenerator {
return this.delegateTasksToBlueprint(() => this.composing);
}

get postPreparing() {
return this.asPostPreparingTaskGroup({
useNpmWrapper({ application }) {
if (application.useNpmWrapper) {
this.useNpmWrapperInstallTask();
}
},
});
}

get [BaseApplicationGenerator.POST_PREPARING]() {
return this.delegateTasksToBlueprint(() => this.postPreparing);
}

get writing() {
return this.asWritingTaskGroup({
async writing({ application }) {
Expand All @@ -67,4 +83,25 @@ export default class NodeGenerator extends BaseApplicationGenerator {
get [BaseApplicationGenerator.WRITING]() {
return this.delegateTasksToBlueprint(() => this.writing);
}

useNpmWrapperInstallTask() {
this.setFeatures({
customInstallTask: async (preferredPm, defaultInstallTask) => {
const buildTool = this.jhipsterConfigWithDefaults.buildTool;
if ((preferredPm && preferredPm !== 'npm') || this.jhipsterConfig.skipClient || (buildTool !== 'gradle' && buildTool !== 'maven')) {
await defaultInstallTask();
return;
}

const npmCommand = process.platform === 'win32' ? 'npmw' : './npmw';
try {
await this.spawn(npmCommand, ['install'], { preferLocal: true });
} catch (error: unknown) {
this.log.error(
chalk.red(`Error executing '${npmCommand} install', please execute it yourself. (${(error as ExecaError).shortMessage})`),
);
}
},
});
}
}
34 changes: 0 additions & 34 deletions generators/server/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

import { existsSync } from 'fs';
import chalk from 'chalk';

import { GENERATOR_COMMON, GENERATOR_SPRING_BOOT } from '../generator-list.js';
import BaseApplicationGenerator from '../base-application/index.js';
Expand Down Expand Up @@ -216,20 +215,6 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator {
return this.delegateTasksToBlueprint(() => this.preparing);
}

get postPreparing() {
return this.asPostPreparingTaskGroup({
useNpmWrapper({ application }) {
if (application.useNpmWrapper) {
this.useNpmWrapperInstallTask();
}
},
});
}

get [BaseApplicationGenerator.POST_PREPARING]() {
return this.delegateTasksToBlueprint(() => this.postPreparing);
}

get configuringEachEntity() {
return this.asConfiguringEachEntityTaskGroup({
configureMicroservice({ application, entityConfig }) {
Expand Down Expand Up @@ -646,25 +631,6 @@ ${instructions}`,
}
}

useNpmWrapperInstallTask() {
this.setFeatures({
customInstallTask: async function customInstallTask(preferredPm, defaultInstallTask) {
const buildTool = this.jhipsterConfigWithDefaults.buildTool;
if ((preferredPm && preferredPm !== 'npm') || this.jhipsterConfig.skipClient || (buildTool !== GRADLE && buildTool !== MAVEN)) {
return defaultInstallTask();
}

const npmCommand = process.platform === 'win32' ? 'npmw' : './npmw';
try {
await this.spawnCommand(npmCommand, ['install'], { preferLocal: true });
} catch (error) {
this.log.error(chalk.red(`Error executing '${npmCommand} install', please execute it yourself. (${error.shortMessage})`));
}
return true;
}.bind(this),
});
}

_validateRelationship(entityName, relationship) {
if (relationship.otherEntityName === undefined) {
throw new Error(
Expand Down
Loading