Skip to content

Commit 8585c3b

Browse files
committed
Add directory skipping option for cli
1 parent 0b6c9b1 commit 8585c3b

File tree

5 files changed

+59
-21
lines changed

5 files changed

+59
-21
lines changed

bin/jscr.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ var fs = require('fs'),
1111

1212

1313
argvParser.parse(process.argv)
14-
.then(argvParser.getTargetedTree)
15-
.then(crawlComplexity)
14+
15+
.then(argvParser.getSpec)
16+
.then(function(specs){
17+
var path = specs.targetedTree;
18+
return crawlComplexity(path, specs);
19+
})
1620
.then(function(data){
1721

18-
var filename = argvParser.getOutputName(),
22+
var filename = argvParser.getOutputFileName(),
1923
html = generateHTML(data.report)
2024

2125
return writeFile(filename, html);
2226

2327
})
24-
2528
.then(function(){
2629
process.exit(0);
2730
})

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function(srcDir){
1+
module.exports = function(srcDir, options){
22

33
var crawlComplexity = require('./src/crawl-complexity');
44

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"type": "git",
88
"url": "https://github.com/slyg/jscomplexity.git"
99
},
10-
"version": "0.0.14",
10+
"version": "0.0.15",
1111
"preferGlobal": "true",
1212
"bin": {
1313
"jscr": "./bin/jscr.js"

src/argv-parser.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
11
var program = require('commander'),
22
Promise = require('bluebird');
33

4-
var pjson = require('../package.json');
5-
6-
var targetedTree = './',
7-
outputName = 'jscomplexityreport.html',
8-
optionsHandler = {};
4+
var pjson = require('../package.json'),
5+
options = {
6+
targetedTree : './',
7+
getOutputFileName : 'jscr-report.html',
8+
skippedDirectories : []
9+
};
910

1011
program
1112
.version(pjson.version)
12-
.usage('[<folder to analyse ...>] [options]');
13+
.usage('[options] [<folder to analyse ...>]');
1314

1415
program
1516
.command('*')
1617
.action(function(target){
17-
targetedTree = target;
18+
options.targetedTree = target;
19+
});
20+
21+
program
22+
.option('-e, --exclude [folder]', 'exclude folders', function(folder){
23+
options.skippedDirectories = folder.split(',');
1824
});
1925

2026
module.exports.parse = function(argv){
2127
return new Promise(function (resolve) {
2228
program.parse(argv);
23-
resolve(targetedTree);
29+
resolve(options.targetedTree);
2430
});
2531
};
2632

33+
module.exports.getSpec = function(){
34+
return options;
35+
};
36+
2737
module.exports.getTargetedTree = function(){
28-
return targetedTree;
38+
return options.targetedTree;
2939
};
3040

31-
module.exports.getOutputName = function(){
32-
return outputName;
41+
module.exports.getOutputFileName = function(){
42+
return options.getOutputFileName;
3343
};

src/crawl-complexity.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,46 @@
123123

124124
}
125125

126+
/**
127+
*
128+
*/
129+
130+
function formatOptions(rawOptions){
131+
132+
var formattedOptions = {
133+
followLinks: false
134+
};
135+
136+
if(rawOptions){
137+
138+
if(
139+
rawOptions.skippedDirectories
140+
&& rawOptions.skippedDirectories.length > 0
141+
) {
142+
formattedOptions.filters = rawOptions.skippedDirectories;
143+
}
144+
145+
}
146+
147+
return formattedOptions;
148+
}
149+
126150
/**
127151
* builds a complexity report of .js files
128152
* found in a file tree from a given path
129153
*
130154
* returns a Promise
131155
* rejects promise if any runtime error occurs
132156
*/
133-
function buildFinalReport(path){
157+
function crawlComplexity(path, options){
134158

135159
var
136160
reportList = [],
137161
errorsList = null,
138-
walker = walk.walk(path),
139162
resolver = Promise.defer()
140-
;
163+
;
164+
165+
walker = walk.walk(path, formatOptions(options));
141166

142167
walker
143168
.on("file", populateReportList(errorsList, reportList))
@@ -154,4 +179,4 @@
154179

155180
}
156181

157-
module.exports = buildFinalReport;
182+
module.exports = crawlComplexity;

0 commit comments

Comments
 (0)