Created
January 13, 2023 07:59
-
-
Save ruvasik/9cc0e2675b41c057c0575308c6fc70b8 to your computer and use it in GitHub Desktop.
NPM utility for run check/format code in folder with eslint/prettier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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