1 | #!/usr/bin/env node
|
2 |
|
3 | var html = require("../lib/html")
|
4 | var fs = require('fs')
|
5 | var concat = require('concat-stream')
|
6 |
|
7 | var args = process.argv.slice(0)
|
8 |
|
9 | args.shift()
|
10 | args.shift()
|
11 |
|
12 | if (args.length > 0) processFiles(args)
|
13 | else readStdin()
|
14 |
|
15 | function readStdin() {
|
16 | var stdin = process.openStdin()
|
17 | stdin.pipe(concat(function concatted (buff) {
|
18 | process.stdout.write(html.prettyPrint(buff.toString(), {indent_size: 2}))
|
19 | }))
|
20 | }
|
21 |
|
22 | function processFiles(files) {
|
23 | if (files.length > 1) {
|
24 | files.map(function(filename) {
|
25 | prettifyFile(filename)
|
26 | })
|
27 | return
|
28 | }
|
29 | var str = fs.readFileSync(files[0]).toString()
|
30 | process.stdout.write(prettify(str))
|
31 | }
|
32 |
|
33 | function prettify(str) {
|
34 | return html.prettyPrint(str, {indent_size: 2})
|
35 | }
|
36 |
|
37 | function prettifyFile(filename) {
|
38 | fs.writeFileSync(filename, prettify(fs.readFileSync(filename).toString()))
|
39 | }
|