-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbundle.js
More file actions
91 lines (77 loc) · 2.76 KB
/
bundle.js
File metadata and controls
91 lines (77 loc) · 2.76 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
/*
* This file is part of Jen.js.
* Copyright (C) 2026 oopsio
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import esbuild from "esbuild";
import { fileURLToPath, pathToFileURL } from "node:url";
import { dirname, join } from "node:path";
import { readdirSync, statSync } from "node:fs";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
function walkDir(dir, ext = ".ts") {
const files = [];
const entries = readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = join(dir, entry.name);
if (entry.isDirectory()) {
files.push(...walkDir(fullPath, ext));
} else if (entry.name.endsWith(ext)) {
files.push(fullPath);
}
}
return files;
}
async function bundleFramework() {
console.log("[BUNDLE] Starting framework bundle...");
// Get all TypeScript files from src/
const srcFiles = walkDir(join(__dirname, "src"), ".ts").concat(
walkDir(join(__dirname, "src"), ".tsx"),
);
// Add root TypeScript files
const rootFiles = [
join(__dirname, "build.ts"),
join(__dirname, "server.ts"),
join(__dirname, "jen.config.ts"),
];
const allEntryPoints = [...srcFiles, ...rootFiles];
console.log(`[BUNDLE] Found ${allEntryPoints.length} TypeScript files`);
console.log(`[BUNDLE] Transpiling to build/src with folder structure...`);
try {
const result = await esbuild.build({
entryPoints: allEntryPoints,
outdir: join(__dirname, "build"),
outbase: __dirname,
format: "esm",
platform: "node",
target: "es2022",
bundle: false,
logLevel: "info",
});
console.log("[BUNDLE] ✅ Framework bundled successfully");
console.log(`[BUNDLE] Output: build/`);
console.log("[BUNDLE] Structure:");
console.log(" build/src/ - All framework modules (6+ depth)");
console.log(" build/build.js - Build entry point");
console.log(" build/server.js - Server entry point");
console.log(" build/jen.config.js - Framework config");
return result;
} catch (err) {
console.error("[BUNDLE] ❌ Bundle failed:", err);
process.exit(1);
}
}
// Run bundler
await bundleFramework();