feat: build bot completely

This commit is contained in:
tresabhi committed 2024-11-27 19:59:53 -06:00
1 parent ced3897696
commit c81f6d08c0
1 file changed
+27 -6
+27 -6
View File
@@ -1,13 +1,17 @@
import { build } from 'esbuild'; import { build } from 'esbuild';
import { readdir } from 'fs/promises'; import { cp, readdir, rm } from 'fs/promises';
const root = '../bot'; const srcRoot = '../bot';
const workers = await readdir(`${root}/src/workers`); const distRoot = '../../dist/bot';
const modulesRoot = '../../node_modules';
const workers = await readdir(`${srcRoot}/src/workers`);
await rm(distRoot, { recursive: true, force: true });
build({ build({
entryPoints: [ entryPoints: [
`${root}/src/main.ts`, `${srcRoot}/src/main.ts`,
...workers.map((worker) => `${root}/src/workers/${worker}`), ...workers.map((worker) => `${srcRoot}/src/workers/${worker}`),
], ],
bundle: true, bundle: true,
outdir: '../../dist/bot', outdir: '../../dist/bot',
@@ -15,8 +19,25 @@ build({
format: 'esm', format: 'esm',
loader: { loader: {
'.ttf': 'file', '.ttf': 'file',
'.node': 'file', '.node': 'empty',
}, },
minify: true, minify: true,
sourcemap: true, sourcemap: true,
}); });
await Promise.all(
(await readdir(`${modulesRoot}/@resvg`)).map(async (module) => {
const files = await readdir(`${modulesRoot}/@resvg/${module}`).then(
(files) => files.filter((file) => file.endsWith('.node')),
);
await Promise.all(
files.map(async (file) => {
await cp(
`${modulesRoot}/@resvg/${module}/${file}`,
`${distRoot}/workers/${file}`,
);
}),
);
}),
);