My goal is to distribute a module across various component manager systems like npmjs and bower. I also want to provide downloadable builds in different styles such as AMD for requirejs, commonJS, and a global namespace version for browsers - all minified. This amounts to more than 10 different builds.
Currently, I have an AMD build along with unit tests written using karma, jasmine, and requirejs in an AMD style. I am seeking advice on how to generate the other builds as well as write tests for them.
I am unsure about the base of transformations required for each build. Each output package has a common part and a package-specific part.
In terms of AMD - requirejs (uncertain about the config options)
define(["module", "dependency"], function (module, dependency) {
var m = {
config: function (options){
//...
},
//...
//do something with the dependency
};
m.config(module.config()); //load config options set by require.config()
return m;
});
For commonJS
var dependency = require("dependency");
module.exports = {
config: function (options){
//...
},
//...
//do something with the dependency
};
When it comes to the global version
var m = (function (){
return {
config: function (options){
//...
},
//...
//do something with the dependency
};
})(dependency);
I'm torn between developing a common codebase and building it before every test, or developing one specific package, testing it, and then transforming it into the other builds?
I plan on using gulp to automate the creation of builds and run unit tests before publishing. Additionally, I would like an automatic version number update feature. Do you think running unit tests after the build process is necessary to ensure bug-free code is published?