-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathgenerateDocs.js
66 lines (57 loc) · 1.79 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
#!/usr/bin/env node
process.env.NODE_PATH = process.cwd();
const tsNode = require("ts-node");
const { resolve } = require("path");
const yargs = require("yargs");
tsNode.register({
dir: resolve(__dirname, "./generator")
});
const { App, AppConfig } = require("@webiny/docs-generator");
const { default: docsConfig } = require("./docs.config");
(async () => {
const { watch, watchOnly, version } = yargs
.version(false)
.option("v", {
alias: "version",
describe: "Whitelist versions to build.",
type: "array",
default: []
})
.option("watch", {
default: false,
description: "Run generator and watch for changes.",
type: "boolean"
})
.option("watchOnly", {
default: false,
description: "Only watch for changes, without the initial generation.",
type: "boolean"
}).argv;
const config = AppConfig.create({
linkValidator: docsConfig.linkValidator,
mdxRemarkPlugins: docsConfig.mdxRemarkPlugins,
projectRootDir: docsConfig.projectRootDir,
devMode: process.env.NODE_ENV === "development",
documentRootConfigs: docsConfig.documentRoots.filter(Boolean),
outputVersions: version,
sitemapOutputPath: docsConfig.sitemapOutputPath
});
const app = new App(config);
if (watchOnly) {
await app.watch();
}
try {
if (docsConfig.cleanOutputDir) {
const rimraf = require("rimraf");
console.log("Cleaning output directory...");
rimraf.sync(docsConfig.cleanOutputDir);
}
await app.generate();
} catch (err) {
process.exit(1);
}
if (watch) {
await app.watch();
}
process.exit();
})();