adventure-runner
Advanced tools
Comparing version 1.0.0 to 2.0.0
65
index.js
'use strict'; | ||
var fs = require('fs'), | ||
path = require('path'), | ||
adventure = require('adventure'); | ||
path = require('path'), | ||
adventure = require('adventure'), | ||
caller = path.dirname(require('caller')()); | ||
module.exports = function (name, problems) { | ||
var getDirectories = function(srcpath) { | ||
if(! fs.existsSync(srcpath)) { | ||
throw new Error(srcpath || 'srcpath' + ' not found!'); | ||
} | ||
return fs.readdirSync(srcpath).filter(function(file) { | ||
return fs.statSync(path.join(srcpath, file)).isDirectory(); | ||
}); | ||
}; | ||
if (typeof name !== 'string') { | ||
throw new TypeError('Expected a string'); | ||
} | ||
var requireProblems = function (problems, root) { | ||
root = root || './problems/'; | ||
var advent = adventure(name); | ||
problems.forEach(function(prob){ | ||
console.log(advent); | ||
advent.add(prob, function () { | ||
return require(path.join(root + prob)); | ||
}); | ||
}); | ||
advent.execute(process.argv.slice(2)); | ||
}; | ||
if (problems instanceof Array) { | ||
if(! fs.existsSync('./problems')) { | ||
throw new Error('./problems dir not found!'); | ||
} | ||
requireProblems(problems); | ||
} else { | ||
requireProblems(getDirectories(problems),problems); | ||
var getDirectories = function (srcpath) { | ||
if (!fs.existsSync(srcpath)) { | ||
throw new Error(srcpath || 'srcpath' + ' not found!'); | ||
} | ||
return fs.readdirSync(srcpath).filter(function (file) { | ||
return fs.statSync(path.join(srcpath, file)).isDirectory(); | ||
}); | ||
}; | ||
if (typeof name !== 'string') { | ||
throw new TypeError('Expected a string'); | ||
} | ||
var requireProblems = function (problems, root) { | ||
root = root || path.join(caller, 'problems/'); | ||
var advent = adventure(name); | ||
problems.forEach(function (prob) { | ||
advent.add(prob, function () { | ||
return require(path.join(root + prob)); | ||
}); | ||
}); | ||
advent.execute(process.argv.slice(2)); | ||
}; | ||
if (problems instanceof Array) { | ||
requireProblems(problems); | ||
} else { | ||
requireProblems(getDirectories(path.join(caller, problems))); | ||
} | ||
}; |
{ | ||
"name": "adventure-runner", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Runner util for nodeschool adventures", | ||
@@ -26,4 +26,5 @@ "license": "MIT", | ||
"dependencies": { | ||
"adventure": "^2.10.0" | ||
"adventure": "^2.10.0", | ||
"caller": "^1.0.0" | ||
} | ||
} |
3751
2
33
+ Addedcaller@^1.0.0
+ Addedcaller@1.1.0(transitive)