#!/usr/bin/env node
"use strict";exports.__esModule=true;exports.nextLint=void 0;var _fs=require("fs");var _index=_interopRequireDefault(require("next/dist/compiled/arg/index.js"));var _path=require("path");var _chalk=_interopRequireDefault(require("chalk"));var _runLintCheck=require("../lib/eslint/runLintCheck");var _utils=require("../server/lib/utils");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}const nextLint=argv=>{const validArgs={// Types
'--help':Boolean,'--dir':[String],// Aliases
'-h':'--help','-d':'--dir'};let args;try{args=(0,_index.default)(validArgs,{argv});}catch(error){if(error.code==='ARG_UNKNOWN_OPTION'){return(0,_utils.printAndExit)(error.message,1);}throw error;}if(args['--help']){(0,_utils.printAndExit)(`
      Description
        Run ESLint on every file in specified directories. 
        If not configured, ESLint will be set up for the first time.

      Usage
        $ next lint <baseDir> [options]

      <baseDir> represents the directory of the Next.js application.
      If no directory is provided, the current directory will be used.

      Options
      -h - list this help
      -d - set directory, or directories, to run ESLint (defaults to only 'pages')
    `,0);}const baseDir=(0,_path.resolve)(args._[0]||'.');// Check if the provided directory exists
if(!(0,_fs.existsSync)(baseDir)){(0,_utils.printAndExit)(`> No such directory exists as the project root: ${baseDir}`);}const dirs=args['--dir'];const lintDirs=(dirs!=null?dirs:['pages','components','lib']).reduce((res,d)=>{const currDir=(0,_path.join)(baseDir,d);if(!(0,_fs.existsSync)(currDir))return res;res.push(currDir);return res;},[]);(0,_runLintCheck.runLintCheck)(baseDir,lintDirs).then(results=>{if(results){console.log(results);}else{console.log(_chalk.default.green('✔ No ESLint warnings or errors'));}}).catch(err=>{(0,_utils.printAndExit)(err.message);});};exports.nextLint=nextLint;
//# sourceMappingURL=next-lint.js.map