Skip to content

Instantly share code, notes, and snippets.

@scvnathan
Created June 27, 2017 22:31
Show Gist options
  • Save scvnathan/3db6d7d78890ae7f6b1fed05b2393c39 to your computer and use it in GitHub Desktop.
Save scvnathan/3db6d7d78890ae7f6b1fed05b2393c39 to your computer and use it in GitHub Desktop.
a little prettier wrapper to allow for custom execution, mainly for ignoring certain file types. I wrote this initially so i can use it with my IDE which in injects the current file as a param
const path = require("path");
const childProcess = require("child_process");
const prettierArgs = Array.from(process.argv).slice(2);
const valid = [".jsx", ".js"];
if (valid.includes(path.extname(prettierArgs[prettierArgs.length - 1]))) {
let prettierLocation = "";
//default locations for locally installed prettier
if (["darwin", "linux"].includes(require("os").platform())) {
prettierLocation = "../node_modules/.bin/prettier";
} else {
prettierLocation = "../node_modules/.bin/prettier.cmd";
}
childProcess.exec(`"${path.resolve(path.join(__dirname, prettierLocation))}" ${prettierArgs.join(" ")}`, (error, stdout, stderr) => {
if (stderr) console.log(`${stderr}`);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment