-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy-app-wikis.mjs
61 lines (51 loc) · 2.15 KB
/
copy-app-wikis.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { readdirSync, existsSync, readFileSync, rmSync, mkdirSync, cpSync, writeFileSync } from 'fs'
import { XMLParser } from 'fast-xml-parser'
const APPS_FOLDER = "../apps"
const getAppsWithWiki = () =>
readdirSync(APPS_FOLDER, { withFileTypes: true })
.filter(entry =>
entry.isDirectory() &&
entry.name.startsWith("Wripple.Apps") &&
!entry.name.endsWith(".Tests") &&
existsSync(`${APPS_FOLDER}/${entry.name}/Wiki`))
.map(dir => dir.name)
const generateDocusaurusIndex = (appDir) => {
writeFileSync(`${appDir}/_category_.json`, '{"link": {"type": "generated-index"}}')
readdirSync(appDir, { withFileTypes: true })
.filter(entry => entry.isDirectory())
.forEach(entry => {
const path = `${appDir}/${entry.name}`
generateDocusaurusIndex(path);
writeFileSync(`${path}/_category_.json`, '{"link": {"type": "generated-index"}}')
})
}
const appsWithWiki = getAppsWithWiki()
console.info(`Found ${appsWithWiki.length} apps with wiki.`)
for (let i = 0; i < appsWithWiki.length; i++) {
const appDir = appsWithWiki[i];
var appFullDir = `${APPS_FOLDER}/${appDir}`
var projFiles =
readdirSync(appFullDir, { withFileTypes: true })
.filter(entry => entry.name.endsWith(".csproj"))
.map(file => `${appFullDir}/${file.name}`);
if (projFiles.length !== 1) {
console.error(`Cannot find .csproj file for '${appFullDir}'.`)
continue;
}
const projFileData = readFileSync(projFiles[0], 'utf8')
const parser = new XMLParser()
const json = parser.parse(projFileData)
const docsDir = `${appFullDir}/Wiki`
const appName = json.Project.PropertyGroup.Title.replace(/[^A-Za-z0-9-]/g, "");
const newDocsDir = `docs/apps/${appName}`
const anyMarkdown = readdirSync(docsDir, { recursive: true}).some(fn => fn.endsWith('.md'));
if(!anyMarkdown) {
console.info(`'${docsDir}' folder does not have any markdown files. Skipping.`)
continue;
}
rmSync(newDocsDir, { recursive: true, force: true })
mkdirSync(newDocsDir, { recursive: true })
cpSync(`${docsDir}/`, newDocsDir, { recursive: true })
generateDocusaurusIndex(newDocsDir)
console.info(`Wiki processed for '${appFullDir}'.`)
}