source: imaps-frontend/node_modules/flat/cli.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100755
File size: 895 bytes
Line 
1#!/usr/bin/env node
2
3const fs = require('fs')
4const path = require('path')
5const readline = require('readline')
6
7const flat = require('./index')
8
9const filepath = process.argv.slice(2)[0]
10if (filepath) {
11 // Read from file
12 const file = path.resolve(process.cwd(), filepath)
13 fs.accessSync(file, fs.constants.R_OK) // allow to throw if not readable
14 out(require(file))
15} else if (process.stdin.isTTY) {
16 usage(0)
17} else {
18 // Read from newline-delimited STDIN
19 const lines = []
20 readline.createInterface({
21 input: process.stdin,
22 output: process.stdout,
23 terminal: false
24 })
25 .on('line', line => lines.push(line))
26 .on('close', () => out(JSON.parse(lines.join('\n'))))
27}
28
29function out (data) {
30 process.stdout.write(JSON.stringify(flat(data), null, 2))
31}
32
33function usage (code) {
34 console.log(`
35Usage:
36
37flat foo.json
38cat foo.json | flat
39`)
40
41 process.exit(code || 0)
42}
Note: See TracBrowser for help on using the repository browser.