Skip to content

Instantly share code, notes, and snippets.

@tonylukasavage
Created November 12, 2014 13:29
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 tonylukasavage/65bbfa7a5284d5258060 to your computer and use it in GitHub Desktop.
Save tonylukasavage/65bbfa7a5284d5258060 to your computer and use it in GitHub Desktop.
implementing a node module
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