-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
build-docs.js
72 lines (57 loc) · 1.68 KB
/
build-docs.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
#!/usr/bin/env node
"use strict";
const path = require("path");
const fs = require("fs");
const shell = require("shelljs");
const globby = require("globby");
const prettier = require("prettier");
shell.config.fatal = true;
const rootDir = path.join(__dirname, "..");
const docs = path.join(rootDir, "website/static/lib");
function pipe(string) {
return new shell.ShellString(string);
}
const isPullRequest = process.env.PULL_REQUEST === "true";
const prettierPath = path.join(
rootDir,
isPullRequest ? "dist" : "node_modules/prettier"
);
shell.mkdir("-p", docs);
if (isPullRequest) {
// --- Build prettier for PR ---
const pkg = require("../package.json");
const newPkg = { ...pkg, version: `999.999.999-pr.${process.env.REVIEW_ID}` };
pipe(JSON.stringify(newPkg, null, 2)).to("package.json");
shell.exec("yarn build");
pipe(JSON.stringify(pkg, null, 2) + "\n").to("package.json"); // restore
}
shell.cp(`${prettierPath}/standalone.js`, `${docs}/`);
shell.cp(`${prettierPath}/parser-!(*.module).js`, `${docs}/`);
const parserModules = globby.sync(["parser-!(*.module).js"], {
cwd: prettierPath,
});
const parsers = {};
for (const file of parserModules) {
const plugin = require(path.join(prettierPath, file));
const property = file.replace(/\.js$/, "").split("-")[1];
parsers[file] = {
parsers: Object.keys(plugin.parsers),
property,
};
}
fs.writeFileSync(
`${docs}/parsers-location.js`,
prettier.format(
`
"use strict";
const parsersLocation = ${JSON.stringify(parsers)};
`,
{ parser: "babel" }
)
);
// --- Site ---
shell.cd("website");
shell.echo("Building website...");
shell.exec("yarn install");
shell.exec("yarn build");
shell.echo();