2024-11-26 21:03:01 -06:00
|
|
|
import { build } from 'esbuild';
|
2024-11-27 19:59:53 -06:00
|
|
|
import { cp, readdir, rm } from 'fs/promises';
|
2024-11-26 21:03:01 -06:00
|
|
|
|
2024-11-27 19:59:53 -06:00
|
|
|
const srcRoot = '../bot';
|
|
|
|
|
const distRoot = '../../dist/bot';
|
|
|
|
|
const modulesRoot = '../../node_modules';
|
|
|
|
|
const workers = await readdir(`${srcRoot}/src/workers`);
|
|
|
|
|
|
|
|
|
|
await rm(distRoot, { recursive: true, force: true });
|
2024-11-26 21:03:01 -06:00
|
|
|
|
|
|
|
|
build({
|
|
|
|
|
entryPoints: [
|
2024-11-27 19:59:53 -06:00
|
|
|
`${srcRoot}/src/main.ts`,
|
|
|
|
|
...workers.map((worker) => `${srcRoot}/src/workers/${worker}`),
|
2024-11-26 21:03:01 -06:00
|
|
|
],
|
|
|
|
|
bundle: true,
|
|
|
|
|
outdir: '../../dist/bot',
|
|
|
|
|
platform: 'node',
|
|
|
|
|
format: 'esm',
|
|
|
|
|
loader: {
|
|
|
|
|
'.ttf': 'file',
|
2024-11-27 19:59:53 -06:00
|
|
|
'.node': 'empty',
|
2024-11-26 21:03:01 -06:00
|
|
|
},
|
|
|
|
|
minify: true,
|
|
|
|
|
sourcemap: true,
|
|
|
|
|
});
|
2024-11-27 19:59:53 -06:00
|
|
|
|
|
|
|
|
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}`,
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}),
|
|
|
|
|
);
|