Skip to content

Commit f736e0d

Browse files
committed
Refactor HTML bundling
1 parent d9375e0 commit f736e0d

2 files changed

Lines changed: 28 additions & 18 deletions

File tree

tasks/bundle-html.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,31 @@ async function writeEntry({path, title, hasLoader, hasStyleSheet, hasCompatibili
9292
await writeFile(d, html(platform, title, hasLoader, hasStyleSheet, hasCompatibilityCheck));
9393
}
9494

95-
async function bundleHTML({platforms, debug}) {
96-
const promises = [];
97-
const enabledPlatforms = Object.values(PLATFORM).filter((platform) => platform !== PLATFORM.API && platforms[platform]);
98-
for (const entry of htmlEntries) {
99-
if (entry.platforms && !entry.platforms.some((platform) => platforms[platform])) {
100-
continue;
101-
}
102-
for (const platform of enabledPlatforms) {
103-
if (entry.platforms === undefined || entry.platforms.includes(platform)) {
104-
promises.push(writeEntry(entry, {debug, platform}));
95+
/**
96+
* @param {HTMLEntry[]} htmlEntries
97+
* @returns {ReturnType<typeof createTask>}
98+
*/
99+
export function createBundleHTMLTask(htmlEntries) {
100+
const bundleHTML = async ({platforms, debug}) => {
101+
const promises = [];
102+
const enabledPlatforms = Object.values(PLATFORM).filter((platform) => platform !== PLATFORM.API && platforms[platform]);
103+
for (const entry of htmlEntries) {
104+
if (entry.platforms && !entry.platforms.some((platform) => platforms[platform])) {
105+
continue;
106+
}
107+
for (const platform of enabledPlatforms) {
108+
if (entry.platforms === undefined || entry.platforms.includes(platform)) {
109+
promises.push(writeEntry(entry, {debug, platform}));
110+
}
105111
}
106112
}
107-
}
108-
await Promise.all(promises);
109-
}
113+
await Promise.all(promises);
114+
};
110115

111-
const bundleHTMLTask = createTask(
112-
'bundle-html',
113-
bundleHTML,
114-
);
116+
return createTask(
117+
'bundle-html',
118+
bundleHTML,
119+
);
120+
}
115121

116-
export default bundleHTMLTask;
122+
export default createBundleHTMLTask(htmlEntries);

tasks/bundle-js.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ async function bundleJS(/** @type {JSEntry} */entry, platform, debug, watch, log
198198
});
199199
}
200200

201+
/**
202+
* @param {JSEntry[]} jsEntries
203+
* @returns {ReturnType<typeof createTask>}
204+
*/
201205
export function createBundleJSTask(jsEntries) {
202206
/** @type {string[]} */
203207
let currentWatchFiles;

0 commit comments

Comments
 (0)