From 8bf975ea1e0c8c4c0128bebae28aa48ce5d99c7c Mon Sep 17 00:00:00 2001 From: hexf00 Date: Sat, 23 Nov 2024 17:14:33 +0800 Subject: [PATCH] chore: add woker presets --- common/shared/prepare/index.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/common/shared/prepare/index.ts b/common/shared/prepare/index.ts index ea1285d..de72912 100644 --- a/common/shared/prepare/index.ts +++ b/common/shared/prepare/index.ts @@ -1,3 +1,4 @@ +import { execSync } from 'node:child_process'; import path from 'node:path'; import process from 'node:process'; import fs from 'fs-extra'; @@ -54,7 +55,27 @@ export function createLocalesFiles() { }); } +interface IPkg { + name: string; + path: string; + private: boolean; + hasWorker: boolean; +} + +function getWorkspacePkgs() { + const pkgs = JSON.parse(execSync('pnpm m ls --json').toString()) as IPkg[]; + const result: Record = {}; + + pkgs.filter(it => it.name.startsWith('@univerjs/preset-')).forEach((it) => { + it.hasWorker = fs.existsSync(path.join(it.path, 'src', 'web-worker.ts')); + result[it.name] = it; + }); + return result; +} + export function createPresetsFiles() { + const presetPkgs = getWorkspacePkgs(); + Object.keys(pkg.dependencies).forEach((key) => { if (key.startsWith('@univerjs/preset')) { const indexTs = `export * from '${key}';\n`; @@ -62,6 +83,13 @@ export function createPresetsFiles() { fs.ensureFileSync(__indexTs); fs.writeFileSync(__indexTs, indexTs); + if (presetPkgs[key].hasWorker) { + const workerTs = `export * from '${key}/web-worker';\n`; + const __workerTs = path.resolve(__dirname, 'src', `${key.replace('@univerjs/', '')}/web-worker.ts`); + fs.ensureFileSync(__workerTs); + fs.writeFileSync(__workerTs, workerTs); + } + LOCLAES_MAP.forEach((localeKey) => { const localeTs = `export { default } from '${key}/locales/${localeKey}';\n`; const __localeTs = path.resolve(__dirname, 'src', `${key.replace('@univerjs/', '')}/locales/${localeKey}.ts`);