Skip to content

Commit

Permalink
chore(cli): upgrade commander to v8
Browse files Browse the repository at this point in the history
  • Loading branch information
nschonni committed Nov 24, 2021
1 parent e5d2821 commit 4b77475
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 33 deletions.
31 changes: 8 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"dependencies": {
"async": "3.2.2",
"chalk": "^4.1.2",
"commander": "5.1.0",
"commander": "^8.3.0",
"glob": "^7.2.0",
"node-fetch": "^2.6.2",
"parse-glob": "3.0.4",
Expand Down
22 changes: 13 additions & 9 deletions src/cli/htmlhint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { queue as asyncQueue, series as asyncSeries } from 'async'
import * as chalk from 'chalk'
import * as program from 'commander'
import { Command } from 'commander'
import { existsSync, readFileSync, statSync } from 'fs'
import * as glob from 'glob'
import { IGlob } from 'glob'
Expand All @@ -28,6 +28,8 @@ function map(val: string) {
return objMap
}

const program = new Command()

program.on('--help', () => {
console.log(' Examples:')
console.log('')
Expand Down Expand Up @@ -76,7 +78,9 @@ program
.option('--warn', 'Warn only, exit with 0')
.parse(process.argv)

if (program.list) {
const cliOptions = program.opts()

if (cliOptions.list) {
listRules()
process.exit(0)
}
Expand All @@ -88,19 +92,19 @@ if (arrTargets.length === 0) {

// init formatter
formatter.init(HTMLHint, {
nocolor: program.nocolor,
nocolor: cliOptions.nocolor,
})

const format = program.format || 'default'
const format = cliOptions.format || 'default'
if (format) {
formatter.setFormat(format)
}

hintTargets(arrTargets, {
rulesdir: program.rulesdir,
ruleset: program.rules,
rulesdir: cliOptions.rulesdir,
ruleset: cliOptions.rules,
formatter: formatter,
ignore: program.ignore,
ignore: cliOptions.ignore,
})

// list all rules
Expand Down Expand Up @@ -170,7 +174,7 @@ function hintTargets(
allHintCount: allHintCount,
time: spendTime,
})
process.exit(!program.warn && allHintCount > 0 ? 1 : 0)
process.exit(!cliOptions.warn && allHintCount > 0 ? 1 : 0)
})
}

Expand Down Expand Up @@ -244,7 +248,7 @@ function hintAllFiles(
// init ruleset
let ruleset = options.ruleset
if (ruleset === undefined) {
ruleset = getConfig(program.config, globInfo.base, formatter)
ruleset = getConfig(cliOptions.config, globInfo.base, formatter)
}

// hint queue
Expand Down

0 comments on commit 4b77475

Please sign in to comment.