Skip to content

Commit 1b4b793

Browse files
author
abrulic
committed
old generate-docs
1 parent fffb212 commit 1b4b793

1 file changed

Lines changed: 7 additions & 57 deletions

File tree

scripts/generate-docs.ts

Lines changed: 7 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,6 @@ function resolveTagsFromSpec(spec: string) {
6363
return matched.sort(semver.rcompare)
6464
}
6565

66-
function hasLocalRef(ref: string) {
67-
try {
68-
run(`git show-ref --verify --quiet ${ref}`)
69-
return true
70-
} catch {
71-
return false
72-
}
73-
}
74-
7566
function buildDocs(sourceDir: string, outDir: string) {
7667
if (!existsSync(sourceDir)) {
7768
throw new Error(
@@ -152,16 +143,6 @@ function buildRef(ref: string, labelForOutDir: string) {
152143
}
153144
}
154145

155-
function buildBranch(branch: string, labelForOutDir: string) {
156-
run(`git fetch --tags --prune origin ${branch}`, {
157-
cwd: workspaceRoot,
158-
inherit: true,
159-
})
160-
const localRef = `refs/heads/${branch}`
161-
const targetRef = hasLocalRef(localRef) ? localRef : `origin/${branch}`
162-
return buildRef(targetRef, labelForOutDir)
163-
}
164-
165146
function buildTag(tag: string) {
166147
return buildRef(`refs/tags/${tag}`, tag)
167148
}
@@ -173,31 +154,6 @@ function getCurrentBranch(): string {
173154
throw new Error("Failed to get current branch")
174155
}
175156
}
176-
177-
function isOnDefaultBranch(defaultBranch: string): boolean {
178-
const currentBranch = getCurrentBranch()
179-
return currentBranch === defaultBranch
180-
}
181-
182-
/**
183-
* Build the current workspace snapshot labelled `labelForOutDir`.
184-
* If we're on the default branch, fetch and build that branch; otherwise
185-
* build the working tree in-place (useful for PR/feature branches).
186-
*/
187-
function buildCurrentSnapshot(defaultBranch: string, onDefaultBranch: boolean, labelForOutDir = "current") {
188-
if (onDefaultBranch) {
189-
// build from the remote/default branch so the snapshot exactly matches the
190-
// default branch state (not the local working tree)
191-
// biome-ignore lint/suspicious/noConsole: keep for logging
192-
console.log(chalk.cyan(`Building default branch '${defaultBranch}' → ${labelForOutDir}`))
193-
buildBranch(defaultBranch, labelForOutDir)
194-
} else {
195-
// build the current workspace directly
196-
// biome-ignore lint/suspicious/noConsole: keep for logging
197-
console.log(chalk.cyan(`Building current workspace → ${labelForOutDir}`))
198-
buildDocs(workspaceRoot, join(outputDir, labelForOutDir))
199-
}
200-
}
201157
;(async () => {
202158
const { values } = parseArgs({
203159
args: process.argv.slice(2),
@@ -207,22 +163,12 @@ function buildCurrentSnapshot(defaultBranch: string, onDefaultBranch: boolean, l
207163
},
208164
})
209165

210-
const defaultBranch = (values.branch as string | undefined)?.trim()
211-
if (!defaultBranch) {
212-
throw new Error(
213-
`❌ Missing required --branch flag.
214-
Please specify the default branch name (e.g., --branch main)
215-
Example: pnpm run generate:docs --branch main`
216-
)
217-
}
218-
219166
const rawVersions = (values.versions as string | undefined)?.trim() ?? ""
220167
const hasVersionsArg = rawVersions.length > 0
221168

222169
let builtVersions: string[] = []
223170

224-
const onDefaultBranch = isOnDefaultBranch(defaultBranch)
225-
const currentBranchToBuild = onDefaultBranch ? defaultBranch : getCurrentBranch()
171+
const currentBranchToBuild = getCurrentBranch()
226172

227173
// biome-ignore lint/suspicious/noConsole: keep for logging
228174
console.log(chalk.cyan(`Building from branch: ${currentBranchToBuild}`))
@@ -235,11 +181,15 @@ function buildCurrentSnapshot(defaultBranch: string, onDefaultBranch: boolean, l
235181
console.log(chalk.cyan(`Building tags: ${tags.join(", ")}`))
236182
for (const t of tags) buildTag(t)
237183

238-
buildCurrentSnapshot(defaultBranch, onDefaultBranch, "current")
184+
// biome-ignore lint/suspicious/noConsole: keep for logging
185+
console.log(chalk.cyan("Building current workspace → current"))
186+
buildDocs(workspaceRoot, join(outputDir, "current"))
239187

240188
builtVersions = ["current", ...tags]
241189
} else {
242-
buildCurrentSnapshot(defaultBranch, onDefaultBranch, "current")
190+
// biome-ignore lint/suspicious/noConsole: keep for logging
191+
console.log(chalk.cyan("Building current workspace → current"))
192+
buildDocs(workspaceRoot, join(outputDir, "current"))
243193

244194
builtVersions = ["current"]
245195
}

0 commit comments

Comments
 (0)