Skip to content
This repository was archived by the owner on Jan 25, 2026. It is now read-only.

Commit 8e0c0c1

Browse files
committed
Add documentation
1 parent 2a5e79d commit 8e0c0c1

File tree

16 files changed

+655
-13
lines changed

16 files changed

+655
-13
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
thirdparty/* linguist-vendored
1+
thirdparty/* linguist-vendored
2+
./docs/build.ts linguist-generated

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
# Qun
2+
13
build
24
release/resources
35
.cache
46
vcpkg_installed
57

8+
# Release Assets
9+
610
release/*
711
!release/shaders
812

docs/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
out
4+
bun.lock
5+
package-lock.json

docs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# docs
2+
3+
This is the documentation frontend for qun

docs/build.ts

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
#!/usr/bin/env bun
2+
import { build, type BuildConfig } from "bun";
3+
import plugin from "bun-plugin-tailwind";
4+
import { existsSync } from "fs";
5+
import { rm } from "fs/promises";
6+
import path from "path";
7+
8+
// Print help text if requested
9+
if (process.argv.includes("--help") || process.argv.includes("-h")) {
10+
console.log(`
11+
🏗️ Bun Build Script
12+
13+
Usage: bun run build.ts [options]
14+
15+
Common Options:
16+
--outdir <path> Output directory (default: "dist")
17+
--minify Enable minification (or --minify.whitespace, --minify.syntax, etc)
18+
--source-map <type> Sourcemap type: none|linked|inline|external
19+
--target <target> Build target: browser|bun|node
20+
--format <format> Output format: esm|cjs|iife
21+
--splitting Enable code splitting
22+
--packages <type> Package handling: bundle|external
23+
--public-path <path> Public path for assets
24+
--env <mode> Environment handling: inline|disable|prefix*
25+
--conditions <list> Package.json export conditions (comma separated)
26+
--external <list> External packages (comma separated)
27+
--banner <text> Add banner text to output
28+
--footer <text> Add footer text to output
29+
--define <obj> Define global constants (e.g. --define.VERSION=1.0.0)
30+
--help, -h Show this help message
31+
32+
Example:
33+
bun run build.ts --outdir=dist --minify --source-map=linked --external=react,react-dom
34+
`);
35+
process.exit(0);
36+
}
37+
38+
// Helper function to convert kebab-case to camelCase
39+
const toCamelCase = (str: string): string => {
40+
return str.replace(/-([a-z])/g, g => g[1].toUpperCase());
41+
};
42+
43+
// Helper function to parse a value into appropriate type
44+
const parseValue = (value: string): any => {
45+
// Handle true/false strings
46+
if (value === "true") return true;
47+
if (value === "false") return false;
48+
49+
// Handle numbers
50+
if (/^\d+$/.test(value)) return parseInt(value, 10);
51+
if (/^\d*\.\d+$/.test(value)) return parseFloat(value);
52+
53+
// Handle arrays (comma-separated)
54+
if (value.includes(",")) return value.split(",").map(v => v.trim());
55+
56+
// Default to string
57+
return value;
58+
};
59+
60+
// Magical argument parser that converts CLI args to BuildConfig
61+
function parseArgs(): Partial<BuildConfig> {
62+
const config: Record<string, any> = {};
63+
const args = process.argv.slice(2);
64+
65+
for (let i = 0; i < args.length; i++) {
66+
const arg = args[i];
67+
if (!arg.startsWith("--")) continue;
68+
69+
// Handle --no-* flags
70+
if (arg.startsWith("--no-")) {
71+
const key = toCamelCase(arg.slice(5));
72+
config[key] = false;
73+
continue;
74+
}
75+
76+
// Handle --flag (boolean true)
77+
if (!arg.includes("=") && (i === args.length - 1 || args[i + 1].startsWith("--"))) {
78+
const key = toCamelCase(arg.slice(2));
79+
config[key] = true;
80+
continue;
81+
}
82+
83+
// Handle --key=value or --key value
84+
let key: string;
85+
let value: string;
86+
87+
if (arg.includes("=")) {
88+
[key, value] = arg.slice(2).split("=", 2);
89+
} else {
90+
key = arg.slice(2);
91+
value = args[++i];
92+
}
93+
94+
// Convert kebab-case key to camelCase
95+
key = toCamelCase(key);
96+
97+
// Handle nested properties (e.g. --minify.whitespace)
98+
if (key.includes(".")) {
99+
const [parentKey, childKey] = key.split(".");
100+
config[parentKey] = config[parentKey] || {};
101+
config[parentKey][childKey] = parseValue(value);
102+
} else {
103+
config[key] = parseValue(value);
104+
}
105+
}
106+
107+
return config as Partial<BuildConfig>;
108+
}
109+
110+
// Helper function to format file sizes
111+
const formatFileSize = (bytes: number): string => {
112+
const units = ["B", "KB", "MB", "GB"];
113+
let size = bytes;
114+
let unitIndex = 0;
115+
116+
while (size >= 1024 && unitIndex < units.length - 1) {
117+
size /= 1024;
118+
unitIndex++;
119+
}
120+
121+
return `${size.toFixed(2)} ${units[unitIndex]}`;
122+
};
123+
124+
console.log("\n🚀 Starting build process...\n");
125+
126+
// Parse CLI arguments with our magical parser
127+
const cliConfig = parseArgs();
128+
const outdir = cliConfig.outdir || path.join(process.cwd(), "dist");
129+
130+
if (existsSync(outdir)) {
131+
console.log(`🗑️ Cleaning previous build at ${outdir}`);
132+
await rm(outdir, { recursive: true, force: true });
133+
}
134+
135+
const start = performance.now();
136+
137+
// Scan for all HTML files in the project
138+
const entrypoints = [...new Bun.Glob("**.html").scanSync("src")]
139+
.map(a => path.resolve("src", a))
140+
.filter(dir => !dir.includes("node_modules"));
141+
console.log(`📄 Found ${entrypoints.length} HTML ${entrypoints.length === 1 ? "file" : "files"} to process\n`);
142+
143+
// Build all the HTML files
144+
const result = await build({
145+
entrypoints,
146+
outdir,
147+
plugins: [plugin],
148+
minify: true,
149+
target: "browser",
150+
sourcemap: "linked",
151+
define: {
152+
"process.env.NODE_ENV": JSON.stringify("production"),
153+
},
154+
...cliConfig, // Merge in any CLI-provided options
155+
});
156+
157+
// Print the results
158+
const end = performance.now();
159+
160+
const outputTable = result.outputs.map(output => ({
161+
"File": path.relative(process.cwd(), output.path),
162+
"Type": output.kind,
163+
"Size": formatFileSize(output.size),
164+
}));
165+
166+
console.table(outputTable);
167+
const buildTime = (end - start).toFixed(2);
168+
169+
console.log(`\n✅ Build completed in ${buildTime}ms\n`);

docs/bun.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module "*.png" {
2+
const value: string;
3+
export default value;
4+
}

docs/bunfig.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
[serve.static]
3+
plugins = ["bun-plugin-tailwind"]
4+
env = "BUN_PUBLIC_*"

docs/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "bun-react-template",
3+
"version": "0.1.0",
4+
"private": true,
5+
"type": "module",
6+
"main": "src/index.tsx",
7+
"module": "src/index.tsx",
8+
"scripts": {
9+
"dev": "bun --hot src/index.tsx",
10+
"start": "NODE_ENV=production bun src/index.tsx",
11+
"build": "bun run build.ts"
12+
},
13+
"dependencies": {
14+
"bun-plugin-tailwind": "^0.0.14",
15+
"highlight.js": "^11.11.1",
16+
"react": "^19",
17+
"react-dom": "^19",
18+
"react-icons": "^5.5.0",
19+
"tailwindcss": "^4.0.6"
20+
},
21+
"devDependencies": {
22+
"@types/react": "^19",
23+
"@types/react-dom": "^19",
24+
"@types/bun": "latest"
25+
}
26+
}

docs/src/ecs.png

100 KB
Loading

0 commit comments

Comments
 (0)