1
1
mirror of https://github.com/theoludwig/html-w3c-validator.git synced 2024-12-08 00:45:37 +01:00

feat: add --current-working-directory option

This commit is contained in:
Théo LUDWIG 2023-08-09 15:36:05 +02:00
parent d4424036c5
commit 1ae47aa197
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B

View File

@ -1,7 +1,8 @@
import path from 'node:path' import path from 'node:path'
import fs from 'node:fs' import fs from 'node:fs'
import { Command } from 'clipanion' import { Command, Option } from 'clipanion'
import * as typanion from 'typanion'
import chalk from 'chalk' import chalk from 'chalk'
import ora from 'ora' import ora from 'ora'
import logSymbols from 'log-symbols' import logSymbols from 'log-symbols'
@ -14,8 +15,7 @@ import { table } from 'table'
import { isExistingPath } from './utils/isExistingPath.js' import { isExistingPath } from './utils/isExistingPath.js'
const CURRENT_DIRECTORY = process.cwd() export const CONFIG_FILE_NAME = '.html-w3c-validatorrc.json'
const CONFIG_FILE_NAME = '.html-w3c-validatorrc.json'
const severities = ['error', 'warning', 'info'] as const const severities = ['error', 'warning', 'info'] as const
@ -53,8 +53,17 @@ export class HTMLValidatorCommand extends Command {
'CLI for validating multiple html pages using <https://validator.w3.org/>.' 'CLI for validating multiple html pages using <https://validator.w3.org/>.'
} }
public currentWorkingDirectory = Option.String(
'--current-working-directory',
process.cwd(),
{
description: 'The current working directory.',
validator: typanion.isString()
}
)
public async execute(): Promise<number> { public async execute(): Promise<number> {
const configPath = path.join(CURRENT_DIRECTORY, CONFIG_FILE_NAME) const configPath = path.join(this.currentWorkingDirectory, CONFIG_FILE_NAME)
try { try {
if (!(await isExistingPath(configPath))) { if (!(await isExistingPath(configPath))) {
throw new Error( throw new Error(
@ -142,7 +151,7 @@ export class HTMLValidatorCommand extends Command {
...options ...options
}) })
} else if (type === 'file') { } else if (type === 'file') {
const htmlPath = path.resolve(CURRENT_DIRECTORY, data) const htmlPath = path.resolve(this.currentWorkingDirectory, data)
if (!(await isExistingPath(htmlPath))) { if (!(await isExistingPath(htmlPath))) {
throw new Error( throw new Error(
`No file found at "${htmlPath}". Please check the path.` `No file found at "${htmlPath}". Please check the path.`