Skip to content

Commit 6e808f9

Browse files
author
abrulic
committed
generate-docs updated test
1 parent e19e0f7 commit 6e808f9

File tree

3 files changed

+75
-58
lines changed

3 files changed

+75
-58
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: "Usage inside a monorepo"
3+
summary: "Add the docs-template into an existing monorepo and run it locally (pnpm workspace, workflows, and content setup)."
4+
description: "Step-by-step guide for integrating the docs-template into a monorepo: add the `docs/` package to `pnpm-workspace.yaml`, move CI workflows to `.github/workflows`, resolve FIXME markers, replace example content under `docs/content`, and run the local dev server with pnpm."
5+
---
6+
7+
## Usage inside a monorepo
8+
9+
This page explains the minimal steps to install the docs-template into an existing monorepo and run the documentation locally. The template is designed to be dropped under the `/docs` folder of your repository and wired into pnpm workspaces.
10+
11+
Follow these steps:
12+
13+
1. Create a repository (or use an existing one)
14+
15+
- You can start from our example stack `@forge42/open-source-stack` or any repo you control. The important part is that you can add a `/docs` folder and control the repository root (where `.github`, `pnpm-workspace.yaml`, etc. live).
16+
17+
2. Download and extract the docs-template into your monorepo
18+
19+
- Download the `docs-template` files from the main branch (or copy the template contents) and extract them into the repository root inside a `docs/` directory.
20+
21+
- Make sure your root `pnpm-workspace.yaml` includes the `docs` package so pnpm can hoist and link the docs project. Example snippet:
22+
23+
```yaml
24+
packages:
25+
packages/*
26+
test-apps/*
27+
+ docs
28+
onlyBuiltDependencies:
29+
'@biomejs/biome'
30+
esbuild
31+
lefthook
32+
```
33+
34+
35+
3. Move or add workflow files to `.github/workflows` in the monorepo root
36+
37+
- The template includes CI workflows (for example: `ci.yml`, `publish-documentation.yml`, and `pr-close.yml`). Move these into your repository root under `.github/workflows/` so GitHub Actions can find and run them.
38+
39+
- The workflows use Fly.io and the template `fly.toml` and `Dockerfile`. If you don't use Fly, you can customize the workflows or remove those steps.
40+
41+
4. Check and resolve FIXME comments inside workflows
42+
43+
- Open the workflow files and search for `FIXME` markers. Resolve those before relying on the workflows.
44+
45+
5. Make sure you have a `/content` folder with documentation pages
46+
47+
- The template ships with example content in `docs/content` that briefly explains how the template works. Remove those example files and add your own documentation content (for example: `01-getting-started.mdx`, `02-project-structure.mdx`, etc.).
48+
49+
6. Install and run locally
50+
51+
- From the repository root run:
52+
53+
```bash
54+
pnpm install
55+
pnpm run dev
56+
```
57+
58+
- After `pnpm run dev` the docs server will start (see terminal output for the local dev URL). Open the URL in your browser to preview the site.
59+
60+
Notes and tips
61+
62+
- If your monorepo already has a `docs/` package, merge carefully to avoid overwriting important files.
63+
- Keep `fly.toml` and `Dockerfile` at the root of the `docs` package (or where the workflows expect them). If you move them, update the workflow paths accordingly.
64+
- Verify `pnpm-workspace.yaml` indentation and syntax — YAML parsing errors can stop workspace linking.
65+
- If you use a different package manager or CI provider, adapt the commands and workflow steps.

scripts/generate-docs.ts

Lines changed: 7 additions & 53 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,11 +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-
}
181157
;(async () => {
182158
const { values } = parseArgs({
183159
args: process.argv.slice(2),
@@ -187,22 +163,12 @@ function isOnDefaultBranch(defaultBranch: string): boolean {
187163
},
188164
})
189165

190-
const defaultBranch = (values.branch as string | undefined)?.trim()
191-
if (!defaultBranch) {
192-
throw new Error(
193-
`❌ Missing required --branch flag.
194-
Please specify the default branch name (e.g., --branch main)
195-
Example: pnpm run generate:docs --branch main`
196-
)
197-
}
198-
199166
const rawVersions = (values.versions as string | undefined)?.trim() ?? ""
200167
const hasVersionsArg = rawVersions.length > 0
201168

202169
let builtVersions: string[] = []
203170

204-
const onDefaultBranch = isOnDefaultBranch(defaultBranch)
205-
const currentBranchToBuild = onDefaultBranch ? defaultBranch : getCurrentBranch()
171+
const currentBranchToBuild = getCurrentBranch()
206172

207173
// biome-ignore lint/suspicious/noConsole: keep for logging
208174
console.log(chalk.cyan(`Building from branch: ${currentBranchToBuild}`))
@@ -215,27 +181,15 @@ function isOnDefaultBranch(defaultBranch: string): boolean {
215181
console.log(chalk.cyan(`Building tags: ${tags.join(", ")}`))
216182
for (const t of tags) buildTag(t)
217183

218-
if (onDefaultBranch) {
219-
// biome-ignore lint/suspicious/noConsole: keep for logging
220-
console.log(chalk.cyan(`Building default branch '${defaultBranch}' → current`))
221-
buildBranch(defaultBranch, "current")
222-
} else {
223-
// biome-ignore lint/suspicious/noConsole: keep for logging
224-
console.log(chalk.cyan("Building current workspace → current"))
225-
buildDocs(workspaceRoot, join(outputDir, "current"))
226-
}
184+
// biome-ignore lint/suspicious/noConsole: keep for logging
185+
console.log(chalk.cyan("Building current workspace → current"))
186+
buildDocs(workspaceRoot, join(outputDir, "current"))
227187

228188
builtVersions = ["current", ...tags]
229189
} else {
230-
if (onDefaultBranch) {
231-
// biome-ignore lint/suspicious/noConsole: keep for logging
232-
console.log(chalk.cyan(`Building default branch '${defaultBranch}' → current`))
233-
buildBranch(defaultBranch, "current")
234-
} else {
235-
// biome-ignore lint/suspicious/noConsole: keep for logging
236-
console.log(chalk.cyan("Building current workspace → current"))
237-
buildDocs(workspaceRoot, join(outputDir, "current"))
238-
}
190+
// biome-ignore lint/suspicious/noConsole: keep for logging
191+
console.log(chalk.cyan("Building current workspace → current"))
192+
buildDocs(workspaceRoot, join(outputDir, "current"))
239193

240194
builtVersions = ["current"]
241195
}

vite.config.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import babel from "vite-plugin-babel"
88
import { iconsSpritesheet } from "vite-plugin-icons-spritesheet"
99
import tsconfigPaths from "vite-tsconfig-paths"
1010

11-
export default defineConfig(({ mode }) => ({
11+
export default defineConfig({
1212
plugins: [
1313
tailwindcss(),
1414
// Run the react-compiler on .tsx files only when bundling
@@ -37,13 +37,11 @@ export default defineConfig(({ mode }) => ({
3737
withTypes: true,
3838
formatter: "biome",
3939
}),
40-
// Only load content-collections plugin in development
41-
// In production, we load pre-generated docs from generated-docs/
42-
...(mode === "development" ? [contentCollections()] : []),
40+
contentCollections(),
4341
],
4442
server: {
4543
open: true,
4644
// biome-ignore lint/nursery/noProcessEnv: Its ok to use process.env here
4745
port: Number(process.env.PORT || 4280),
4846
},
49-
}))
47+
})

0 commit comments

Comments
 (0)