chore: SDK 工程骨架(esbuild+vitest)
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -7,3 +7,5 @@ server/.venv/
|
||||
server/db.sqlite3
|
||||
server/.cache/
|
||||
server/tracker/data/*.xdb
|
||||
sdk/node_modules/
|
||||
sdk/dist/
|
||||
|
||||
@@ -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"],
|
||||
});
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
Generated
+1188
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||
});
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2018",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["src", "test"]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { defineConfig } from "vitest/config";
|
||||
export default defineConfig({
|
||||
test: { environment: "happy-dom", setupFiles: [] },
|
||||
});
|
||||
Reference in New Issue
Block a user