Skip to content

Commit

Permalink
switch to rspack
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 19, 2024
1 parent 67d9b6b commit 45a35e6
Show file tree
Hide file tree
Showing 20 changed files with 477 additions and 654 deletions.
4 changes: 2 additions & 2 deletions generators/client/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ export default class JHipsterClientGenerator extends BaseApplicationGenerator {
source.addWebpackConfig({
config: `${conditional}require('./webpack.microfrontend')(config, options, targetOptions)`,
});
} else if (application.clientFrameworkVue || application.clientFrameworkReact) {
} else if (application.clientFrameworkReact) {
source.addWebpackConfig({ config: "require('./webpack.microfrontend')({ serve: options.env.WEBPACK_SERVE })" });
} else {
} else if (!application.clientFrameworkVue) {
throw new Error(`Client framework ${application.clientFramework} doesn't support microfrontends`);
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

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

exports[`generator - javascript:rsbuild with defaults options should match files snapshot 1`] = `
{
".yo-rc.json": {
"stateCleared": "modified",
},
"package.json": {
"stateCleared": "modified",
},
"rsbuild.config.mjs.jhi": {
"stateCleared": "modified",
},
}
`;
26 changes: 26 additions & 0 deletions generators/javascript/generators/rsbuild/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 '../../../../lib/command/types.js';

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

export default command;
53 changes: 53 additions & 0 deletions generators/javascript/generators/rsbuild/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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, describe, expect, it } from 'esmocha';

import { shouldSupportFeatures, testBlueprintSupport } from '../../../../test/support/tests.js';
import { defaultHelpers as helpers, result } from '../../../../lib/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).withMockedJHipsterGenerators().withMockedSource().withSharedApplication({}).withJHipsterConfig();
});

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(`[]`);
});
});
});
129 changes: 129 additions & 0 deletions generators/javascript/generators/rsbuild/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* 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 BaseGenerator from '../../../../generators/base-application/index.js';

export default class RspackGenerator extends BaseGenerator {
constructor(args, options, features) {
super(args, options, { queueCommandTasks: true, ...features });
}

async beforeQueue() {
if (!this.fromBlueprint) {
await this.composeWithBlueprints();
}

if (!this.delegateToBlueprint) {
await this.dependsOnBootstrapApplication();
}
}

get preparing() {
return this.asPreparingTaskGroup({});
}

get [BaseGenerator.PREPARING]() {
return this.delegateTasksToBlueprint(() => this.preparing);
}

get postPreparing() {
return this.asPostPreparingTaskGroup({});
}

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

get preparingEachEntity() {
return this.asPreparingEachEntityTaskGroup({});
}

get [BaseGenerator.PREPARING_EACH_ENTITY]() {
return this.delegateTasksToBlueprint(() => this.preparingEachEntity);
}

get preparingEachEntityField() {
return this.asPreparingEachEntityFieldTaskGroup({});
}

get [BaseGenerator.PREPARING_EACH_ENTITY_FIELD]() {
return this.delegateTasksToBlueprint(() => this.preparingEachEntityField);
}

get preparingEachEntityRelationship() {
return this.asPreparingEachEntityRelationshipTaskGroup({});
}

get [BaseGenerator.PREPARING_EACH_ENTITY_RELATIONSHIP]() {
return this.delegateTasksToBlueprint(() => this.preparingEachEntityRelationship);
}

get postPreparingEachEntity() {
return this.asPostPreparingEachEntityTaskGroup({});
}

get [BaseGenerator.POST_PREPARING_EACH_ENTITY]() {
return this.delegateTasksToBlueprint(() => this.postPreparingEachEntity);
}

get default() {
return this.asDefaultTaskGroup({});
}

get [BaseGenerator.DEFAULT]() {
return this.delegateTasksToBlueprint(() => this.default);
}

get writing() {
return this.asWritingTaskGroup({
async writeFiles({ application }) {
await this.writeFiles({
blocks: [{ templates: ['rsbuild.config.mjs.jhi'] }],
context: application,
});
},
});
}

get [BaseGenerator.WRITING]() {
return this.delegateTasksToBlueprint(() => this.writing);
}

get postWriting() {
return this.asPostWritingTaskGroup({
addScripts({ application }) {
this.packageJson.merge({
devDependencies: {
'@rsbuild/core': 'latest',
},
scripts: {
start: 'rsbuild dev',
build: 'rsbuild build',
'webapp:build:dev': `${application.clientPackageManager} run build -- --mode=development`,
'webapp:build:prod': `${application.clientPackageManager} run build -- --mode=production`,
'webapp:dev': `${application.clientPackageManager} run start`,
},
});
},
});
}

get [BaseGenerator.POST_WRITING]() {
return this.delegateTasksToBlueprint(() => this.postWriting);
}
}
20 changes: 20 additions & 0 deletions generators/javascript/generators/rsbuild/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';
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<%#
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.
-%>
<&_
// Register sections and max allowed fragments, 0 for unlimited.
fragments.registerSections({
importsSection: 0,
pluginsSection: 0,
configSection: 0,
});
_&>
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from '@rsbuild/core';
<&- fragments.importsSection() -&>

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

