import * as Fs from "@std/fs"; import * as Path from "@std/path"; import type { Artifact } from "../common/types.d.ts"; import { diffuseVersion } from "../common/diffuse-version.ts"; import { execSync, utf8String } from "../common/index.ts"; import artifactsJson from "../artifacts/artifacts.json" with { type: "json" }; import versionsJson from "../artifacts/versions.json" with { type: "json" }; const artifacts: Record = artifactsJson as any; const versions: Record = versionsJson as any; //////////////////////////////////////////// // ESTABLISH VERSION //////////////////////////////////////////// let version = diffuseVersion(); console.log("🎵 Diffuse version:", version); //////////////////////////////////////////// // CHECK IF VERSION ALREADY EXISTS // Unless version ends with `-alpha` or `-beta` //////////////////////////////////////////// if ( versions[version] && !(version.endsWith("-alpha") || version.endsWith("-beta")) ) { console.log( "✅️ Version already present as artifact:", versions[version].cid, ); Deno.exit(); } //////////////////////////////////////////// // BUILD DIFFUSE //////////////////////////////////////////// Deno.chdir("diffuse"); execSync("rm", "-rf", ".env"); execSync("deno", "run", "build"); Deno.chdir(".."); const BUILD = Path.join("diffuse", "dist"); //////////////////////////////////////////// // TEMP DIR //////////////////////////////////////////// const TMP_DIR = Deno.makeTempDirSync(); const TMP_CAR = Path.join(TMP_DIR, "diffuse.car"); //////////////////////////////////////////// // MAKE CAR //////////////////////////////////////////// const carCmd = execSync( "deno", "run", "-A", "ipfs-car", "pack", BUILD, "--no-wrap", "--output", TMP_CAR, ); const cid = utf8String(carCmd.stdout).trim(); Deno.removeSync(TMP_DIR, { recursive: true }); if (!cid) throw new Error("CID result missing"); console.log("💎 Artifact CID:", cid); //////////////////////////////////////////// // CHECK IF ARTIFACT ALREADY EXISTS //////////////////////////////////////////// if (artifacts[cid]) { console.log( "✅️ Artifact already present as version:", artifacts[cid].version, ); Deno.exit(); } //////////////////////////////////////////// // ADD ARTIFACT //////////////////////////////////////////// Fs.copySync(BUILD, Path.join("artifacts", cid), { overwrite: true }); //////////////////////////////////////////// // ADD TO INDEXES //////////////////////////////////////////// const artifact: Artifact = { cid, createdAt: new Date().toISOString(), version, }; artifacts[cid] = artifact; versions[version] = artifact; Deno.writeTextFileSync( "artifacts/artifacts.json", JSON.stringify(artifacts, null, 2), ); Deno.writeTextFileSync( "artifacts/versions.json", JSON.stringify(versions, null, 2), );