UNPKG

884 BJavaScriptView Raw
1#!/usr/bin/env node
2
3var html = require("../lib/html")
4var fs = require('fs')
5var concat = require('concat-stream')
6
7var args = process.argv.slice(0)
8// shift off node and script name
9args.shift()
10args.shift()
11
12if (args.length > 0) processFiles(args)
13else readStdin()
14
15function 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
22function 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
33function prettify(str) {
34 return html.prettyPrint(str, {indent_size: 2})
35}
36
37function prettifyFile(filename) {
38 fs.writeFileSync(filename, prettify(fs.readFileSync(filename).toString()))
39}