export default defineConfig({
context: __dirname,
output: {
path: './<%= this.relativeDir(clientRootDir, clientDistDir) %>',
uniqueName: '<%= lowercaseBaseName %>',
},
html: {
template: './<%= this.relativeDir(clientRootDir, clientSrcDir) %>index.html',
},
plugins: [
<&- fragments.pluginsSection() -&>
],
<&- fragments.configSection() -&>
});
35 changes: 10 additions & 25 deletions generators/vue/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1431,22 +1431,16 @@ exports[`generator - vue microservice-jwt-skipUserManagement(false)-withAdminUi(
"clientRoot/vitest.config.mts": {
"stateCleared": "modified",
},
"clientRoot/webpack/config.js": {
"stateCleared": "modified",
},
"clientRoot/webpack/vue.utils.js": {
"clientRoot/webpack/webpack.microfrontend.js": {
"stateCleared": "modified",
},
"clientRoot/webpack/webpack.common.js": {
"package.json": {
"stateCleared": "modified",
},
"clientRoot/webpack/webpack.dev.js": {
"rsbuild.config.mjs": {
"stateCleared": "modified",
},
"clientRoot/webpack/webpack.microfrontend.js": {
"stateCleared": "modified",
},
"clientRoot/webpack/webpack.prod.js": {
"rsbuild.module-federation.config.mjs": {
"stateCleared": "modified",
},
}
Expand Down Expand Up @@ -1478,6 +1472,12 @@ exports[`generator - vue microservice-oauth2-withAdminUi(true)-skipJhipsterDepen
"package.json": {
"stateCleared": "modified",
},
"rsbuild.config.mjs": {
"stateCleared": "modified",
},
"rsbuild.module-federation.config.mjs": {
"stateCleared": "modified",
},
"src/main/webapp/404.html": {
"stateCleared": "modified",
},
Expand Down Expand Up @@ -1907,24 +1907,9 @@ exports[`generator - vue microservice-oauth2-withAdminUi(true)-skipJhipsterDepen
"vitest.config.mts": {
"stateCleared": "modified",
},
"webpack/config.js": {
"stateCleared": "modified",
},
"webpack/vue.utils.js": {
"stateCleared": "modified",
},
"webpack/webpack.common.js": {
"stateCleared": "modified",
},
"webpack/webpack.dev.js": {
"stateCleared": "modified",
},
"webpack/webpack.microfrontend.js": {
"stateCleared": "modified",
},
"webpack/webpack.prod.js": {
"stateCleared": "modified",
},
}
`;

Expand Down
13 changes: 3 additions & 10 deletions generators/vue/files-vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,10 @@ export const vueFiles = {
}),
],
microfrontend: [
clientRootTemplatesBlock({
{
condition: generator => generator.microfrontend,
templates: [
'webpack/config.js',
'webpack/webpack.common.js',
'webpack/webpack.dev.js',
'webpack/webpack.prod.js',
'webpack/vue.utils.js',
'webpack/webpack.microfrontend.js.jhi.vue',
],
}),
templates: ['rsbuild.module-federation.config.mjs', 'rsbuild.config.mjs.jhi.vue'],
},
{
condition: generator => generator.microfrontend,
...clientApplicationTemplatesBlock(),
Expand Down
Loading

0 comments on commit 45a35e6

Please sign in to comment.