-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·37 lines (30 loc) · 906 Bytes
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env node
'use strict'
import htmlnorm from './lib/htmlnorm.js'
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
import { readFileSync } from 'fs'
const VERSION = JSON.parse(readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), './package.json'))).version
const USAGE = `
Safely normalize HTML for testing, semantic diffs and readability.
USAGE
htmlnorm <file>
htmlnorm --version
htmlnorm --help
If no file arg is given, stdin is used.
`
const args = process.argv.slice(2)
let file
if (args.length === 0) {
file = '/dev/stdin'
} else if (args[0] === '--help') {
process.stdout.write(USAGE)
process.exit(0)
} else if (args[0] === '--version') {
process.stdout.write('htmlnorm ' + VERSION + '\n')
process.exit(0)
} else {
file = args[0]
}
const result = htmlnorm(readFileSync(file, 'utf8'))
process.stdout.write(result)