Skip to content

Instantly share code, notes, and snippets.

@KazChe
Created March 1, 2014 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KazChe/9288874 to your computer and use it in GitHub Desktop.
Save KazChe/9288874 to your computer and use it in GitHub Desktop.
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