mirror of
https://github.com/theoludwig/html-w3c-validator.git
synced 2025-05-21 23:21:29 +02:00
chore: initial commit
This commit is contained in:
15
src/HTMLValidatorCommand.ts
Normal file
15
src/HTMLValidatorCommand.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { Command } from 'clipanion'
|
||||
|
||||
// const CURRENT_DIRECTORY = process.cwd()
|
||||
|
||||
export class HTMLValidatorCommand extends Command {
|
||||
static usage = {
|
||||
description:
|
||||
'CLI for validating multiple html pages using <https://validator.w3.org/>.'
|
||||
}
|
||||
|
||||
async execute(): Promise<number> {
|
||||
console.log('html-w3c-validator')
|
||||
return 0
|
||||
}
|
||||
}
|
22
src/__test__/HTMLValidatorCommand.test.ts
Normal file
22
src/__test__/HTMLValidatorCommand.test.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { cli } from '../cli.js'
|
||||
import { HTMLValidatorCommand } from '../HTMLValidatorCommand.js'
|
||||
|
||||
describe('html-w3c-validator', () => {
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it('should be instance of the command', async () => {
|
||||
const command = cli.process([])
|
||||
expect(command).toBeInstanceOf(HTMLValidatorCommand)
|
||||
})
|
||||
|
||||
it('succeeds and validate the html correctly', async () => {
|
||||
console.log = jest.fn()
|
||||
const exitCode = await cli.run([], {
|
||||
stdin: process.stdin
|
||||
})
|
||||
expect(console.log).toHaveBeenCalledWith('html-w3c-validator')
|
||||
expect(exitCode).toEqual(0)
|
||||
})
|
||||
})
|
17
src/cli.ts
Normal file
17
src/cli.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import path from 'node:path'
|
||||
|
||||
import { Builtins, Cli } from 'clipanion'
|
||||
import readPackage from 'read-pkg'
|
||||
|
||||
import { HTMLValidatorCommand } from './HTMLValidatorCommand.js'
|
||||
|
||||
const packageJSON = readPackage.sync({ cwd: path.join(__dirname, '..') })
|
||||
|
||||
export const cli = new Cli({
|
||||
binaryLabel: packageJSON.name,
|
||||
binaryName: packageJSON.name,
|
||||
binaryVersion: packageJSON.version
|
||||
})
|
||||
cli.register(Builtins.HelpCommand)
|
||||
cli.register(Builtins.VersionCommand)
|
||||
cli.register(HTMLValidatorCommand)
|
12
src/index.ts
Normal file
12
src/index.ts
Normal file
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env node
|
||||
import chalk from 'chalk'
|
||||
import { Cli } from 'clipanion'
|
||||
|
||||
import { cli } from './cli.js'
|
||||
|
||||
const [, , ...arguments_] = process.argv
|
||||
|
||||
cli.runExit(arguments_, Cli.defaultContext).catch(() => {
|
||||
console.error(chalk.red('Error occurred...'))
|
||||
process.exit(1)
|
||||
})
|
Reference in New Issue
Block a user