Skip to content

Commit 4a0aa67

Browse files
committed
Stage terrariumctl into fresh checkouts
1 parent 8b9e4b9 commit 4a0aa67

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

scripts/terrarium-install.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { $ } from "bun";
22
import { confirm, input, select } from "@inquirer/prompts";
33
import type { CAC } from "cac";
44
import chalk from "chalk";
5-
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5+
import { copyFileSync, cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
66
import { join } from "node:path";
77
import { tmpdir } from "node:os";
88
import { stringify } from "yaml";
@@ -138,6 +138,15 @@ function syncBundleArtifacts(bundleDir: string, repoDir: string): void {
138138
cpSync(sourceDir, join(repoDir, "dist"), { recursive: true, force: true });
139139
}
140140

141+
function stageRunningBinary(repoDir: string): void {
142+
if (!process.execPath || !existsSync(process.execPath)) {
143+
return;
144+
}
145+
const targetDir = join(repoDir, "dist");
146+
mkdirSync(targetDir, { recursive: true });
147+
copyFileSync(process.execPath, join(targetDir, "terrariumctl"));
148+
}
149+
141150
function localSourcePath(repoUrl: string): string {
142151
if (repoUrl.startsWith("file://")) {
143152
return repoUrl.slice("file://".length);
@@ -177,6 +186,9 @@ async function prepareRepo(ref: string): Promise<void> {
177186
}
178187

179188
syncBundleArtifacts(BUNDLE_DIR, REPO_DIR);
189+
if (!existsSync(join(REPO_DIR, "dist", "terrariumctl"))) {
190+
stageRunningBinary(REPO_DIR);
191+
}
180192
if (!existsSync(join(REPO_DIR, "dist", "terrariumctl"))) {
181193
fail("compiled Terrarium binaries are missing from the repository checkout");
182194
}

0 commit comments

Comments
 (0)