Skip to content

Instantly share code, notes, and snippets.

@A
Created November 5, 2013 19:18
Show Gist options
  • Save A/7324545 to your computer and use it in GitHub Desktop.
Save A/7324545 to your computer and use it in GitHub Desktop.
'use strict';
/**
* Module dependencies.
*/
var config = require('../lib/util').config;
var log = require('../lib/util').log(module);
var util = require('util');
var fs = require('fs');
var Clinch = require('clinch');
var rootDir = process.env.PWD;
var extend = require('shortcode-params');
// End of dependencies
var Compilation = function(params, next) {
this.defaults = {
package_name: undefined,
main: undefined,
out: undefined,
replacement: {},
strict : 'on',
inject : 'on',
cache_modules: 'on'
};
this.params = extend(this.defaults, params);
this.compile(this.params, next);
};
Compilation.prototype.compile = function(params, next) {
var clinch = new Clinch();
this.package_config = {
bundle: {
main: params.main
},
strict : params.strict,
inject : params.inject,
package_name: params.package_name,
replacement: params.replacement,
cache_modules: params.cache_modules
};
clinch.buldPackage(this.package_config, function(err, data) {
log.info('%s starts to compiling!', params.package_name);
if (err) return err;
fs.writeFileSync(params.out, data);
log.info('%s compiled!', params.package_name);
'function' === typeof next && next();
});
};
// End of Compilation.
module.exports = function(done) {
var modules = config.get('clinch');
var keys = Object.keys(modules);
var length = keys.length;
var next = function() {
--length
? null
: done();
};
for (var i = length - 1; i >= 0; i--) {
var key = keys[i];
new Compilation(modules[key], next);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment