2018-05-27 15:14:01 -03:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
2021-05-15 20:09:52 +08:00
|
|
|
import path from "node:path";
|
|
|
|
|
import fs from "node:fs";
|
|
|
|
|
import shell from "shelljs";
|
|
|
|
|
import globby from "globby";
|
|
|
|
|
import prettier from "prettier";
|
|
|
|
|
import createEsmUtils from "esm-utils";
|
2018-05-27 15:14:01 -03:00
|
|
|
|
2018-08-07 18:53:11 +08:00
|
|
|
shell.config.fatal = true;
|
|
|
|
|
|
2021-05-15 20:09:52 +08:00
|
|
|
const { __dirname, require } = createEsmUtils(import.meta);
|
2018-05-27 15:31:52 -03:00
|
|
|
const rootDir = path.join(__dirname, "..");
|
2018-05-27 15:14:01 -03:00
|
|
|
const docs = path.join(rootDir, "website/static/lib");
|
|
|
|
|
|
|
|
|
|
function pipe(string) {
|
|
|
|
|
return new shell.ShellString(string);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isPullRequest = process.env.PULL_REQUEST === "true";
|
2020-07-17 09:07:26 +08:00
|
|
|
const prettierPath = path.join(
|
|
|
|
|
rootDir,
|
|
|
|
|
isPullRequest ? "dist" : "node_modules/prettier"
|
|
|
|
|
);
|
2018-05-27 15:14:01 -03:00
|
|
|
|
|
|
|
|
shell.mkdir("-p", docs);
|
|
|
|
|
|
|
|
|
|
if (isPullRequest) {
|
|
|
|
|
// --- Build prettier for PR ---
|
2018-05-27 21:51:50 -03:00
|
|
|
const pkg = require("../package.json");
|
2020-01-20 18:49:52 +08:00
|
|
|
const newPkg = { ...pkg, version: `999.999.999-pr.${process.env.REVIEW_ID}` };
|
2018-12-25 08:20:35 +08:00
|
|
|
pipe(JSON.stringify(newPkg, null, 2)).to("package.json");
|
2020-10-26 09:44:09 +08:00
|
|
|
shell.exec("yarn build --playground");
|
2020-04-14 19:27:25 +03:00
|
|
|
pipe(JSON.stringify(pkg, null, 2) + "\n").to("package.json"); // restore
|
2018-05-27 15:14:01 -03:00
|
|
|
}
|
2020-07-17 09:07:26 +08:00
|
|
|
|
2019-01-11 00:33:43 +01:00
|
|
|
shell.cp(`${prettierPath}/standalone.js`, `${docs}/`);
|
|
|
|
|
shell.cp(`${prettierPath}/parser-*.js`, `${docs}/`);
|
2018-05-27 15:14:01 -03:00
|
|
|
|
2020-07-17 09:07:26 +08:00
|
|
|
const parserModules = globby.sync(["parser-*.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" }
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2018-05-27 15:14:01 -03:00
|
|
|
// --- Site ---
|
|
|
|
|
shell.cd("website");
|
|
|
|
|
shell.echo("Building website...");
|
|
|
|
|
shell.exec("yarn install");
|
|
|
|
|
|
|
|
|
|
shell.exec("yarn build");
|
|
|
|
|
|
|
|
|
|
shell.echo();
|