{"version":3,"file":"repo-context-BuA2JqPm.mjs","names":[],"sources":["../src/repo-context.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\"\nimport { createRepoSlug, getRepoIdentity, getRepoRoot, isGitRepo } from \"../../core/src/index.js\"\nimport { parseOptionalRepoFlag } from \"./config.js\"\nimport { getLatestRunPointerPath, getRepoArtifactsDir } from \"./paths.js\"\n\ninterface LatestRunPointer {\n\trepoSlug: string\n\trepoRoot: string\n}\n\nexport interface ResolvedRepoContext {\n\trepoRoot: string\n\trepoSlug: string\n\tartifactsDir: string\n\trest: string[]\n}\n\nexport function resolveRepoContext(argv: string[]): ResolvedRepoContext {\n\tconst { repo, rest } = parseOptionalRepoFlag(argv)\n\n\tif (repo) {\n\t\tconst repoRoot = getRepoRoot(repo)\n\t\tconst repoSlug = createRepoSlug(getRepoIdentity(repoRoot), repoRoot)\n\t\treturn {\n\t\t\trepoRoot,\n\t\t\trepoSlug,\n\t\t\tartifactsDir: getRepoArtifactsDir(repoSlug),\n\t\t\trest,\n\t\t}\n\t}\n\n\tconst cwd = process.cwd()\n\tconst repoRoot = getRepoRoot(cwd)\n\tconst repoSlug = createRepoSlug(getRepoIdentity(repoRoot), repoRoot)\n\tconst artifactsDir = getRepoArtifactsDir(repoSlug)\n\tif (isGitRepo(cwd) || existsSync(artifactsDir)) {\n\t\treturn {\n\t\t\trepoRoot,\n\t\t\trepoSlug,\n\t\t\tartifactsDir,\n\t\t\trest,\n\t\t}\n\t}\n\n\tconst latestPointerPath = getLatestRunPointerPath()\n\tif (!existsSync(latestPointerPath)) {\n\t\treturn {\n\t\t\trepoRoot,\n\t\t\trepoSlug,\n\t\t\tartifactsDir,\n\t\t\trest,\n\t\t}\n\t}\n\n\tconst latest = JSON.parse(readFileSync(latestPointerPath, \"utf-8\")) as LatestRunPointer\n\treturn {\n\t\trepoRoot: latest.repoRoot,\n\t\trepoSlug: latest.repoSlug,\n\t\tartifactsDir: getRepoArtifactsDir(latest.repoSlug),\n\t\trest,\n\t}\n}\n"],"mappings":";;;;AAiBA,SAAgB,mBAAmB,MAAqC;CACvE,MAAM,EAAE,MAAM,SAAS,sBAAsB,KAAK;AAElD,KAAI,MAAM;EACT,MAAM,WAAW,YAAY,KAAK;EAClC,MAAM,WAAW,eAAe,gBAAgB,SAAS,EAAE,SAAS;AACpE,SAAO;GACN;GACA;GACA,cAAc,oBAAoB,SAAS;GAC3C;GACA;;CAGF,MAAM,MAAM,QAAQ,KAAK;CACzB,MAAM,WAAW,YAAY,IAAI;CACjC,MAAM,WAAW,eAAe,gBAAgB,SAAS,EAAE,SAAS;CACpE,MAAM,eAAe,oBAAoB,SAAS;AAClD,KAAI,UAAU,IAAI,IAAI,WAAW,aAAa,CAC7C,QAAO;EACN;EACA;EACA;EACA;EACA;CAGF,MAAM,oBAAoB,yBAAyB;AACnD,KAAI,CAAC,WAAW,kBAAkB,CACjC,QAAO;EACN;EACA;EACA;EACA;EACA;CAGF,MAAM,SAAS,KAAK,MAAM,aAAa,mBAAmB,QAAQ,CAAC;AACnE,QAAO;EACN,UAAU,OAAO;EACjB,UAAU,OAAO;EACjB,cAAc,oBAAoB,OAAO,SAAS;EAClD;EACA"}