Skip to content

Commit 6c0e46c

Browse files
committed
Build website script refactoring
1 parent 0273d13 commit 6c0e46c

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

website/scripts/helpers.mjs

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

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-
9077
export async function buildAndCopyCoreJS(version, srcDir, cacheDir = null, checkout = false) {
78+
async function bundlePackage(esModules) {
79+
await exec(`npm run bundle-package${ esModules ? ' esmodules' : '' }`, { cwd: srcDir });
80+
const bundleName = `core-js-bundle${ esModules ? '-esmodules' : '' }.js`;
81+
const srcPath = join(srcDir, 'packages/core-js-bundle/minified.js');
82+
const destPath = join(srcDir, 'website/src/public/bundles/', target, bundleName);
83+
await cp(srcPath, destPath);
84+
if (cacheDir !== null) {
85+
const cachePath = join(cacheDir, target, bundleName);
86+
await cp(srcPath, cachePath);
87+
}
88+
}
89+
9190
const target = version.branch ?? version.tag;
92-
const name = version.path ?? version.label;
93-
const cache = cacheDir !== null;
9491
console.log(`Building and copying core-js for ${ target }`);
95-
const targetBundlePath = `${ cacheDir }/${ target }/`;
92+
const targetBundlePath = join(cacheDir ?? '', target);
9693

97-
if (cache && await isExists(targetBundlePath)) {
94+
if (cacheDir !== null && await isExists(targetBundlePath)) {
9895
console.time('Core JS bundles copied');
9996
const bundlePath = join(targetBundlePath, 'core-js-bundle.js');
100-
const destBundlePath = join(srcDir, 'website/src/public/bundles/', name, 'core-js-bundle.js');
97+
const destBundlePath = join(srcDir, 'website/src/public/bundles/', target, 'core-js-bundle.js');
10198
await cp(bundlePath, destBundlePath);
10299

103100
const esmodulesBundlePath = join(targetBundlePath, 'core-js-bundle-esmodules.js');
104-
const esmodulesDestBundlePath = join(srcDir, 'website/src/public/bundles/', name, 'core-js-bundle-esmodules.js');
101+
const esmodulesDestBundlePath = join(srcDir, 'website/src/public/bundles/', target, 'core-js-bundle-esmodules.js');
105102
await cp(esmodulesBundlePath, esmodulesDestBundlePath);
106103
console.timeEnd('Core JS bundles copied');
107104
return;
@@ -113,11 +110,8 @@ export async function buildAndCopyCoreJS(version, srcDir, cacheDir = null, check
113110
}
114111
await installDependencies(srcDir);
115112

116-
await bundlePackage(srcDir, name);
117-
await cacheBuild(srcDir, join(targetBundlePath, 'core-js-bundle.js'), cache);
118-
119-
await bundlePackage(srcDir, name, true);
120-
await cacheBuild(srcDir, join(targetBundlePath, 'core-js-bundle-esmodules.js'), cache);
113+
await bundlePackage(false);
114+
await bundlePackage(true);
121115

122116
console.timeEnd('Core JS bundles built');
123117
}

0 commit comments

Comments
 (0)