diff --git a/package.json b/package.json index 0cbc7cf..98d1d4d 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "scripts": { "build": "npm run features && npm run ts-node -- ./scripts/build/build.ts", "build:raw": "npm run build -- --no-uglify", - "code-linter": "eslint --cache --ext .js,.ts", "features": "ts-node -- ./scripts/genFeatures.ts --files ./features.json -d", "fix": "npm run lint -- --fix", "fix:code": "npm run lint -- --fix --code", diff --git a/scripts/lint.ts b/scripts/lint.ts index 895062c..f90e59f 100644 --- a/scripts/lint.ts +++ b/scripts/lint.ts @@ -1,39 +1,49 @@ import commandLineArgs from 'command-line-args'; import colors from 'chalk'; -import { processCommands, FailedCommandData } from './utils/proc'; +import { execSync } from 'child_process'; const options = commandLineArgs([ { name: 'fix', type: Boolean }, - { name: 'typecheck', type: Boolean }, + { name: 'typecheck', type: String }, { name: 'code', type: Boolean }, { name: 'prettier', type: Boolean }, { name: 'files', type: String }, ]); -const commands = (files: string, fix: boolean) => ({ - typecheck: 'tsc', - prettier: `prettier ${fix ? '--write --list-different' : '--check'} ${ - files || '"./**/*.{ts,js,tsx}"' - }`, - code: `npm run code-linter -- ${fix ? '--fix' : ''} ${files || '.'}`, -}); +const processCommand = (command: string) => { + console.log(colors.cyan(`\nπŸ‘€ ${command}\n`)); + execSync(command, { stdio: 'inherit' }); +}; -async function main() { +function main() { const optionsCount = Object.keys(options).length; const shouldRunAll = (options.fix && optionsCount === 1) || optionsCount === 0; - const commandsMap = commands(options.files, options.fix); - const commandsToExecute = Object.entries(commandsMap) - .filter(([key, command]) => options[key] || shouldRunAll) - .map(([key, command]) => command); - - await processCommands(commandsToExecute).catch( - ({ exitCode }: FailedCommandData = {}) => { - if (exitCode) { - process.exit(exitCode); - } - }, - ); + const { typecheck, prettier, code, fix, files } = options; + + if (typecheck !== undefined || shouldRunAll) { + const project = options.typecheck || 'tsconfig.json'; + const tscCommand = `tsc --project ${project}`; + processCommand(tscCommand); + } + + if (prettier || shouldRunAll) { + const prettierOptions = fix ? '--write --list-different' : '--check'; + const pattern = files || '"./**/*.{ts,js,tsx}"'; + const prettierCommand = `prettier ${prettierOptions} ${pattern}`; + processCommand(prettierCommand); + } + + if (code || shouldRunAll) { + const eslintOptions = [ + '--cache', + '--ext .js,.ts', + ...(fix ? ['--fix'] : []), + ].join(' '); + const pattern = files || '.'; + const eslintCommand = `eslint ${eslintOptions} ${pattern}`; + processCommand(eslintCommand); + } console.log(colors.greenBright('Success!\n')); } diff --git a/src/utils/object/path.ts b/src/utils/object/path.ts index 92a0878..bf31938 100644 --- a/src/utils/object/path.ts +++ b/src/utils/object/path.ts @@ -53,7 +53,9 @@ type CtxPath = { * @type function(...?): ? */ export const ctxPath: CtxPath = curry2SwapArgs(getPath) as CtxPath; -export const len = ctxPath('length'); +export const len = ctxPath('length') as ( + obj: T, // eslint-disable-line no-use-before-define +) => T extends ArrayLike ? number : unknown; /** * ΠŸΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ ΠΈΠ· списка [1,2,3] ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ {1: {2: 3}}