UNPKG

1.05 kBJavaScriptView Raw
1#!/usr/bin/env node
2/*eslint no-process-exit: 0 */
3'use strict';
4
5var fs = require('fs'),
6 path = require('path'),
7 read = require('read-file-stdin'),
8 write = require('write-file-stdout'),
9 rucksack = require('../'),
10 opts = require('minimist');
11
12// Set shorthand aliases for options
13opts = opts(process.argv.slice(2), {
14 boolean: [
15 'autoprefixer',
16 'fallbacks'
17 ],
18 alias: {
19 h: 'help',
20 s: 'sourcemap',
21 v: 'version'
22 }
23});
24
25var file = opts._[0],
26 out = opts._[1];
27
28// Fetch verion from package.json
29if (opts.version) {
30 return console.log(require('../package.json').version);
31}
32
33// Pipe out help doc from help.txt
34if (file === 'help' || opts.help) {
35 return fs.createReadStream(path.join(__dirname, '/help.txt'))
36 .pipe(process.stdout)
37 .on('close', function() {
38 process.exit(1);
39 });
40}
41
42read(file, function(err, buf) {
43
44 if (err) {
45 throw err;
46 }
47
48 if (file) {
49 opts.from = file;
50 }
51
52 if (out) {
53 opts.to = out;
54 }
55
56 write(out, rucksack.process(String(buf), opts));
57
58});