Files
blitzkit/scripts/build.ts
T

61 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-03-29 16:33:13 -05:00
import { exec } from 'child_process';
2023-10-01 16:56:59 -05:00
import { build } from 'esbuild';
2023-10-16 20:44:47 -05:00
import { cp, readdir } from 'fs/promises';
2024-03-17 21:45:55 -05:00
import { argv } from 'process';
2024-03-29 16:45:17 -05:00
import { promisify } from 'util';
2024-03-17 21:45:55 -05:00
2024-03-29 16:45:17 -05:00
const execPromise = promisify(exec);
2024-03-29 16:33:13 -05:00
const isProduction = argv.includes('--production');
2023-10-01 16:56:59 -05:00
2024-03-29 16:45:17 -05:00
await readdir('src/workers').then((workers) => {
2023-10-16 20:44:47 -05:00
const files = [
'bot',
'index',
2023-10-16 20:08:08 -05:00
2023-10-16 20:44:47 -05:00
...workers.map((file) => `workers/${file.replace('.ts', '')}`),
];
2023-10-01 16:56:59 -05:00
2023-10-16 20:44:47 -05:00
build({
entryPoints: files.map((file) => `src/${file}.ts`),
outdir: 'dist/bot',
2023-10-01 16:56:59 -05:00
2023-10-16 20:44:47 -05:00
platform: 'node',
tsconfig: 'tsconfig.esbuild.json',
loader: {
'.node': 'copy',
'.ttf': 'file',
},
format: 'cjs',
jsx: 'transform',
outExtension: {
'.js': '.cjs',
},
2023-10-01 16:56:59 -05:00
2024-03-17 21:45:55 -05:00
external: ['sharp'],
2023-10-16 20:44:47 -05:00
bundle: true,
sourcemap: true,
2023-10-20 11:11:41 -05:00
minifyIdentifiers: false, // causes goofy errors
2023-10-16 20:44:47 -05:00
minifySyntax: true,
minifyWhitespace: true,
2023-10-01 16:56:59 -05:00
2023-10-16 20:44:47 -05:00
logLevel: 'info',
});
2023-10-01 16:56:59 -05:00
});
2023-10-16 20:44:47 -05:00
// copy schema.prisma
2024-03-29 16:45:17 -05:00
await cp('prisma/schema.prisma', 'dist/bot/schema.prisma');
await readdir('node_modules/prisma').then((files) =>
2023-10-16 20:44:47 -05:00
files
.filter((file) => file.endsWith('.node'))
.map((file) => cp(`node_modules/prisma/${file}`, `dist/bot/${file}`)),
);
2024-03-29 16:33:13 -05:00
if (isProduction) {
// install fixed sharp
console.log('Installing fixed sharp...');
2024-03-29 16:45:17 -05:00
await execPromise('yarn init -y && yarn add [email protected] --ignore-engines', {
2024-03-29 16:33:13 -05:00
cwd: 'dist/bot',
});
}
2024-03-29 16:42:56 -05:00
console.log('Generated:', await readdir('dist/bot'));