refactor(build-sdk): simplify SDK build process by removing minification logic
This commit is contained in:
+363
-1
File diff suppressed because one or more lines are too long
@@ -1,4 +1,4 @@
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { cp, mkdir } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
@@ -8,19 +8,7 @@ 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");
|
||||
await cp(source, target);
|
||||
|
||||
console.log(`sdk written to ${target}`);
|
||||
|
||||
Reference in New Issue
Block a user