UNPKG

1.42 kBPlain TextView Raw
1#!/usr/bin/env node
2
3var RSG = require('../lib/rsg')
4var argv = require('minimist')(process.argv.slice(2))
5
6var GRAY_COLOR = '\u001b[90m'
7var MAGENTA_COLOR = '\u001b[35m'
8var RESET_COLOR = '\u001b[0m'
9
10!(function () {
11 if (!argv._[0] || argv.h || argv.help) {
12 return require('fs').createReadStream(require('path').resolve(__dirname, 'usage.txt'))
13 .pipe(process.stdout)
14 .on('close', function () { process.exit(1) })
15 }
16
17 if (argv.V || argv.version) {
18 return console.log(require('../package.json').version)
19 }
20
21 var opts = {
22 output: argv.o || argv.output,
23 title: argv.t || argv.title,
24 root: argv.r || argv.root,
25 pushstate: argv.p || argv.pushstate,
26 files: argv.f || argv.files,
27 config: argv.c || argv.config
28 }
29
30 // removing falsy fields from an opts
31 Object.keys(opts).forEach(function (name) {
32 if (!opts[name]) {
33 delete opts[name]
34 }
35 })
36
37 // convert files to array
38 // 'a.js, b.js' -> ['a.js', 'b.js']
39 if (opts.files) {
40 opts.files = opts.files.split(',').map(function (part) { return part.trim() })
41 }
42
43 RSG(argv._[0], opts).generate(function (err) {
44 if (err) {
45 console.error(String(err))
46 process.exit(1)
47 }
48
49 if (argv.v || argv.verbose) {
50 var time = '[' + GRAY_COLOR + new Date().toLocaleTimeString() + RESET_COLOR + ']'
51 console.log(time, MAGENTA_COLOR + this.opts.output)
52 }
53
54 process.exit(0)
55 })
56})()