Skip to content

Commit

Permalink
docs: Add a predocs script creating symlinks for docs generator
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Feb 25, 2024
1 parent 74a86e2 commit 959f1cf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintignore
@@ -1,5 +1,6 @@
/browser/
/dist/
/docs/
/docs-slate/
/lib/
/package-lock.json
Expand Down
32 changes: 32 additions & 0 deletions docs/prepare-docs.mjs
@@ -0,0 +1,32 @@
#!/usr/bin/env node

import { lstat, mkdir, readdir, readFile, symlink, rm } from 'node:fs/promises'
import { resolve } from 'node:path'
import { parseAllDocuments } from '../dist/index.js'

const source = 'docs'
const target = 'docs-slate/source'

// Create symlink for index.html.md
const indexSource = resolve(source, 'index.html.md')
const indexTarget = resolve(target, 'index.html.md')
try {
const prevIndex = await lstat(indexTarget)
if (prevIndex.isSymbolicLink()) await rm(indexTarget)
} catch {}
await symlink(indexSource, indexTarget, 'file')

// Create symlinks for included sections
const includesDir = resolve(target, 'includes')
try {
await mkdir(includesDir)
} catch {
for (const ent of await readdir(includesDir, { withFileTypes: true })) {
if (ent.isSymbolicLink()) await rm(resolve(includesDir, ent.name))
}
}
const [indexDoc] = parseAllDocuments(await readFile(indexSource, 'utf-8'))
for (const { value } of indexDoc.get('includes').items) {
const name = `${value}.md`
await symlink(resolve(source, name), resolve(includesDir, name), 'file')
}
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -52,7 +52,9 @@
"test:dist:types": "tsc --allowJs --moduleResolution node --noEmit --target es5 dist/index.js",
"test:types": "tsc --noEmit && tsc --noEmit -p tests/tsconfig.json",
"docs:install": "cd docs-slate && bundle install",
"predocs:deploy": "node docs/prepare-docs.mjs",
"docs:deploy": "cd docs-slate && ./deploy.sh",
"predocs": "node docs/prepare-docs.mjs",
"docs": "cd docs-slate && bundle exec middleman server",
"preversion": "npm test && npm run build",
"prepublishOnly": "npm run clean && npm test && npm run build"
Expand Down

0 comments on commit 959f1cf

Please sign in to comment.