Skip to content

Commit 9a85e7f

Browse files
gaborantalUltimateBeaver
authored andcommitted
Added directory based analysis, handled empty input
1 parent 54a8639 commit 9a85e7f

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ node src/main.js -h # for a list of command line arguments
1212
1313
# Running on simple input scripts
1414
node src/main.js --cg input-scripts/simple-scripts/functioncall-arithmetic.js
15+
16+
# Running on a whole directory
17+
node src/main.js --cg input-scripts/fullcalendar/
18+
19+
# Running on mixed input
20+
node src/main.js --cg input-scripts/fullcalendar/fullcalendar/ input-scripts/fullcalendar/lib/jquery-2.1.0.js
1521
```
1622

1723
## Running Tests

src/main.js

+30-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ var bindings = require('./bindings'),
1515
diagnostics = require('./diagnostics'),
1616
callbackCounter = require('./callbackCounter'),
1717
requireJsGraph = require('./requireJsGraph'),
18-
ArgumentParser = require('argparse').ArgumentParser;
18+
ArgumentParser = require('argparse').ArgumentParser,
19+
path = require('path'),
20+
fs = require('fs'),
21+
utils = require('./utils');
1922

2023
var argParser = new ArgumentParser({
2124
addHelp: true,
@@ -59,9 +62,32 @@ argParser.addArgument(
5962
}
6063
);
6164

62-
var r = argParser.parseKnownArgs();
63-
var args = r[0],
64-
files = r[1];
65+
const r = argParser.parseKnownArgs();
66+
const args = r[0];
67+
const inputList = r[1];
68+
69+
let filelist = [];
70+
71+
inputList.forEach(function (file) {
72+
file = path.resolve(file);
73+
if (!fs.existsSync(file)) {
74+
console.warn('The path "' + file + '" does not exists.');
75+
}
76+
else if (fs.statSync(file).isDirectory()) {
77+
filelist = utils.collectFiles(file, filelist);
78+
}
79+
else if (file.endsWith(".js")) {
80+
filelist.push(file);
81+
}
82+
});
83+
84+
let files = Array.from(new Set(filelist)); // remove the duplicates
85+
86+
if (files.length === 0) {
87+
console.warn("Input file list is empty!");
88+
argParser.printHelp();
89+
process.exit(-1);
90+
}
6591

6692
args.strategy = args.strategy || 'ONESHOT';
6793
if (!args.strategy.match(/^(NONE|ONESHOT|DEMAND|FULL)$/)) {

src/utils.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
/**
5+
* Collect all the files in the given directory, recursively
6+
*/
7+
function collectFiles(dir, filelist) {
8+
let files = fs.readdirSync(dir);
9+
filelist = filelist || [];
10+
files.forEach(function (file) {
11+
if (fs.statSync(path.join(dir, file)).isDirectory()) {
12+
filelist = collectFiles(path.join(dir, file), filelist);
13+
}
14+
else if (file.endsWith(".js")) {
15+
filelist.push(path.join(dir, file));
16+
}
17+
});
18+
return filelist;
19+
}
20+
21+
module.exports.collectFiles = collectFiles;

0 commit comments

Comments
 (0)