UNPKG

955 BPlain TextView Raw
1#!/usr/bin/env node
2
3'use strict';
4
5var fs = require('fs');
6var argv = require('minimist')(process.argv.slice(2), {
7 alias: {
8 properties: ['p', 'props']
9 },
10 default: {
11 properties: []
12 }
13});
14var stdin = require('get-stdin');
15var apartment = require('..');
16var ok;
17
18if (typeof argv.properties === 'string') {
19 argv.p = argv.props = argv.properties = argv.properties.split(',');
20}
21
22if (argv._.length) {
23 go(read(argv._[0]));
24} else {
25 stdin().then(go);
26 setTimeout(die, 100);
27}
28
29function read (file) {
30 return fs.readFileSync(file, { encoding: 'utf8' });
31}
32
33function go (data) {
34 ok = true;
35 var diff = apartment(data, argv);
36 process.stdout.write(diff);
37 process.exit();
38}
39
40function die () {
41 if (ok) {
42 return;
43 }
44 console.log([
45 'usage:',
46 ' apartment <file> [OPTIONS]',
47 ' --properties <props>, a comma-separated list of properties to remove',
48 'result:',
49 ' <diff>'
50 ].join('\n'));
51 process.exit();
52}