2017-06-28 23:34:59 +03:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const path = require("path");
|
|
|
|
const pkg = require("../../package.json");
|
2017-09-14 01:14:35 +03:00
|
|
|
const formatMarkdown = require("../../website/static/markdown");
|
2017-08-29 23:39:49 +03:00
|
|
|
const shell = require("shelljs");
|
2017-06-28 23:34:59 +03:00
|
|
|
|
|
|
|
const rootDir = path.join(__dirname, "..", "..");
|
|
|
|
const parsers = [
|
|
|
|
"babylon",
|
|
|
|
"flow",
|
|
|
|
"typescript",
|
|
|
|
"graphql",
|
|
|
|
"postcss",
|
2017-10-12 01:46:44 +03:00
|
|
|
"parse5",
|
|
|
|
"markdown"
|
2017-06-28 23:34:59 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
process.env.PATH += path.delimiter + path.join(rootDir, "node_modules", ".bin");
|
|
|
|
|
|
|
|
function pipe(string) {
|
|
|
|
return new shell.ShellString(string);
|
|
|
|
}
|
|
|
|
|
|
|
|
shell.set("-e");
|
|
|
|
shell.cd(rootDir);
|
|
|
|
|
2017-11-28 01:27:25 +03:00
|
|
|
shell.rm("-Rf", "dist/");
|
2017-06-28 23:34:59 +03:00
|
|
|
|
|
|
|
// --- Lib ---
|
|
|
|
|
|
|
|
shell.echo("Bundling lib index...");
|
|
|
|
shell.exec("rollup -c scripts/build/rollup.index.config.js");
|
|
|
|
|
|
|
|
shell.echo("Bundling lib bin...");
|
|
|
|
shell.exec("rollup -c scripts/build/rollup.bin.config.js");
|
|
|
|
shell.chmod("+x", "./dist/bin/prettier.js");
|
|
|
|
|
2017-11-22 14:27:40 +03:00
|
|
|
shell.echo("Bundling lib third-party...");
|
|
|
|
shell.exec("rollup -c scripts/build/rollup.third-party.config.js");
|
|
|
|
|
2017-06-28 23:34:59 +03:00
|
|
|
for (const parser of parsers) {
|
|
|
|
if (parser === "postcss") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
shell.echo(`Bundling lib ${parser}...`);
|
|
|
|
shell.exec(
|
2017-12-05 13:14:03 +03:00
|
|
|
`rollup -c scripts/build/rollup.parser.config.js --environment parser:${parser}`
|
2017-06-28 23:34:59 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
shell.echo("Bundling lib postcss...");
|
|
|
|
// PostCSS has dependency cycles and won't work correctly with rollup :(
|
|
|
|
shell.exec(
|
|
|
|
"webpack --hide-modules src/parser-postcss.js dist/parser-postcss.js"
|
|
|
|
);
|
|
|
|
// Prepend module.exports =
|
|
|
|
const content = shell.cat("dist/parser-postcss.js").stdout;
|
|
|
|
pipe(`module.exports = ${content}`).to("dist/parser-postcss.js");
|
|
|
|
|
|
|
|
shell.echo();
|
|
|
|
|
|
|
|
// --- Misc ---
|
|
|
|
|
|
|
|
shell.echo("Remove eval");
|
|
|
|
shell.sed(
|
|
|
|
"-i",
|
|
|
|
/eval\("require"\)/,
|
|
|
|
"require",
|
|
|
|
"dist/index.js",
|
|
|
|
"dist/bin/prettier.js"
|
|
|
|
);
|
|
|
|
|
2017-09-09 16:39:11 +03:00
|
|
|
shell.echo("Update ISSUE_TEMPLATE.md");
|
2017-09-14 01:14:35 +03:00
|
|
|
const issueTemplate = shell.cat(".github/ISSUE_TEMPLATE.md").stdout;
|
|
|
|
const newIssueTemplate = issueTemplate.replace(
|
|
|
|
/-->[^]*$/,
|
|
|
|
"-->\n\n" +
|
|
|
|
formatMarkdown(
|
|
|
|
"// code snippet",
|
|
|
|
"// code snippet",
|
|
|
|
"",
|
|
|
|
pkg.version,
|
|
|
|
"https://prettier.io/playground/#.....",
|
|
|
|
{ parser: "babylon" },
|
|
|
|
[["# Options (if any):", true], ["--single-quote", true]],
|
|
|
|
true
|
|
|
|
)
|
2017-09-09 16:39:11 +03:00
|
|
|
);
|
2017-09-14 01:14:35 +03:00
|
|
|
pipe(newIssueTemplate).to(".github/ISSUE_TEMPLATE.md");
|
2017-09-09 16:39:11 +03:00
|
|
|
|
2017-06-28 23:34:59 +03:00
|
|
|
shell.echo("Copy package.json");
|
|
|
|
const pkgWithoutDependencies = Object.assign({}, pkg);
|
|
|
|
delete pkgWithoutDependencies.dependencies;
|
2017-10-03 11:34:08 +03:00
|
|
|
pkgWithoutDependencies.scripts = {
|
|
|
|
prepublishOnly:
|
|
|
|
"node -e \"assert.equal(require('.').version, require('..').version)\""
|
|
|
|
};
|
2017-06-28 23:34:59 +03:00
|
|
|
pipe(JSON.stringify(pkgWithoutDependencies, null, 2)).to("dist/package.json");
|
|
|
|
|
|
|
|
shell.echo("Copy README.md");
|
|
|
|
shell.cp("README.md", "dist/README.md");
|
|
|
|
|
|
|
|
shell.echo("Done!");
|
|
|
|
shell.echo();
|
|
|
|
shell.echo("How to test against dist:");
|
2017-10-03 12:44:02 +03:00
|
|
|
shell.echo(" 1) yarn test:dist");
|
2017-06-28 23:34:59 +03:00
|
|
|
shell.echo();
|
|
|
|
shell.echo("How to publish:");
|
|
|
|
shell.echo(" 1) IMPORTANT!!! Go to dist/");
|
|
|
|
shell.echo(" 2) npm publish");
|