feat: add guarded Base Sepolia encore
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { access, readFile, rename } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
@@ -14,9 +14,33 @@ export async function selectManifest({ root = process.cwd(), network }) {
|
||||
return { source, active };
|
||||
}
|
||||
|
||||
export async function archiveManifest({ root = process.cwd(), network, now = new Date() }) {
|
||||
if (network !== "baseSepolia") throw new Error("only baseSepolia may be archived");
|
||||
const spec = networkSpec(network);
|
||||
const source = join(root, "deployments", spec.canonical);
|
||||
await readManifest(source);
|
||||
if (!(now instanceof Date) || Number.isNaN(now.valueOf())) throw new Error("archive timestamp is invalid");
|
||||
const timestamp = now.toISOString().replace(/[-:.]/g, "");
|
||||
if (!/^\d{8}T\d{9}Z$/.test(timestamp)) throw new Error("archive timestamp is invalid");
|
||||
const target = join(root, "deployments", `base-sepolia.${timestamp}.json`);
|
||||
try {
|
||||
await access(target);
|
||||
} catch (error) {
|
||||
if (error.code === "ENOENT") {
|
||||
await rename(source, target);
|
||||
return { source, path: target };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
throw new Error("refusing to overwrite an existing Base Sepolia archive");
|
||||
}
|
||||
|
||||
export async function runSelectCli(argv, { root = process.cwd(), log = console.log } = {}) {
|
||||
log(EDUCATIONAL_WARNING);
|
||||
if (argv.length !== 1) throw new Error("usage: select-manifest.mjs <anvil|baseSepolia>");
|
||||
if (argv.length === 2 && argv[0] === "archive" && argv[1] === "baseSepolia") {
|
||||
return archiveManifest({ root, network: argv[1] });
|
||||
}
|
||||
if (argv.length !== 1) throw new Error("usage: select-manifest.mjs <anvil|baseSepolia> | archive baseSepolia");
|
||||
return selectManifest({ root, network: argv[0] });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user