Implement ChessUp server, vanilla TS UI, Stockfish analytics, and Docker/Cloudflared setup
This commit is contained in:
commit
e2e085b341
52 changed files with 15730 additions and 0 deletions
112
build.mjs
Normal file
112
build.mjs
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import esbuild from 'esbuild';
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
const watch = args.includes('--watch');
|
||||
const buildTests = args.includes('--tests');
|
||||
|
||||
const rootDir = process.cwd();
|
||||
const distPublicDir = path.join(rootDir, 'dist', 'public');
|
||||
const distServerDir = path.join(rootDir, 'dist', 'server');
|
||||
const distTestsDir = path.join(rootDir, 'dist', 'tests');
|
||||
|
||||
function copyHtml() {
|
||||
fs.mkdirSync(distPublicDir, { recursive: true });
|
||||
const srcHtml = path.join(rootDir, 'src', 'client', 'index.html');
|
||||
const destHtml = path.join(distPublicDir, 'index.html');
|
||||
if (fs.existsSync(srcHtml)) {
|
||||
fs.copyFileSync(srcHtml, destHtml);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
fs.mkdirSync(distPublicDir, { recursive: true });
|
||||
fs.mkdirSync(distServerDir, { recursive: true });
|
||||
|
||||
const serverOptions = {
|
||||
entryPoints: [path.join(rootDir, 'src', 'server', 'index.ts')],
|
||||
outfile: path.join(distServerDir, 'index.js'),
|
||||
bundle: true,
|
||||
platform: 'node',
|
||||
format: 'cjs',
|
||||
target: 'node22',
|
||||
packages: 'external',
|
||||
sourcemap: true,
|
||||
logLevel: 'info'
|
||||
};
|
||||
|
||||
const clientOptions = {
|
||||
entryPoints: [path.join(rootDir, 'src', 'client', 'main.ts')],
|
||||
outfile: path.join(distPublicDir, 'app.js'),
|
||||
bundle: true,
|
||||
platform: 'browser',
|
||||
format: 'iife',
|
||||
target: ['es2017', 'safari12', 'chrome60'],
|
||||
minify: !watch,
|
||||
sourcemap: watch,
|
||||
logLevel: 'info'
|
||||
};
|
||||
|
||||
const cssOptions = {
|
||||
entryPoints: [path.join(rootDir, 'src', 'client', 'styles.css')],
|
||||
outfile: path.join(distPublicDir, 'styles.css'),
|
||||
bundle: true,
|
||||
target: ['safari12', 'chrome60'],
|
||||
minify: !watch,
|
||||
logLevel: 'info'
|
||||
};
|
||||
|
||||
if (watch) {
|
||||
copyHtml();
|
||||
const contexts = await Promise.all([
|
||||
esbuild.context(serverOptions),
|
||||
esbuild.context(clientOptions),
|
||||
esbuild.context(cssOptions)
|
||||
]);
|
||||
await Promise.all(contexts.map((ctx) => ctx.watch()));
|
||||
const htmlPath = path.join(rootDir, 'src', 'client', 'index.html');
|
||||
fs.watchFile(htmlPath, { interval: 500 }, () => {
|
||||
copyHtml();
|
||||
console.log('[build] Copied index.html');
|
||||
});
|
||||
console.log('[build] Watching for changes...');
|
||||
return;
|
||||
}
|
||||
|
||||
copyHtml();
|
||||
await Promise.all([
|
||||
esbuild.build(serverOptions),
|
||||
esbuild.build(clientOptions),
|
||||
esbuild.build(cssOptions)
|
||||
]);
|
||||
|
||||
if (buildTests) {
|
||||
const testsDir = path.join(rootDir, 'tests');
|
||||
if (fs.existsSync(testsDir)) {
|
||||
const testFiles = fs
|
||||
.readdirSync(testsDir)
|
||||
.filter((f) => f.endsWith('.test.ts'))
|
||||
.map((f) => path.join(testsDir, f));
|
||||
if (testFiles.length > 0) {
|
||||
fs.mkdirSync(distTestsDir, { recursive: true });
|
||||
await esbuild.build({
|
||||
entryPoints: testFiles,
|
||||
outdir: distTestsDir,
|
||||
bundle: true,
|
||||
platform: 'node',
|
||||
format: 'cjs',
|
||||
target: 'node22',
|
||||
packages: 'external',
|
||||
sourcemap: true,
|
||||
logLevel: 'info'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue