-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaa
executable file
·124 lines (98 loc) · 3.72 KB
/
aa
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env node
var program = require("commander");
const analyzeModule = require("./lib/analyze.js");
const nodeOs = require("os");
const nodePath = require("path");
const package = require("./package");
var logger = new function() {
this.showLogs = true;
this.warnings = false;
this.log = function() {
if (this.showLogs) {
console.log.apply(this, arguments);
}
};
this.warn = function() {
if (this.warnings) {
console.warn.apply(this, arguments);
}
};
}();
const defaultName = "ASP-Analysis";
const defaultDirectory = ".";
const defaultOutput = "Desktop/asp-analyze";
program
.version(package.version)
.option("-n, --analysisName <name>", "optional name for analysis. defaults to " + defaultName, defaultName)
.option("-o, --outputDir <dir>", "optional directory for output. defaults to ~/" + defaultOutput, getOutputDir , getOutputDir(defaultOutput))
.option("-s, --summary", "show summary ", true)
.option("-c, --openCsv", "open csv file on completion", false)
.option("-w, --warnings", "show warnings", false);
var compareCmd = program
.command("compare <ref1> <ref2>");
compareCmd
.option("-d,--dir <name>", "directory to analyze. defaults to " + defaultDirectory,defaultDirectory)
.description("compare two scans")
.action((arg1,arg2)=>{compare(arg1,arg2);});
//DEFINE SCAN
var scanCmd = program
.command("scan [dir]");
scanCmd
.option("-k, --kpi", "output the kpi as a json object. This will hide warnings.")
.description("scan and analyze directory")
.action((args)=>{scan(args);});
program.parse(process.argv);
if (!process.argv.slice(2).length) {
program.outputHelp();
}
//console.log(program);
async function scan(scanArgs){
var pathVal = scanArgs;
if (!pathVal){
pathVal = defaultDirectory;
}
var scanCommands = scanCmd;
if (scanCommands.kpi)
logger.showLogs = false;
logger.warnings = !!program.warnings;
var analysisOpts = {
warnings : !!program.warnings,
summary : !!program.summary,
openCsv : !!program.openCsv,
analysisName : program.analysisName,
output : program.outputDir,
dir : pathVal,
kpi : scanCommands.kpi
};
var analysis = await analyzeModule({logger: logger}).startAnalyze(analysisOpts);
if (analysisOpts.kpi){
console.log(analysisOpts.kpis);
}
}
function compare(ref1,ref2){
logger.warnings = !!program.warnings;
var compareCommands = compareCmd;
var compareOpts = {
warnings : !!program.warnings,
summary : !!program.summary,
analysisName : program.analysisName,
output : program.outputDir,
dir : compareCommands.dir,
openCsv : !!program.openCsv,
before : ref1,
after : ref2
};
analyzeModule({logger: logger}).startCompare(compareOpts);
}
function getDateTimeForPath() {
var now = new Date();
return `${now.getFullYear()}.${("0" + (now.getMonth() + 1)).slice(-2)}.${("0" + now.getDate()).slice(-2)}-${("0" + now.getHours()).slice(-2)}.${("0" + now.getMinutes()).slice(-2)}.${("0" + now.getSeconds()).slice(-2)}`;
// return now.getFullYear() + "" + (now.getMonth() + 1) + "" + now.getDate() + "-" + now.getHours() + "" + now.getMinutes() + "" + now.getSeconds();
}
function getOutputDir(outputArg){
var outputVal = outputArg;
if (outputVal == defaultOutput || !outputVal){
outputVal = nodePath.join(nodeOs.homedir(),outputVal);
}
return nodePath.join(outputVal, getDateTimeForPath());
}