forked from aris-creator/jancok
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateDocs.js
93 lines (85 loc) · 2.32 KB
/
generateDocs.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
Generates Typedocs documentation and links all README.md files from
other packages, also prepare documentation structure that fits
the project structure.
*/
const fs = require("fs-extra");
const jetpack = require("fs-jetpack");
const path = require("path");
const execa = require("execa");
run();
async function copyRootDirectoryFile(filename) {
await jetpack.copyAsync(
path.join(__dirname, "..", filename),
path.join(__dirname, "..", "docs", filename),
{ overwrite: true }
);
}
async function run() {
await buildDocs();
copyStaticFiles();
await Promise.all([
copyRootDirectoryFile("README.md"),
copyRootDirectoryFile("CONTRIBUTING.md"),
copyRootDirectoryFile("TROUBLESHOOTING.md"),
copyRootDirectoryFile("CHEATSHEET.md"),
copyRootDirectoryFile("STRUCTURE.md"),
]);
await jetpack.removeAsync(path.join(__dirname, "..", "docs", "globals.md"));
}
async function buildDocs() {
try {
const typedocResult = await execa("yarn", [
"typedoc",
"--options",
"typedoc.js",
]);
console.log(typedocResult.stdout);
} catch (e) {
console.error(e);
}
}
function createDocsStructure(filepath) {
relDirPath = filepath.substring(0, filepath.lastIndexOf("/") + 1);
absDirPath = `${__dirname}/../docs/${relDirPath}`;
fs.mkdirSync(absDirPath, { recursive: true });
}
function copyStaticFiles() {
getFilesPath(`${__dirname}/../packages`, /\.md$/, (filepath) => {
let relFilePath = getRelativePath(filepath, "packages/");
let copyDest = `${__dirname}/../docs/${relFilePath}`;
createDocsStructure(relFilePath);
fs.copyFile(filepath, copyDest, (err) => {
if (err) throw err;
});
});
}
function getRelativePath(filepath, separator) {
let [_, rel] = filepath.split(separator);
return `${rel}`;
}
function getFilesPath(
startPath,
filter,
cb,
excludePattern = /(?:node_modules)/
) {
if (!fs.existsSync(startPath)) {
throw new Error("Cannot look for files - not existing path!");
}
let files = fs.readdirSync(startPath);
files.forEach((file) => {
let filepath = path.join(startPath, file);
if (excludePattern.test(filepath)) {
} else {
try {
fs.lstatSync(filepath);
getFilesPath(filepath, filter, cb);
} catch (e) {
if (filter.test(filepath)) {
cb(filepath);
}
}
}
});
}