Skip to content

Commit 2e30098

Browse files
committed
refactor: Cleanup code within scenarios
1 parent c0697ad commit 2e30098

2 files changed

Lines changed: 38 additions & 21 deletions

File tree

internal/npm-integration-poc/scenarios/03-webcomponents-integration.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
* Uses the custom rollup-plugin-ui5-webcomponents.js with metadata extraction
66
*/
77

8-
import {rollup} from "rollup";
9-
import {nodeResolve} from "@rollup/plugin-node-resolve";
10-
import commonjs from "@rollup/plugin-commonjs";
118
import {mkdir, writeFile} from "fs/promises";
129
import path from "path";
1310
import {fileURLToPath} from "url";
14-
import {printScenarioHeader} from "./shared-config.js";
11+
import {
12+
createRollupConfig,
13+
generateAMDBundleWithOutput,
14+
printScenarioHeader
15+
} from "./shared-config.js";
1516
import ui5WebComponentsPlugin from "../lib/plugins/rollup-plugin-ui5-webcomponents.js";
1617
import {DEFAULT_CONFIG, createPluginOptions} from "../lib/config/standalone-config.js";
1718
import {ThirdpartyGenerator} from "../lib/utils/thirdparty-generator.js";
@@ -27,23 +28,18 @@ async function bundleWebComponents() {
2728
const $metadata = {};
2829

2930
try {
30-
// Use shared configuration (DRY principle)
31+
// Create plugin with metadata collection
3132
const plugin = ui5WebComponentsPlugin(createPluginOptions(console, $metadata));
3233

33-
const bundle = await rollup({
34-
input: "@ui5/webcomponents/dist/MessageStrip.js",
35-
plugins: [
36-
nodeResolve({browser: true, preferBuiltins: false}),
37-
commonjs(),
38-
plugin
39-
],
40-
external: [/^sap\//]
41-
});
42-
43-
const {output} = await bundle.generate({
44-
format: "amd",
45-
amd: {define: "sap.ui.define"}
46-
});
34+
// Use shared configuration (DRY principle)
35+
const config = createRollupConfig(
36+
"@ui5/webcomponents/dist/MessageStrip.js",
37+
[plugin],
38+
{external: [/^sap\//]}
39+
);
40+
41+
// Generate bundle with full output (needed for chunks)
42+
const output = await generateAMDBundleWithOutput(config);
4743

4844
console.log("\n✅ Bundle generated successfully!\n");
4945

internal/npm-integration-poc/scenarios/shared-config.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
1818
*
1919
* @param input
2020
* @param extraPlugins
21+
* @param options Additional rollup options (e.g., external)
2122
*/
22-
export function createRollupConfig(input, extraPlugins = []) {
23+
export function createRollupConfig(input, extraPlugins = [], options = {}) {
2324
return {
2425
input,
2526
plugins: [
@@ -31,7 +32,8 @@ export function createRollupConfig(input, extraPlugins = []) {
3132
transformMixedEsModules: true
3233
}),
3334
...extraPlugins
34-
]
35+
],
36+
...options
3537
};
3638
}
3739

@@ -53,6 +55,25 @@ export async function generateAMDBundle(config) {
5355
return output[0].code;
5456
}
5557

58+
/**
59+
* Generate AMD bundle with full output (for multi-chunk scenarios)
60+
*
61+
* @param config
62+
* @returns {Promise<Array>} Full output array with all chunks
63+
*/
64+
export async function generateAMDBundleWithOutput(config) {
65+
const bundle = await rollup(config);
66+
67+
const {output} = await bundle.generate({
68+
format: "amd",
69+
amd: {
70+
define: "sap.ui.define"
71+
}
72+
});
73+
74+
return output;
75+
}
76+
5677
/**
5778
* Write output to scenario dist folder
5879
*

0 commit comments

Comments
 (0)