* Move files around in preparation for refactor * Update paths in build script * Extract generic printing logic from the JavaScript printer * Conform printer API * Fixup decorator handling * Fix multiparser * Create plugin entry for markdown * Create plugin entry for javascript/typescript * Create plugin entry for html * Create plugin entry for graphql * Create plugin entry for css/less/scss * Move JSON to JS plugin entry * Integrate plugins into getSupportInfo() * Move astFormat to parser definition * Move util to common * Implement parser loading * remark -> mdast * Rename cli/cli -> cli/index * Rename builder -> doc package, fix printer resolution * Fix doc shape assumption in CSS-in-JS logic * Fix third-party.js prod resolution * Fixup build-docs script * Distribute multiparser code * Remove requirement to forward options * Flatten closure * Remove debug directory * Expose doc * Add external plugins * Pass options to loadPlugins * Export getParsers * Pin resolve version * Use getSupportInfo in Markdown embed * Document plugin API * Update build-docs * Add CLI for plugins * Lint docs * Fixup build.js * Add vue language * Fixup multiparser for vue * Upgrade rollup and rollup-plugin-commonjs * Fixup third-party build * Change AST format in docs
102 lines
2.6 KiB
JavaScript
Executable File
102 lines
2.6 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
"use strict";
|
|
|
|
const path = require("path");
|
|
const pkg = require("../../package.json");
|
|
const formatMarkdown = require("../../website/static/markdown");
|
|
const parsers = require("./parsers");
|
|
const shell = require("shelljs");
|
|
|
|
const rootDir = path.join(__dirname, "..", "..");
|
|
|
|
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);
|
|
|
|
shell.rm("-Rf", "dist/");
|
|
|
|
// --- Lib ---
|
|
|
|
shell.exec("rollup -c scripts/build/rollup.index.config.js");
|
|
|
|
shell.exec("rollup -c scripts/build/rollup.bin.config.js");
|
|
shell.chmod("+x", "./dist/bin/prettier.js");
|
|
|
|
shell.exec("rollup -c scripts/build/rollup.third-party.config.js");
|
|
|
|
for (const parser of parsers) {
|
|
if (parser.endsWith("postcss")) {
|
|
continue;
|
|
}
|
|
shell.exec(
|
|
`rollup -c scripts/build/rollup.parser.config.js --environment parser:${parser}`
|
|
);
|
|
}
|
|
|
|
shell.echo("\nsrc/language-css/parser-postcss.js → dist/parser-postcss.js");
|
|
// PostCSS has dependency cycles and won't work correctly with rollup :(
|
|
shell.exec(
|
|
"webpack --hide-modules src/language-css/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"
|
|
);
|
|
|
|
shell.echo("Update ISSUE_TEMPLATE.md");
|
|
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
|
|
)
|
|
);
|
|
pipe(newIssueTemplate).to(".github/ISSUE_TEMPLATE.md");
|
|
|
|
shell.echo("Copy package.json");
|
|
const pkgWithoutDependencies = Object.assign({}, pkg);
|
|
delete pkgWithoutDependencies.dependencies;
|
|
pkgWithoutDependencies.scripts = {
|
|
prepublishOnly:
|
|
"node -e \"assert.equal(require('.').version, require('..').version)\""
|
|
};
|
|
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:");
|
|
shell.echo(" 1) yarn test:dist");
|
|
shell.echo();
|
|
shell.echo("How to publish:");
|
|
shell.echo(" 1) IMPORTANT!!! Go to dist/");
|
|
shell.echo(" 2) npm publish");
|