Created
March 1, 2014 12:00
-
-
Save KazChe/9288874 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"), | |
path = require("path"), | |
p = "/some-app/webapp/WEB-INF/jsp", | |
files, | |
result = { | |
"name": null, | |
"type": null, | |
"location": null | |
}, | |
allResults = new Array(); | |
var getReader = function readDir(dirName) { | |
files = fs.readdirSync(dirName); | |
files.map(function (file) { | |
return path.join(dirName, file); | |
}).forEach(function (file) { | |
var factory = new ResultItemFactory(); | |
var resultItem = factory.createResultItem({ | |
"name": file.replace(/^.*[\\\/]/, ''), | |
"location": dirName, | |
"type": path.extname(file) ? "<FILE>" : "<DIRECTORY>" | |
}) | |
allResults.push(resultItem); | |
}); | |
console.log(allResults) | |
return allResults; | |
} | |
function ResultItemFactory() { | |
ResultItemFactory.prototype.resultItem = ResultItem; | |
ResultItemFactory.prototype.createResultItem = function(options) { | |
this.resultItem.name = options.name; | |
this.resultItem.location = options.location; | |
this.resultItem.type = options.type | |
return new this.resultItem(options); | |
} | |
} | |
function ResultItem(options) { | |
this.location = options.location; | |
this.name = options.name; | |
this.type = options.type; | |
} | |
exports.getReader = getReader; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment