chore: SDK 工程骨架(esbuild+vitest)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-15 11:30:42 +08:00
parent 2a7f08fd14
commit 8e2c91663e
8 changed files with 1246 additions and 0 deletions
+2
View File
@@ -7,3 +7,5 @@ server/.venv/
server/db.sqlite3
server/.cache/
server/tracker/data/*.xdb
sdk/node_modules/
sdk/dist/
+6
View File
@@ -0,0 +1,6 @@
import { build } from "esbuild";
await build({
entryPoints: ["src/index.ts"],
bundle: true, minify: true, format: "iife",
outfile: "dist/v1.js", target: ["es2018"],
});
+17
View File
@@ -0,0 +1,17 @@
{
"name": "ctk-sdk",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"build": "node build.mjs",
"test": "vitest run",
"checksize": "node build.mjs && gzip -c dist/v1.js | wc -c"
},
"devDependencies": {
"esbuild": "^0.24.0",
"happy-dom": "^15.0.0",
"typescript": "^5.6.0",
"vitest": "^2.1.0"
}
}
+1188
View File
File diff suppressed because it is too large Load Diff
+7
View File
@@ -0,0 +1,7 @@
export function uuid(): string {
if (globalThis.crypto?.randomUUID) return crypto.randomUUID();
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
});
}
+9
View File
@@ -0,0 +1,9 @@
import { describe, it, expect } from "vitest";
import { uuid } from "../src/util";
describe("uuid", () => {
it("生成 36 位且不重复", () => {
const a = uuid(), b = uuid();
expect(a).toMatch(/^[0-9a-f-]{36}$/);
expect(a).not.toBe(b);
});
});
+13
View File
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true
},
"include": ["src", "test"]
}
+4
View File
@@ -0,0 +1,4 @@
import { defineConfig } from "vitest/config";
export default defineConfig({
test: { environment: "happy-dom", setupFiles: [] },
});