Skip to content

Commit

Permalink
move npmw install task to java:node
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 22, 2024
1 parent d49bf40 commit 75dba3d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
38 changes: 38 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,26 @@ 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})`),
);
}
return;

Check failure on line 104 in generators/java/generators/node/generator.ts

View workflow job for this annotation

GitHub Actions / check-npm-test

Unnecessary return statement
},
});
}
}
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

0 comments on commit 75dba3d

Please sign in to comment.