feat: add minified SDK build script and update widget script references

This commit is contained in:
mlogclub
2026-04-24 19:43:59 +08:00
parent 197631b4db
commit c945f1e73d
5 changed files with 394 additions and 3 deletions
+26
View File
@@ -0,0 +1,26 @@
import { mkdir, readFile, writeFile } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
const currentDir = path.dirname(fileURLToPath(import.meta.url));
const rootDir = path.resolve(currentDir, "..");
const source = path.join(rootDir, "lib", "sdk", "cs-ai-agent-sdk.js");
const targetDir = path.join(rootDir, "public", "sdk");
const target = path.join(targetDir, "cs-ai-agent-sdk.min.js");
function minifyJavaScript(sourceText) {
return sourceText
.replace(/\/\*[\s\S]*?\*\//g, "")
.replace(/(^|[^:])\/\/.*$/gm, "$1")
.replace(/\s+/g, " ")
.replace(/\s*([{}()[\];,:?=+\-*/<>|&])\s*/g, "$1")
.trim();
}
const sourceText = await readFile(source, "utf8");
const output = `${minifyJavaScript(sourceText)}\n`;
await mkdir(targetDir, { recursive: true });
await writeFile(target, output, "utf8");
console.log(`sdk written to ${target}`);