-
Notifications
You must be signed in to change notification settings - Fork 1
/
docs-gen.js
69 lines (52 loc) · 2.45 KB
/
docs-gen.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
import fs from "fs-extra";
import path from "path";
import { simpleGit } from "simple-git";
import pnpmExec from "@pnpm/exec";
import typedoc, { Application } from "typedoc";
import docsGenData from "./docs-gen/data.json" with { type: "json" };
const pnpm = pnpmExec.default;
(async () => {
const docsGenPath = path.resolve(path.join(".", "docs-gen")),
tmpDocsGenPath = path.resolve(path.join(docsGenPath, "tmp"));
await fs.mkdir(tmpDocsGenPath);
for (const remote of docsGenData) {
console.log(`Cloning and building ${remote.package ?? remote.folder}`);
const branch = "main"; //remote.package && pkgInfo.devDependencies[remote.package] ? `${remote.package}@${pkgInfo.devDependencies[remote.package].replace("^", "")}` : "main";
// TODO: remove comments when the new tsParticles version will be released
await simpleGit().clone(remote.url, path.join(tmpDocsGenPath, remote.folder), ["--depth", "1", "-b", branch]);
console.log(`Installing packages on folder ${remote.folder}`);
await pnpm(["install"], {
cwd: path.resolve(path.join(tmpDocsGenPath, remote.folder)),
});
console.log(`Running command ${remote.buildCommand} packages on folder ${remote.folder}`);
await pnpm(["run", remote.buildCommand], {
cwd: path.resolve(path.join(tmpDocsGenPath, remote.folder)),
});
//await pnpm(["run", "build:docs"], {
// cwd: path.resolve(path.join(tmpDocsGenPath, remote.folder))
//});
//await fs.copy(path.join(tmpDocsGenPath, remote.folder, "docs"), path.join(".", "dist", "docs"));
}
try {
const typedocApp = await Application.bootstrapWithPlugins(
{
options: path.join(docsGenPath, "typedoc.json"),
tsconfig: path.join(docsGenPath, "tsconfig.json"),
},
[new typedoc.TSConfigReader(), new typedoc.TypeDocReader()],
);
const project = await typedocApp.convert();
if (project) {
if (!(await fs.pathExists("./dist"))) {
await fs.mkdir("./dist");
}
// Project may not have converted correctly
const outputDir = path.join(".", "dist", "docs");
// Rendered docs
await typedocApp.generateDocs(project, outputDir);
}
} catch (e) {
console.log("Error during docs generation", e);
}
await fs.remove(tmpDocsGenPath);
})();