Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rm, mkdir, readdir } from "node:fs/promises";
import { rm, mkdir, cp } from "node:fs/promises";
import { join } from "node:path";

const DIST = "dist";
Expand All @@ -21,7 +21,7 @@ async function build() {
minify: true,
sourcemap: "external",
target: "browser",
external: ["/lib/*"],
external: ["/lib/*", "*/zerocms_tagger.js", "*/zerocms_tagger_bg.wasm"],
});

if (!result.success) {
Expand All @@ -31,12 +31,7 @@ async function build() {

// 3. Copy Static Libraries
console.log("📂 Copying libraries...");
const libs = await readdir("lib");
for (const lib of libs) {
const src = join("lib", lib);
const dest = join(DIST, "lib", lib);
await Bun.write(dest, Bun.file(src));
}
await cp("lib", join(DIST, "lib"), { recursive: true });

// Extract the generated hashed file name from Bun's output
const jsOutput = result.outputs.find(out => out.path.endsWith('.js'));
Expand Down
32 changes: 19 additions & 13 deletions serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,22 @@ const server = http.createServer((req, res) => {
}
});

server.listen(PORT, () => {
console.log(`\x1b[32m[ZeroCMS] Server running at http://localhost:${PORT}\x1b[0m`);
console.log(`\x1b[33mOpen http://localhost:${PORT} to start the CMS.\x1b[0m`);
if (CLIENT_ID === 'YOUR_CLIENT_ID') {
console.log(`\x1b[31m[!] GITHUB_CLIENT_ID is not configured. OAuth will not work.\x1b[0m`);
}
if (!APP_ID) {
console.log(`\x1b[33m[!] GITHUB_APP_ID not found. Organization support disabled.\x1b[0m`);
}
if (!PRIVATE_KEY) {
console.log(`\x1b[33m[!] GITHUB_PRIVATE_KEY not found. Organization support disabled.\x1b[0m`);
}
});
if (require.main === module) {
server.listen(PORT, () => {
console.log(`\x1b[32m[ZeroCMS] Server running at http://localhost:${PORT}\x1b[0m`);
console.log(`\x1b[33mOpen http://localhost:${PORT} to start the CMS.\x1b[0m`);
if (CLIENT_ID === 'YOUR_CLIENT_ID') {
console.log(`\x1b[31m[!] GITHUB_CLIENT_ID is not configured. OAuth will not work.\x1b[0m`);
}
if (!APP_ID) {
console.log(`\x1b[33m[!] GITHUB_APP_ID not found. Organization support disabled.\x1b[0m`);
}
if (!PRIVATE_KEY) {
console.log(`\x1b[33m[!] GITHUB_PRIVATE_KEY not found. Organization support disabled.\x1b[0m`);
}
});
}

if (typeof module !== 'undefined') {
module.exports.base64Url = base64Url;
}
30 changes: 30 additions & 0 deletions tests/serve.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { test, expect } = require("bun:test");
const { base64Url } = require("../serve.js");

test("base64Url handles standard string", () => {
expect(base64Url("hello world")).toBe("aGVsbG8gd29ybGQ");
});

test("base64Url handles empty string", () => {
expect(base64Url("")).toBe("");
});

test("base64Url replaces + with -", () => {
// String.fromCharCode(0, 190) creates a string whose standard base64 encoding contains '+'
// The standard base64 is AMK+
const input = String.fromCharCode(0, 190);
expect(base64Url(input)).toBe("AMK-");
});

test("base64Url replaces / with _", () => {
// String.fromCharCode(128, 63) creates a string whose standard base64 encoding contains '/'
// The standard base64 is woA/
const input = String.fromCharCode(128, 63);
expect(base64Url(input)).toBe("woA_");
});

test("base64Url removes =", () => {
// 'a' has standard base64 encoding 'YQ=='
// The two '=' should be removed
expect(base64Url("a")).toBe("YQ");
});