Skip to content

Commit 959f1cf

Browse files
committed
docs: Add a predocs script creating symlinks for docs generator
1 parent 74a86e2 commit 959f1cf

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/browser/
22
/dist/
3+
/docs/
34
/docs-slate/
45
/lib/
56
/package-lock.json

docs/prepare-docs.mjs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env node
2+
3+
import { lstat, mkdir, readdir, readFile, symlink, rm } from 'node:fs/promises'
4+
import { resolve } from 'node:path'
5+
import { parseAllDocuments } from '../dist/index.js'
6+
7+
const source = 'docs'
8+
const target = 'docs-slate/source'
9+
10+
// Create symlink for index.html.md
11+
const indexSource = resolve(source, 'index.html.md')
12+
const indexTarget = resolve(target, 'index.html.md')
13+
try {
14+
const prevIndex = await lstat(indexTarget)
15+
if (prevIndex.isSymbolicLink()) await rm(indexTarget)
16+
} catch {}
17+
await symlink(indexSource, indexTarget, 'file')
18+
19+
// Create symlinks for included sections
20+
const includesDir = resolve(target, 'includes')
21+
try {
22+
await mkdir(includesDir)
23+
} catch {
24+
for (const ent of await readdir(includesDir, { withFileTypes: true })) {
25+
if (ent.isSymbolicLink()) await rm(resolve(includesDir, ent.name))
26+
}
27+
}
28+
const [indexDoc] = parseAllDocuments(await readFile(indexSource, 'utf-8'))
29+
for (const { value } of indexDoc.get('includes').items) {
30+
const name = `${value}.md`
31+
await symlink(resolve(source, name), resolve(includesDir, name), 'file')
32+
}

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
"test:dist:types": "tsc --allowJs --moduleResolution node --noEmit --target es5 dist/index.js",
5353
"test:types": "tsc --noEmit && tsc --noEmit -p tests/tsconfig.json",
5454
"docs:install": "cd docs-slate && bundle install",
55+
"predocs:deploy": "node docs/prepare-docs.mjs",
5556
"docs:deploy": "cd docs-slate && ./deploy.sh",
57+
"predocs": "node docs/prepare-docs.mjs",
5658
"docs": "cd docs-slate && bundle exec middleman server",
5759
"preversion": "npm test && npm run build",
5860
"prepublishOnly": "npm run clean && npm test && npm run build"

0 commit comments

Comments
 (0)