I have ported an old C# library into Node.js. Because the original source was all in separate class files, I have ended up with a bunch of custom modules (see example). Now I want to use this 'library' in a website I have build using Node.js and express. Whats the best way to deploy my 'Library' into the website folder structure/repo. I was thinking I should 'build' or combine all of these modules into a single module/file to use in the website structure. How could I do that without re-crafting it all by hand?
foo_util.js
GLOBAL.pi = function () {
return 3.142;
};
foo.js
var util = require('./foo_util');
exports.foo = function(name){
this.name = name;
};
exports.foo.prototype.SayHello = function(nextPart){
return 'Hello ' + this.name;
};
bar.js
var util = require('./foo_util');
var foo = require('./foo');
exports.bar = function(name, age){
this.name = name;
this.age = (age!=0?age:pi());
};
exports.bar.prototype = new foo.foo();
test_bar.js (nodeunit)
var foo = require('./foo');
var bar = require('./bar');
exports.SampleTest = function(Assert)
{
var target = new bar.bar('Bob', 0);
var msg = target.SayHello();
Assert.strictEqual(target.age, 3.142,"child class attribute should be set");
Assert.strictEqual(target instanceof bar.bar, true, "should be a bar");
Assert.strictEqual(target instanceof foo.foo, true, "should also be a foo");
Assert.strictEqual(msg, "Hello Bob","parent method should work");
Assert.done();
};