Files
test-repo/scripts/build/build-docs.js
T
Christopher Chedeau c40b061b80 [vue] Introduce proper support for Vue Single File Components (SFC) (#3563)
There's a lot of demand for vue sfc (#2097). This introduces partial support for them: all the html is printed as is, except for the script and style tags which are printed using prettier. I believe that this should cover a lot of the use cases while being simple to support and if we want we can extend to more in the future.

I copy pasted the html parser used by vue (it's just a single 400 lines file) so that we don't run the chancesof conflicts. I'm also very conservative: I only print the style and script at the top level and for the lang attributes we support.

I expect this to be landable as is and provide value, review welcome :)
2017-12-25 01:15:33 +01:00

75 lines
1.8 KiB
JavaScript

#!/usr/bin/env node
"use strict";
const path = require("path");
const shell = require("shelljs");
const rootDir = path.join(__dirname, "..", "..");
const docs = path.join(rootDir, "website/static/lib");
const parsers = [
"babylon",
"flow",
"typescript",
"graphql",
"postcss",
"parse5",
"markdown",
"vue"
];
function pipe(string) {
return new shell.ShellString(string);
}
const isPullRequest = process.env.PULL_REQUEST === "true";
const prettierPath = isPullRequest ? "dist" : "node_modules/prettier/";
// --- Build prettier for PR ---
if (isPullRequest) {
const pkg = require("../../package.json");
pkg.version = `pr-${process.env.REVIEW_ID}`;
pipe(JSON.stringify(pkg, null, 2)).to("package.json");
shell.exec("node scripts/build/build.js");
}
// --- Docs ---
shell.mkdir("-p", docs);
shell.echo("Bundling docs index...");
shell.cp(`${prettierPath}/index.js`, `${docs}/index.js`);
shell.exec(
`node_modules/babel-cli/bin/babel.js ${docs}/index.js --out-file ${docs}/index.js --presets=es2015`
);
shell.echo("Bundling docs babylon...");
shell.exec(
`rollup -c scripts/build/rollup.docs.config.js --environment filepath:parser-babylon.js -i ${prettierPath}/parser-babylon.js`
);
shell.exec(
`node_modules/babel-cli/bin/babel.js ${docs}/parser-babylon.js --out-file ${docs}/parser-babylon.js --presets=es2015`
);
for (const parser of parsers) {
if (parser === "babylon") {
continue;
}
shell.echo(`Bundling docs ${parser}...`);
shell.exec(
`rollup -c scripts/build/rollup.docs.config.js --environment filepath:parser-${parser}.js -i ${prettierPath}/parser-${parser}.js`
);
}
shell.echo("Copy sw-toolbox.js to docs");
shell.cp("node_modules/sw-toolbox/sw-toolbox.js", `${docs}/sw-toolbox.js`);
// --- Site ---
shell.cd("website");
shell.echo("Building website...");
shell.exec("yarn install");
shell.exec("yarn build");
shell.echo();