Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. const path = require("path");
  2. const childProcess = require("child_process");
  3.  
  4. const prettierArgs = Array.from(process.argv).slice(2);
  5. const valid = [".jsx", ".js"];
  6.  
  7. if (valid.includes(path.extname(prettierArgs[prettierArgs.length - 1]))) {
  8. let prettierLocation = "";
  9. //default locations for locally installed prettier
  10. if (["darwin", "linux"].includes(require("os").platform())) {
  11. prettierLocation = "../node_modules/.bin/prettier";
  12. } else {
  13. prettierLocation = "../node_modules/.bin/prettier.cmd";
  14. }
  15.  
  16. childProcess.exec(`"${path.resolve(path.join(__dirname, prettierLocation))}" ${prettierArgs.join(" ")}`, (error, stdout, stderr) => {
  17. if (stderr) console.log(`${stderr}`);
  18. });
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement