Skip to content

Instantly share code, notes, and snippets.

@ruvasik
Created January 13, 2023 07:59
Show Gist options
  • Save ruvasik/9cc0e2675b41c057c0575308c6fc70b8 to your computer and use it in GitHub Desktop.
Save ruvasik/9cc0e2675b41c057c0575308c6fc70b8 to your computer and use it in GitHub Desktop.
NPM utility for run check/format code in folder with eslint/prettier
const execSync = require("child_process").execSync;
const fs = require("fs");
const path = process.argv[3] || 'src/';
const args = Array.prototype.slice.call( process.argv, 4 ).join(' ');
if (!fs.existsSync(path))
throw new Error(`Not found ${path}`);
switch (process.argv[2]) {
case "check":
execSync(`npx next lint --dir ${path} ${args}`, {stdio: 'inherit'});
execSync(`npx prettier -c ${path} ${args}`, {stdio: 'inherit'});
break;
case "format":
execSync(`npx next lint --fix --dir ${path} ${args}`, {stdio: 'inherit'});
execSync(`npx prettier -w ${path} ${args}`, {stdio: 'inherit'});
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment