-
Notifications
You must be signed in to change notification settings - Fork 18
/
cli.js
81 lines (67 loc) · 1.88 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
75
76
77
78
79
80
81
#!/usr/bin/env node
'use strict';
var jfogs = require('./');
var optimist = require('optimist');
var mkdirp = require('mkdirp');
var fs = require('fs');
var path = require('path');
var util = require('util');
var colors = require('colors');
var argv = optimist
.usage('$0 input1.js [input2.js] -o output')
.alias('h', 'help')
.describe('h', 'show this help message and exit.')
.string('h')
.alias('o', 'output')
.describe('o', 'output file.')
.string('o')
.alias('t', 'type')
.describe('t', 'Encryption type. (e.g. "zero" | "reverse")')
.string('t')
.alias('b', 'breakout')
.describe('t', 'Export Variants & Function')
.boolean('b')
.alias('v', 'version')
.describe('v', 'Print version number and exit.')
.wrap(80)
.argv;
if (argv._.length < 1) {
if (argv.version) {
var json = require('./package.json');
console.log(json.name + ' ' + json.version);
return;
}
console.log(
String(function () {
/*
Usage:
#{j,yellow}#{fog,green}#{s,yellow} <input list> [options]
Options:
#{-o, --output,cyan} Output file (default STDOUT)
#{-t, --type,cyan} Encryption type (default "") e.g. "zero" | "reverse"
#{-v, --version,cyan} Output jfogs version
#{-b, --breakout,cyan} Export Variants & Function
*/
})
.replace(/[^]*\/\*!?\s*|\s*\*\/[^]*/g, '')
.replace(/#\{(.*?),(\w+)\}/g, function (all, text, color) {
return colors[color](text);
})
);
return;
}
var contents = [];
var filenames = [];
argv._.forEach(function (filename) {
filenames.push(filename);
contents.push(jfogs.obfuscate(fs.readFileSync(filename), argv));
});
var content = contents.join('\n');
if (argv.output) {
mkdirp(path.dirname(argv.output));
fs.writeFileSync(argv.output, content);
console.log(colors.green(util.format('%j jfogs output complete.', filenames)));
}
else {
console.log(content);
}