forked from Persper/js-callgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
js-callgraph.js
executable file
·117 lines (104 loc) · 2.8 KB
/
js-callgraph.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
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
#!/usr/bin/env node
/*******************************************************************************
* Copyright (c) 2013 Max Schaefer
* Copyright (c) 2018 Persper Foundation
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0.
*******************************************************************************/
const JCG = require("./src/runner");
const ArgumentParser = require('argparse').ArgumentParser;
const fs = require('fs');
let argParser = new ArgumentParser({
addHelp: true,
description: 'Call graph generator'
});
argParser.addArgument(
['--fg'],
{
nargs: 0,
help: 'print flow graph'
}
);
argParser.addArgument(
['--cg'],
{
nargs: 0,
help: 'print call graph'
}
);
argParser.addArgument(
['--time'],
{
nargs: 0,
help: 'print timings'
}
);
argParser.addArgument(
['--strategy'],
{help: 'interprocedural propagation strategy; one of NONE, ONESHOT (default), DEMAND, and FULL (not yet implemented) '}
);
argParser.addArgument(
['--countCB'],
{
nargs: 0,
help: 'Counts the number of callbacks.'
}
);
argParser.addArgument(
['--reqJs'],
{
nargs: 0,
help: 'Make a RequireJS dependency graph.'
}
);
argParser.addArgument(
['--output'],
{
nargs: 1,
help: 'The output file name, which contains the JSON of result. (extension: .json)'
}
);
argParser.addArgument(
['--filter'],
{
nargs: 1,
help: 'The filters contains file. The syntax of filtering readable in README.md'
}
);
let r = argParser.parseKnownArgs();
const args = r[0];
const inputList = r[1];
JCG.setArgs(args);
JCG.setFiles(inputList);
if (args.filter !== null) {
let filter = [];
let filterFile = args.filter[0];
if (!fs.existsSync(filterFile)) {
console.warn('The path of filter file "' + filterFile + '" does not exists.');
} else {
let content = fs.readFileSync(filterFile, 'utf8').split(/\r?\n/);
let lineNumber = 0;
content.forEach(function (line) {
line = line.trim();
lineNumber++;
if (line.trim().length <= 1)
return;
if (!line.startsWith("#")) {
if (line.startsWith("+") || line.startsWith("-")) {
filter.push(line);
} else {
console.warn("[" + filterFile + "] Line " + lineNumber + " contains a not valid filter: " + line);
}
}
});
JCG.setFilter(filter);
}
}
JCG.setConsoleOutput(true);
/*
* The build return with a JSON of result.
*/
JCG.build();