Skip to content

Commit 5559947

Browse files
author
abrulic
committed
fix?
1 parent 7017599 commit 5559947

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

docs/scripts/generate-docs.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type ExecSyncOptions, execSync } from "node:child_process";
22
import { cpSync, existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
33
import os from "node:os";
4-
import { join, resolve, posix as pathPosix } from "node:path";
4+
import path, { join, resolve, posix as pathPosix } from "node:path";
55
import { parseArgs } from "node:util";
66
import chalk from "chalk";
77
import semver from "semver";
@@ -41,8 +41,7 @@ try {
4141
}
4242

4343
const repoPath = (...segs: string[]) =>
44-
pathPosix.join(...segs.filter(Boolean).map(s => s.replace(/^\/+|\/+$/g, "")));
45-
44+
path.normalize(path.join(...segs.filter(Boolean)));
4645

4746
const allTags = () => run("git tag --list").split("\n").filter(Boolean);
4847

@@ -70,13 +69,14 @@ function hasLocalRef(ref: string) {
7069
try { run(`git show-ref --verify --quiet ${ref}`); return true; } catch { return false; }
7170
}
7271

72+
const REPO_ROOT = run("git rev-parse --show-toplevel", { cwd: currentDocsWorkspace });
73+
7374
function refHasPath(ref: string, pathFromRepoRoot: string): boolean {
75+
const p = pathFromRepoRoot.replace(/^\/+/, "").replace(/\/+$/, "");
7476
try {
75-
const out = run(`git ls-tree -r --name-only ${ref} -- "${pathFromRepoRoot}"`);
76-
return out.trim().length > 0;
77-
} catch {
78-
return false;
79-
}
77+
run(`git -C "${REPO_ROOT}" rev-parse --verify --quiet "${ref}:${p}"`);
78+
return true;
79+
} catch { return false; }
8080
}
8181

8282
function buildDocs(sourceDir: string, outDir: string) {
@@ -211,11 +211,11 @@ function isPullRequestCI() {
211211
builtVersions = [...tags];
212212
} else {
213213
// Fallback: build default branch (useful if you want a "main" channel)
214-
const checkPath = repoPath(docsRelative, contentDir); // e.g. "docs/content"
215-
run(`git fetch --prune origin ${defaultBranch}`, { cwd: currentDocsWorkspace, inherit: true });
216-
const hasOnDefault = refHasPath(`origin/${defaultBranch}`, checkPath);
214+
const checkPath = repoPath(docsRelative, contentDir); // "docs/content"
215+
run(`git fetch --prune origin ${defaultBranch}`, { cwd: currentDocsWorkspace, inherit: true });
217216

218-
if (!hasOnDefault) {
217+
const hasOnDefault = refHasPath(`origin/${defaultBranch}`, checkPath);
218+
if (!hasOnDefault) {
219219
throw new Error(`Default branch 'origin/${defaultBranch}' has no '${checkPath}'. Pass --versions to build tags.`);
220220
}
221221
console.log(chalk.cyan(`(ci) Building docs from '${defaultBranch}' → ${defaultBranch}`));
@@ -237,4 +237,4 @@ export const versions = ${JSON.stringify(builtVersions, null, 2)} as const
237237
})().catch((e) => {
238238
console.error(chalk.red("❌ Build failed:"), e);
239239
process.exit(1);
240-
});
240+
});

0 commit comments

Comments
 (0)