Skip to content

Commit 8746977

Browse files
authored
Merge pull request #174 from LiliaFramework/codex/remove-about.md-generation-mechanic
feat: build module docs from readme
2 parents 52c50ac + dcf5da5 commit 8746977

File tree

2 files changed

+44
-83
lines changed

2 files changed

+44
-83
lines changed

generate_about_md.js

Lines changed: 0 additions & 83 deletions
This file was deleted.

generate_module_docs.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
4+
let modulesPath = path.join(__dirname, 'modules.json')
5+
if (!fs.existsSync(modulesPath)) {
6+
const alternativePath = path.join(__dirname, 'documentation', 'modules.json')
7+
if (fs.existsSync(alternativePath)) {
8+
modulesPath = alternativePath
9+
} else {
10+
process.exit(1)
11+
}
12+
}
13+
14+
let modules
15+
try {
16+
modules = JSON.parse(fs.readFileSync(modulesPath, 'utf8'))
17+
} catch {
18+
process.exit(1)
19+
}
20+
if (!Array.isArray(modules)) process.exit(1)
21+
22+
function toFolderName(name) {
23+
return String(name)
24+
.toLowerCase()
25+
.replace(/[^a-z0-9]+/g, '_')
26+
.replace(/^_+|_+$/g, '')
27+
}
28+
29+
for (const mod of modules) {
30+
const id = mod.uniqueID || ''
31+
if (!id) continue
32+
33+
const folder = toFolderName(mod.name || id)
34+
35+
const readmePath = path.join(__dirname, folder, 'README.md')
36+
if (!fs.existsSync(readmePath)) continue
37+
38+
const outputDir = path.join(__dirname, 'documentation', 'docs', 'modules', folder)
39+
fs.mkdirSync(outputDir, { recursive: true })
40+
41+
fs.copyFileSync(readmePath, path.join(outputDir, 'about.md'))
42+
}
43+
44+
console.log('README.md files copied as about.md.')

0 commit comments

Comments
 (0)