1 | #!/usr/bin/env node
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | var fs = require('fs');
|
6 | var argv = require('minimist')(process.argv.slice(2), {
|
7 | alias: {
|
8 | properties: ['p', 'props']
|
9 | },
|
10 | default: {
|
11 | properties: []
|
12 | }
|
13 | });
|
14 | var stdin = require('get-stdin');
|
15 | var apartment = require('..');
|
16 | var ok;
|
17 |
|
18 | if (typeof argv.properties === 'string') {
|
19 | argv.p = argv.props = argv.properties = argv.properties.split(',');
|
20 | }
|
21 |
|
22 | if (argv._.length) {
|
23 | go(read(argv._[0]));
|
24 | } else {
|
25 | stdin().then(go);
|
26 | setTimeout(die, 100);
|
27 | }
|
28 |
|
29 | function read (file) {
|
30 | return fs.readFileSync(file, { encoding: 'utf8' });
|
31 | }
|
32 |
|
33 | function go (data) {
|
34 | ok = true;
|
35 | var diff = apartment(data, argv);
|
36 | process.stdout.write(diff);
|
37 | process.exit();
|
38 | }
|
39 |
|
40 | function 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 | }
|