Created
November 12, 2014 13:29
-
-
Save tonylukasavage/65bbfa7a5284d5258060 to your computer and use it in GitHub Desktop.
implementing a node module
This file contains hidden or 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 format = require('util').format, | |
fs = require('fs'), | |
path = require('path'); | |
var code = '', testCode = '', | |
test = fs.readFileSync(path.join(__dirname, 'test', 'app_src.js'), 'utf8'), | |
template = 'exports.%s = function %s%s {\n' + | |
'\tthrow new Error(\'%s not yet implemented\');\n' + | |
'};\n\n', | |
testTemplate = '\tit(\'#%s\', function() {\n' + | |
'\t\t(function() { fs.%s(); }).should.throw(/implemented/);\n' + | |
'\t});\n\n'; | |
Object.keys(fs).forEach(function(func) { | |
var sig = fs[func].toString().match(/(\([^\)]*\))/)[1]; | |
code += format(template, func, func, sig, func); | |
testCode += format(testTemplate, func, func); | |
}); | |
fs.writeFileSync(path.join(__dirname, 'src', 'ti-fs.js'), code); | |
fs.writeFileSync(path.join(__dirname, 'test', 'app.js'), format(test, testCode)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment