requisite
Version:
A cosmic javascript bundler.
137 lines (116 loc) • 4.2 kB
JavaScript
// Generated by CoffeeScript 1.10.0
var Define, Module, Prelude, Wrapper, fs, path, utils,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
fs = require('fs');
path = require('path');
Module = require('./module');
utils = require('./utils');
Wrapper = (function() {
function Wrapper() {
this.ast = utils.parse('');
this.body = this.ast.body;
}
Wrapper.prototype.walk = function(fn) {
return utils.walk(this.ast, fn);
};
Wrapper.prototype.toString = function(opts) {
return utils.codegen(this.ast, opts);
};
Wrapper.prototype.clone = function() {
return new this.constructor(this);
};
return Wrapper;
})();
Prelude = (function(superClass) {
extend(Prelude, superClass);
function Prelude(opts) {
var i, j, k, len, len1, len2, node, prelude, preludeAsync, ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7;
if (opts == null) {
opts = {};
}
this.async = (ref = opts.async) != null ? ref : true;
this.bare = (ref1 = opts.bare) != null ? ref1 : false;
this.globalRequire = (ref2 = opts.globalRequire) != null ? ref2 : false;
this.prelude = (ref3 = opts.prelude) != null ? ref3 : path.join(__dirname, 'prelude.js');
this.preludeAsync = (ref4 = opts.preludeAsync) != null ? ref4 : path.join(__dirname, 'prelude-async.js');
Prelude.__super__.constructor.call(this);
if (!this.bare) {
this.ast = utils.parse('(function (global){}.call(this, this))');
this.walk((function(_this) {
return function(node) {
if (node.type === 'BlockStatement') {
return _this.body = node.body;
}
};
})(this));
}
if (this.prelude) {
prelude = utils.parse(fs.readFileSync(this.prelude));
ref5 = prelude.body;
for (i = 0, len = ref5.length; i < len; i++) {
node = ref5[i];
this.body.push(node);
}
if (this.async) {
preludeAsync = utils.parse(fs.readFileSync(this.preludeAsync));
ref6 = preludeAsync.body;
for (j = 0, len1 = ref6.length; j < len1; j++) {
node = ref6[j];
this.body.push(node);
}
}
if (this.globalRequire) {
ref7 = (utils.parse("global.require = require")).body;
for (k = 0, len2 = ref7.length; k < len2; k++) {
node = ref7[k];
this.body.push(node);
}
}
}
}
return Prelude;
})(Wrapper);
Define = (function(superClass) {
extend(Define, superClass);
function Define(opts) {
var absolutePath, async, defineType, normalizedPath, ref, ref1, ref2, ref3, ref4, relativePath, requireAs, sourcePath, strict, useStrict;
if (opts == null) {
opts = {};
}
absolutePath = (ref = opts.absolutePath) != null ? ref : '';
normalizedPath = opts.normalizedPath;
relativePath = opts.relativePath;
requireAs = (ref1 = opts.requireAs) != null ? ref1 : '';
async = (ref2 = opts.async) != null ? ref2 : false;
strict = (ref3 = opts.strict) != null ? ref3 : false;
if (async) {
defineType = 'async';
requireAs = path.join(opts.urlRoot, requireAs);
} else {
defineType = 'define';
}
if (strict) {
useStrict = "'use strict';";
} else {
useStrict = '';
}
requireAs = requireAs.replace(/\\/g, '\\\\');
sourcePath = (ref4 = relativePath != null ? relativePath : normalizedPath) != null ? ref4 : absolutePath;
this.ast = utils.parse("// source: " + sourcePath + "\nrequire." + defineType + "(\"" + requireAs + "\", function(module, exports, __dirname, __filename) {\n " + useStrict + "\n});");
this.walk((function(_this) {
return function(node) {
if (node.type === 'BlockStatement') {
return _this.body = node.body;
}
};
})(this));
}
return Define;
})(Wrapper);
module.exports = {
Define: Define,
Prelude: Prelude,
Wrapper: Wrapper
};
//# sourceMappingURL=wrapper.js.map