Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit d469991

Browse files
committed
Aggregate generated docs into one file
1 parent 82282b1 commit d469991

File tree

6 files changed

+814
-4
lines changed

6 files changed

+814
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ ci/bin
33
cmd/coder/coder
44
ci/integration/bin
55
ci/integration/env.sh
6-
coder-sdk/env.sh
6+
coder-sdk/env.sh
7+
.vscode

ci/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
- `steps/gendocs.sh` generates CLI documentation into `/docs` from the command specifications.
88
- `steps/lint.sh` lints all Go source files based on the rules set fourth in `/.golangci.yml`.
99

10-
1110
## integration tests
1211

1312
### `tcli`

ci/image/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ ENV CI=true
55

66
RUN go get golang.org/x/tools/cmd/goimports
77
RUN go get github.com/mattn/goveralls
8-
RUN apt update && apt install grep
8+
9+
RUN apt update && apt install zip curl grep
10+
RUN curl -fsSL https://deno.land/x/install/install.sh | sh
11+
ENV PATH="/root/.deno/bin:${PATH}"

ci/scripts/aggregate_docs.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// join all /docs files into a single markdown file
2+
// fix all hyperlinks
3+
4+
const newFilename = "coder_cli_all_docs.md"
5+
const newPath = `./docs/${newFilename}`
6+
Deno.chdir(`${new URL(".", import.meta.url).pathname}/../../`)
7+
8+
const dirs = []
9+
for await (const dir of Deno.readDir("./docs")) {
10+
dirs.push(dir)
11+
}
12+
13+
const filenames = dirs.map(({ name }) => name).filter((f) => f !== newFilename)
14+
const filenameParts = filenames
15+
.map((f) => f.split("_"))
16+
.sort((a, b) => a.length - b.length)
17+
.sort((a, b) => {
18+
for (let i in a.length > b.length ? a : b) {
19+
if (a[i] != b[i]) return a > b ? -1 : 1
20+
}
21+
return 1
22+
})
23+
24+
let aggregated = ""
25+
for (let i in filenameParts) {
26+
const filename = filenameParts[i].join("_")
27+
const file = await Deno.readFile(`./docs/${filename}`)
28+
aggregated += `\n${new TextDecoder().decode(file)}`
29+
}
30+
for (let i in filenames) {
31+
aggregated = aggregated.replaceAll(
32+
filenames[i],
33+
`#${filenames[i].replace(".md", "").split("_").join("-")}`
34+
)
35+
}
36+
37+
try {
38+
await Deno.remove(newPath)
39+
} catch {}
40+
await Deno.writeFile(newPath, new TextEncoder().encode(aggregated))

ci/steps/gendocs.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -euo pipefail
44

5-
echo "Generating docs..."
5+
echo "-- Generating docs"
66

77
cd "$(dirname "$0")"
88
cd ../../
@@ -11,6 +11,14 @@ rm -rf ./docs
1111
mkdir ./docs
1212
go run ./cmd/coder gen-docs ./docs
1313

14+
if ! command -v deno >/dev/null; then
15+
"deno is required to compile the docs into a single file"
16+
exit 1
17+
fi
18+
19+
echo "-- Aggregating docs"
20+
deno run --allow-read --allow-write ./ci/scripts/aggregate_docs.ts
21+
1422
if [[ ${CI-} && $(git ls-files --other --modified --exclude-standard) ]]; then
1523
echo "Documentation needs generation:"
1624
git -c color.ui=always status | grep --color=no '\e\[31m'

0 commit comments

Comments
 (0)