Skip to content

Commit

Permalink
chore: add woker presets
Browse files Browse the repository at this point in the history
  • Loading branch information
hexf00 committed Nov 23, 2024
1 parent 09181f6 commit 8bf975e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions common/shared/prepare/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -54,14 +55,41 @@ 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<string, IPkg> = {};

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`;
const __indexTs = path.resolve(__dirname, 'src', `${key.replace('@univerjs/', '')}/index.ts`);
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`);
Expand Down

0 comments on commit 8bf975e

Please sign in to comment.