-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
91 lines (83 loc) · 2.5 KB
/
Copy pathbuild.js
File metadata and controls
91 lines (83 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env node
/**
* Codex Dashboard build script.
*
* Concatenates JS source files in dependency order, then runs esbuild
* for minification + source map generation. This preserves the global
* scope semantics (all functions remain on window) while producing a
* single optimised bundle.
*
* Usage:
* node build.js # one-shot build
* node build.js --watch # rebuild on file change
*/
const fs = require('fs');
const path = require('path');
const { execFileSync } = require('child_process');
const { buildSync } = require('esbuild');
const STATIC = path.join(__dirname, 'static');
// Dependency order — app.js first (core), charts.js second (helpers),
// then domain modules in any order.
const SOURCE_FILES = [
'app.js',
'charts.js',
'sessions.js',
'overview.js',
'plan.js',
'subagents.js',
'timeline.js',
];
const BANNER = '/* Codex Dashboard bundle — generated by build.js */\n';
const OUT_FILE = path.join(STATIC, 'bundle.js');
const CONCAT_TMP = path.join(STATIC, '.bundle-src.tmp.js');
function concatenate() {
let src = BANNER;
for (const f of SOURCE_FILES) {
const content = fs.readFileSync(path.join(STATIC, f), 'utf8');
src += `\n// ═══ ${f} ═══\n${content}\n`;
}
fs.writeFileSync(CONCAT_TMP, src);
return CONCAT_TMP;
}
const CSS_IN = path.join(STATIC, 'app.css');
const CSS_OUT = path.join(STATIC, 'tailwind.css');
function buildCSS() {
execFileSync(
'npx', ['tailwindcss', '-i', CSS_IN, '-o', CSS_OUT, '--minify'],
{ stdio: 'inherit', cwd: __dirname }
);
const size = (fs.statSync(CSS_OUT).size / 1024).toFixed(1);
console.log(`✓ ${CSS_OUT} (${size} KB)`);
}
function build() {
buildCSS();
const tmpFile = concatenate();
try {
buildSync({
entryPoints: [tmpFile],
outfile: OUT_FILE,
bundle: false, // already concatenated
minify: !process.argv.includes('--watch'),
sourcemap: true,
target: 'es2020',
charset: 'utf8',
logLevel: 'info',
});
const size = (fs.statSync(OUT_FILE).size / 1024).toFixed(1);
console.log(`✓ ${OUT_FILE} (${size} KB)`);
} finally {
try { fs.unlinkSync(tmpFile); } catch {}
}
}
if (process.argv.includes('--watch')) {
console.log('Watching for changes...');
build();
for (const f of SOURCE_FILES) {
fs.watchFile(path.join(STATIC, f), { interval: 500 }, () => {
console.log(`\n${f} changed — rebuilding...`);
try { build(); } catch (e) { console.error('Build error:', e.message); }
});
}
} else {
build();
}