mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
feat: split bot and server builds
This commit is contained in:
1 parent
dc1c49da6a
commit
d0f91df95b
2 files changed
+27
-54
No files matched your search
+2
-1
@@ -5,11 +5,12 @@
|
|||||||
"main": "src/server.ts",
|
"main": "src/server.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"build": "node scripts/build",
|
||||||
"build:bot": "node scripts/build --build=bot",
|
"build:bot": "node scripts/build --build=bot",
|
||||||
"build:server": "node scripts/build --build=server",
|
"build:server": "node scripts/build --build=server",
|
||||||
|
"build:website": "",
|
||||||
"build:docs": "vitepress build docs",
|
"build:docs": "vitepress build docs",
|
||||||
"build:ratingsleaderboard": "vite-node --script scripts/buildRatingsLeaderboard",
|
"build:ratingsleaderboard": "vite-node --script scripts/buildRatingsLeaderboard",
|
||||||
"build": "node scripts/build --build=all",
|
|
||||||
"dev:bot": "yarn build:bot --dev && yarn start:bot",
|
"dev:bot": "yarn build:bot --dev && yarn start:bot",
|
||||||
"dev:server": "yarn build:server --dev && yarn start:server",
|
"dev:server": "yarn build:server --dev && yarn start:server",
|
||||||
"dev:docs": "vitepress dev docs",
|
"dev:docs": "vitepress dev docs",
|
||||||
|
|||||||
+25
-53
@@ -1,63 +1,35 @@
|
|||||||
import { build } from 'esbuild';
|
import { build } from 'esbuild';
|
||||||
import { copyFile, mkdirSync, rmSync } from 'fs';
|
|
||||||
import { argv } from 'process';
|
import { argv } from 'process';
|
||||||
|
|
||||||
const isProd = !argv.includes('--dev');
|
const targetFile = argv
|
||||||
const buildAll = argv.includes('--build=all');
|
.find((arg) => arg.startsWith('--build='))
|
||||||
const buildBot = argv.includes('--build=bot') || buildAll;
|
?.split('=')[1];
|
||||||
const buildServer = argv.includes('--build=server') || buildAll;
|
const files = targetFile ? [targetFile] : ['bot', 'server'];
|
||||||
|
|
||||||
if (isProd) {
|
// copyFile('package.dist.json', 'dist/package.json', () =>
|
||||||
// only remove in production to ensure no time is wasted in dev
|
// console.log('package.json copied'),
|
||||||
console.log('Removing dist...');
|
// );
|
||||||
rmSync('dist', { recursive: true, force: true });
|
|
||||||
console.log('Dist removed');
|
|
||||||
|
|
||||||
console.log('Creating dist...');
|
files.forEach(async (file) => {
|
||||||
mkdirSync('dist');
|
console.log(`Building ${file}...`);
|
||||||
console.log('Dist created');
|
|
||||||
|
|
||||||
console.log('Copying package.json...');
|
await build({
|
||||||
copyFile('package.dist.json', 'dist/package.json', () =>
|
entryPoints: [`src/${file}.ts`],
|
||||||
console.log('package.json copied'),
|
outfile: `dist/${file}/index.cjs`,
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const commonOptions = {
|
platform: 'node',
|
||||||
platform: 'node',
|
loader: {
|
||||||
loader: {
|
'.node': 'copy',
|
||||||
'.node': 'copy',
|
'.ttf': 'file',
|
||||||
'.ttf': 'file',
|
},
|
||||||
},
|
format: 'cjs',
|
||||||
format: 'cjs',
|
|
||||||
|
|
||||||
bundle: true,
|
bundle: true,
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
minifyIdentifiers: false, // causes errors
|
minify: true,
|
||||||
minifySyntax: isProd,
|
|
||||||
minifyWhitespace: isProd,
|
|
||||||
|
|
||||||
logLevel: isProd ? 'info' : 'silent',
|
logLevel: 'info',
|
||||||
};
|
|
||||||
|
|
||||||
if (buildBot) {
|
|
||||||
console.log('Building bot...');
|
|
||||||
build({
|
|
||||||
...commonOptions,
|
|
||||||
|
|
||||||
entryPoints: ['src/bot.ts'],
|
|
||||||
outfile: 'dist/bot.cjs',
|
|
||||||
}).then(() => console.log('Bot built'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buildServer) {
|
|
||||||
console.log('Building server...');
|
|
||||||
build({
|
|
||||||
...commonOptions,
|
|
||||||
|
|
||||||
entryPoints: ['src/server.ts'],
|
|
||||||
outfile: 'dist/server.cjs',
|
|
||||||
}).then(() => {
|
|
||||||
console.log('Server built');
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
console.log(`Built ${file}`);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user