Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
export function getRepoRoot(cwd = process.cwd()): string {
|
||||
const candidates = [cwd, path.resolve(cwd, ".."), path.resolve(cwd, "../.."), path.resolve(cwd, "../../..")];
|
||||
const root = candidates.find(
|
||||
(candidate) => fs.existsSync(path.join(candidate, "package.json")) && fs.existsSync(path.join(candidate, "apps/web/app"))
|
||||
);
|
||||
|
||||
return root ?? cwd;
|
||||
}
|
||||
|
||||
export function resolveRepoPath(relativePath: string, cwd = process.cwd()): string {
|
||||
const repoRoot = getRepoRoot(cwd);
|
||||
const normalizedPath = relativePath.replaceAll("\\", "/");
|
||||
if (normalizedPath === "app" || normalizedPath.startsWith("app/") || normalizedPath === "public" || normalizedPath.startsWith("public/")) {
|
||||
throw new Error(`Use apps/web/${normalizedPath} instead of legacy root ${normalizedPath}`);
|
||||
}
|
||||
const candidates = [path.join(repoRoot, normalizedPath)];
|
||||
|
||||
return candidates.find((candidate) => fs.existsSync(candidate)) ?? candidates[0];
|
||||
}
|
||||
|
||||
export function repoPathExists(relativePath: string, cwd = process.cwd()): boolean {
|
||||
return fs.existsSync(resolveRepoPath(relativePath, cwd));
|
||||
}
|
||||
|
||||
export function readRepoFile(relativePath: string, cwd = process.cwd()): string {
|
||||
return fs.readFileSync(resolveRepoPath(relativePath, cwd), "utf8");
|
||||
}
|
||||
|
||||
export function readRepoDir(relativePath: string, cwd = process.cwd()): string[] {
|
||||
return fs.readdirSync(resolveRepoPath(relativePath, cwd));
|
||||
}
|
||||
Reference in new issue
Block a user