-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Process documentation with Handlebars
- Loading branch information
Showing
4 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Handlebars from "handlebars" | ||
import { JSDOM } from "jsdom" | ||
import { readFileSync, writeFileSync } from "node:fs" | ||
import * as path from "node:path" | ||
import * as util from "node:util" | ||
|
||
const shell = { | ||
exec: await (async () => util.promisify((await import('node:child_process')).exec))() | ||
} | ||
|
||
const controller = new AbortController(); | ||
|
||
async function sh(cmdAndArgs) { | ||
if (cmdAndArgs.length === 0 || cmdAndArgs[0].length === 0) throw new Error("Expected a command.") | ||
|
||
const { stdout, stderr } = await shell.exec(cmdAndArgs.join("").split(" ").filter(x => x.length).join(" "), { signal: controller.signal }); | ||
if (stderr && stderr.length) console.error(stderr); | ||
return stdout?.trim(); | ||
} | ||
|
||
const files = (await sh`find docs -name '*.html'`).split("\n").map(doc => doc.trim()) | ||
|
||
const DUB_VERSION = await sh`git describe --tags --abbrev=0` | ||
// TODO: Calculate tree of symbols | ||
const SYMBOLS = [] | ||
const MODULES = files.filter(file => file.includes("docs/index.html") === false).map(file => ({ | ||
name: path.basename(file, ".html"), | ||
file: path.basename(file) | ||
})) | ||
const constants = { | ||
DUB_VERSION, | ||
SYMBOLS, | ||
MODULES | ||
} | ||
|
||
files.forEach(file => { | ||
const template = Handlebars.compile(readFileSync(file).toString(), { strict: true }) | ||
writeFileSync(file, template(constants)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters