Skip to content

Commit 699d587

Browse files
committed
Build script refactoring
1 parent fcb8391 commit 699d587

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

website/scripts/helpers.mjs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,34 @@ export async function copyCommonFiles(srcDir) {
7474
console.timeEnd('Copied common files');
7575
}
7676

77-
export async function buildAndCopyCoreJS(version, srcDir, cacheDir = '', checkout = false) {
77+
async function cacheBuild(srcDir, destPath, cache) {
78+
if (!cache) return;
79+
const bundlePath = join(srcDir, 'packages/core-js-bundle/minified.js');
80+
await cp(bundlePath, destPath);
81+
}
82+
83+
async function bundlePackage(srcDir, target, esModules = false) {
84+
await exec(`npm run bundle-package${ esModules ? ' esmodules' : '' }`, { cwd: srcDir });
85+
const bundlePath = join(srcDir, 'packages/core-js-bundle/minified.js');
86+
const destPath = join(srcDir, 'website/src/public/bundles/', target, `core-js-bundle${ esModules ? '-esmodules' : '' }.js`);
87+
await cp(bundlePath, destPath);
88+
}
89+
90+
export async function buildAndCopyCoreJS(version, srcDir, cacheDir = null, checkout = false) {
7891
const target = version.branch ?? version.tag;
7992
const name = version.path ?? version.label;
80-
const cache = cacheDir !== '';
93+
const cache = cacheDir !== null;
8194
console.log(`Building and copying core-js for ${ target }`);
8295
const targetBundlePath = `${ cacheDir }/${ target }/`;
8396

8497
if (cache && await isExists(targetBundlePath)) {
8598
console.time('Core JS bundles copied');
8699
const bundlePath = join(targetBundlePath, 'core-js-bundle.js');
87100
const destBundlePath = join(srcDir, 'website/src/public/bundles/', name, 'core-js-bundle.js');
101+
await cp(bundlePath, destBundlePath);
102+
88103
const esmodulesBundlePath = join(targetBundlePath, 'core-js-bundle-esmodules.js');
89104
const esmodulesDestBundlePath = join(srcDir, 'website/src/public/bundles/', name, 'core-js-bundle-esmodules.js');
90-
await cp(bundlePath, destBundlePath);
91105
await cp(esmodulesBundlePath, esmodulesDestBundlePath);
92106
console.timeEnd('Core JS bundles copied');
93107
return;
@@ -98,25 +112,12 @@ export async function buildAndCopyCoreJS(version, srcDir, cacheDir = '', checkou
98112
await checkoutVersion(version, srcDir);
99113
}
100114
await installDependencies(srcDir);
101-
await exec('npm run bundle-package', { cwd: srcDir });
102-
const bundlePath = join(srcDir, 'packages/core-js-bundle/minified.js');
103-
const destPath = join(srcDir, 'website/src/public/bundles/', name, 'core-js-bundle.js');
104-
await cp(bundlePath, destPath);
105-
106-
if (cache) {
107-
const cacheBundlePath = join(targetBundlePath, 'core-js-bundle.js');
108-
await cp(bundlePath, cacheBundlePath);
109-
}
110115

111-
await exec('npm run bundle-package esmodules', { cwd: srcDir });
112-
const esmodulesBundlePath = join(srcDir, 'packages/core-js-bundle/minified.js');
113-
const esmodulesDestBundlePath = join(srcDir, 'website/src/public/bundles/', name, 'core-js-bundle-esmodules.js');
114-
await cp(esmodulesBundlePath, esmodulesDestBundlePath);
116+
await bundlePackage(srcDir, name);
117+
await cacheBuild(srcDir, join(targetBundlePath, 'core-js-bundle.js'), cache);
115118

116-
if (cache) {
117-
const cacheEsmodulesBundlePath = join(targetBundlePath, 'core-js-bundle-esmodules.js');
118-
await cp(esmodulesBundlePath, cacheEsmodulesBundlePath);
119-
}
119+
await bundlePackage(srcDir, name, true);
120+
await cacheBuild(srcDir, join(targetBundlePath, 'core-js-bundle-esmodules.js'), cache);
120121

121122
console.timeEnd('Core JS bundles built');
122123
}

0 commit comments

Comments
 (0)