UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

1 lines 1.94 kB
{"version":3,"file":"snapshot.mjs","names":[],"sources":["../../src/cli/snapshot.ts"],"sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\nexport interface SyncSnapshot {\n parentRef: string;\n timestamp: string;\n files: Record<string, string>;\n}\n\nconst SNAPSHOT_DIR = \".bos\";\nconst SNAPSHOT_FILE = \"sync-snapshot.json\";\n\nfunction snapshotPath(projectDir: string): string {\n return join(projectDir, SNAPSHOT_DIR, SNAPSHOT_FILE);\n}\n\nexport async function readSnapshot(projectDir: string): Promise<SyncSnapshot | null> {\n const path = snapshotPath(projectDir);\n if (!existsSync(path)) {\n return null;\n }\n try {\n const content = readFileSync(path, \"utf-8\");\n return JSON.parse(content) as SyncSnapshot;\n } catch {\n return null;\n }\n}\n\nexport async function writeSnapshot(\n projectDir: string,\n data: { parentRef: string; files: Record<string, string> },\n): Promise<void> {\n const dir = join(projectDir, SNAPSHOT_DIR);\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n\n const snapshot: SyncSnapshot = {\n parentRef: data.parentRef,\n timestamp: new Date().toISOString(),\n files: data.files,\n };\n\n writeFileSync(snapshotPath(projectDir), `${JSON.stringify(snapshot, null, 2)}\\n`);\n}\n"],"mappings":";;;;AASA,MAAM,eAAe;AACrB,MAAM,gBAAgB;AAEtB,SAAS,aAAa,YAA4B;CAChD,OAAO,KAAK,YAAY,cAAc,aAAa;AACrD;AAEA,eAAsB,aAAa,YAAkD;CACnF,MAAM,OAAO,aAAa,UAAU;CACpC,IAAI,CAAC,WAAW,IAAI,GAClB,OAAO;CAET,IAAI;EACF,MAAM,UAAU,aAAa,MAAM,OAAO;EAC1C,OAAO,KAAK,MAAM,OAAO;CAC3B,QAAQ;EACN,OAAO;CACT;AACF;AAEA,eAAsB,cACpB,YACA,MACe;CACf,MAAM,MAAM,KAAK,YAAY,YAAY;CACzC,IAAI,CAAC,WAAW,GAAG,GACjB,UAAU,KAAK,EAAE,WAAW,KAAK,CAAC;CAGpC,MAAM,WAAyB;EAC7B,WAAW,KAAK;EAChB,4BAAW,IAAI,KAAK,EAAC,CAAC,YAAY;EAClC,OAAO,KAAK;CACd;CAEA,cAAc,aAAa,UAAU,GAAG,GAAG,KAAK,UAAU,UAAU,MAAM,CAAC,EAAE,GAAG;AAClF"}