-
Notifications
You must be signed in to change notification settings - Fork 12
/
cli.js
74 lines (64 loc) · 2.27 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env node
'use strict';
var argv = require('minimist')(process.argv.slice(2), {
alias: {
i: 'id',
d: 'domain',
g: ['global', 'globalName'],
w: 'double',
m: 'minify',
c: 'color',
s: ['script-tag', 'scriptTag'],
t: 'track',
h: 'help',
v: 'version'
},
string: ['_', 'id', 'domain', 'g', 'global'],
boolean: ['minify', 'color', 'help', 'version']
});
var chalk = require('chalk');
if (argv.version) {
console.log(require('./package.json').version);
} else if (argv.help) {
var sumUp = require('sum-up');
var yellow = chalk.yellow;
var pkg = require('./package.json');
console.log([
sumUp(pkg),
'',
'Usage: ' + pkg.name + ' <parameters> [options]',
'',
'Options:',
yellow('--id, -i <ID> ') + ' Set web property ID',
yellow('--domain, -d <domain>') + ' Set domain',
yellow('--global, -g <name> ') + ' Change global variable name ("ga" by default)',
yellow('--minify, -m ') + ' Minify output like UglifyJS',
yellow('--double, -w ') + ' Use double quotes (single quotes by default)',
yellow('--no-color, ') + ' Print code in a single color',
yellow('--color, -c ') + ' Colorize parameters anyway (enabled by default)',
yellow('--no-track, ') + ' Just load, don\'t send a pageview',
yellow('--track, -t ') + ' Send a pageview after loading (enabled by default)',
yellow('--no-script-tag, ') + ' Just print the JS code without any HTML',
yellow('--script-tag, -s ') + ' Include <script> tag in output (disabled by default)',
yellow('--help, -h ') + ' Print usage information',
yellow('--version, -v ') + ' Print version',
''
].join('\n'));
} else {
argv.color = argv.color || (chalk.supportsColor && !argv['no-color']);
argv.singleQuotes = !argv.double;
var isogram = require('./');
try {
var code;
if (argv._.length === 0) {
code = isogram.apply(null, [argv]);
} else {
code = isogram.apply(null, [argv._[0], argv]);
}
console.log(code);
} catch (e) {
process.stderr.write(e.message + '\n', function() {
process.exit(1);
});
}
}