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

add maven:frontend-plugin and java:node generators #25733

Merged
merged 3 commits into from
Apr 4, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`generator - java:node with defaults options should call source snapshot 1`] = `{}`;

exports[`generator - java:node with defaults options should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
},
"npmw": {
"stateCleared": "modified",
},
"npmw.cmd": {
"stateCleared": "modified",
},
}
`;

exports[`generator - java:node with gradle build tool should call source snapshot 1`] = `{}`;

exports[`generator - java:node with gradle build tool should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
},
"build.gradle": {
"stateCleared": "modified",
},
"npmw": {
"stateCleared": "modified",
},
"npmw.cmd": {
"stateCleared": "modified",
},
}
`;
26 changes: 26 additions & 0 deletions generators/java/generators/node/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright 2013-2024 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 type { JHipsterCommandDefinition } from '../../../base/api.js';

const command: JHipsterCommandDefinition = {
configs: {},
import: [],
};

export default command;
81 changes: 81 additions & 0 deletions generators/java/generators/node/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Copyright 2013-2024 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 { basename, dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { before, it, describe, expect } from 'esmocha';

import { shouldSupportFeatures, testBlueprintSupport } from '../../../../test/support/tests.js';
import { defaultHelpers as helpers, result } from '../../../../testing/index.js';
import Generator from './index.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const generator = `${basename(resolve(__dirname, '../../'))}:${basename(__dirname)}`;

describe(`generator - ${generator}`, () => {
shouldSupportFeatures(Generator);
describe('blueprint support', () => testBlueprintSupport(generator));

describe('with defaults options', () => {
before(async () => {
await helpers.runJHipster(generator).withJHipsterConfig().withMockedJHipsterGenerators().withMockedSource();
});

it('should match files snapshot', () => {
expect(result.getStateSnapshot()).toMatchSnapshot();
});

it('should call source snapshot', () => {
expect(result.sourceCallsArg).toMatchSnapshot();
});

it('should compose with generators', () => {
expect(result.composedMockedGenerators).toMatchInlineSnapshot(`
[
"jhipster:java:build-tool",
"jhipster:maven:frontend-plugin",
]
`);
});
});

describe('with gradle build tool', () => {
before(async () => {
await helpers.runJHipster(generator).withJHipsterConfig().withMockedJHipsterGenerators().withMockedSource().withGradleBuildTool();
});

it('should match files snapshot', () => {
expect(result.getStateSnapshot()).toMatchSnapshot();
});

it('should call source snapshot', () => {
expect(result.sourceCallsArg).toMatchSnapshot();
});

it('should compose with generators', () => {
expect(result.composedMockedGenerators).toMatchInlineSnapshot(`
[
"jhipster:gradle:node-gradle",
"jhipster:java:build-tool",
]
`);
});
});
});
107 changes: 107 additions & 0 deletions generators/java/generators/node/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* Copyright 2013-2024 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 BaseApplicationGenerator from '../../../base-application/index.js';

export default class NodeGenerator extends BaseApplicationGenerator {
async beforeQueue() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints();
}

if (!this.delegateToBlueprint) {
await this.dependsOnBootstrapApplication();
await this.dependsOnJHipster('jhipster:java:build-tool');
}
}

get initializing() {
return this.asInitializingTaskGroup({
async parseCommand() {
await this.parseCurrentJHipsterCommand();
},
});
}

get [BaseApplicationGenerator.INITIALIZING]() {
return this.delegateTasksToBlueprint(() => this.initializing);
}

get prompting() {
return this.asPromptingTaskGroup({
async promptCommand({ control }) {
if (control.existingProject && this.options.askAnswered !== true) return;
await this.promptCurrentJHipsterCommand();
},
});
}

get [BaseApplicationGenerator.PROMPTING]() {
return this.delegateTasksToBlueprint(() => this.prompting);
}

get composing() {
return this.asComposingTaskGroup({
async compose() {
const { buildTool } = this.jhipsterConfigWithDefaults;
if (buildTool === 'maven') {
await this.composeWithJHipster('jhipster:maven:frontend-plugin');
} else if (buildTool === 'gradle') {
await this.composeWithJHipster('jhipster:gradle:node-gradle');
}
},
});
}

get [BaseApplicationGenerator.COMPOSING]() {
return this.delegateTasksToBlueprint(() => this.composing);
}

get loading() {
return this.asLoadingTaskGroup({
async loadConfig({ application }) {
await this.loadCurrentJHipsterCommandConfig(application);
},
});
}

get [BaseApplicationGenerator.LOADING]() {
return this.delegateTasksToBlueprint(() => this.loading);
}

get writing() {
return this.asWritingTaskGroup({
async writing({ application }) {
await this.writeFiles({
blocks: [
{
condition: (ctx: any) => ctx.useNpmWrapper,
transform: false,
templates: ['npmw', 'npmw.cmd'],
},
],
context: application,
});
},
});
}

get [BaseApplicationGenerator.WRITING]() {
return this.delegateTasksToBlueprint(() => this.writing);
}
}
20 changes: 20 additions & 0 deletions generators/java/generators/node/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright 2013-2024 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.
*/
export { default } from './generator.js';
export { default as command } from './command.js';
Loading
Loading