everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
33 lines (31 loc) • 1 kB
JavaScript
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
//#region src/cli/snapshot.ts
const SNAPSHOT_DIR = ".bos";
const SNAPSHOT_FILE = "sync-snapshot.json";
function snapshotPath(projectDir) {
return join(projectDir, SNAPSHOT_DIR, SNAPSHOT_FILE);
}
async function readSnapshot(projectDir) {
const path = snapshotPath(projectDir);
if (!existsSync(path)) return null;
try {
const content = readFileSync(path, "utf-8");
return JSON.parse(content);
} catch {
return null;
}
}
async function writeSnapshot(projectDir, data) {
const dir = join(projectDir, SNAPSHOT_DIR);
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
const snapshot = {
parentRef: data.parentRef,
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
files: data.files
};
writeFileSync(snapshotPath(projectDir), `${JSON.stringify(snapshot, null, 2)}\n`);
}
//#endregion
export { readSnapshot, writeSnapshot };
//# sourceMappingURL=snapshot.mjs.map