-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
71 lines (60 loc) · 1.55 KB
/
main.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
#!/usr/bin/env ringo
load('peruse.js');
function main(args) {
var fs = require('fs');
var system = require('system');
var args = {
debug: false,
fix: false,
fileName: ''
};
var source;
// Get command arguments
for (var i = 0; i < system.args.length; i++) {
// Get file names
if (system.args[i].indexOf('-file=') > -1) {
args.fileName = system.args[i].replace('-file=', '');
if (args.fileName.indexOf(';') == -1) {
args.fileName = [args.fileName];
} else {
args.fileName = args.fileName.split(';');
}
}
// Get boolean flags
getArg(system.args[i], 'fix');
getArg(system.args[i], 'debug');
getArg(system.args[i], 'prefix');
getArg(system.args[i], 'nestedPrefix');
}
// Check each file
var fileNameLength = args.fileName.length;
for (var i = 0; i < fileNameLength; i++) {
var code = fs.open(args.fileName[i]).read();
var results = peruse.checkCode(
code,
args.fileName[i],
args
);
// Save fixes
if (results.summary.fixedCount > 0) {
fs.write(args.fileName[i] + '.bak', code);
fs.write(args.fileName[i], results.codeFixed);
}
}
function getArg(str, flag) {
if (str.indexOf('-' + flag + '=') > -1) {
var value = str.replace('-' + flag + '=', '');
if (value == 'true') {
args[flag] = true;
} else if (value == 'false') {
args[flag] = false;
} else {
args[flag] = value;
}
}
}
}
// main script to start application
if (require.main == module) {
main();
}