requisite
Version:
A cosmic javascript bundler.
133 lines (112 loc) • 3.95 kB
JavaScript
// Generated by CoffeeScript 1.7.1
var Define, Module, Prelude, Wrapper, fs, path, utils,
__hasProp = {}.hasOwnProperty,
__extends = 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; };
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(_super) {
__extends(Prelude, _super);
function Prelude(opts) {
var node, prelude, preludeAsync, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6;
if (opts == null) {
opts = {};
}
this.async = (_ref = opts.async) != null ? _ref : true;
this.globalRequire = (_ref1 = opts.globalRequire) != null ? _ref1 : false;
this.prelude = (_ref2 = opts.prelude) != null ? _ref2 : path.join(__dirname, 'prelude.js');
this.preludeAsync = (_ref3 = opts.preludeAsync) != null ? _ref3 : 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));
_ref4 = prelude.body;
for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
node = _ref4[_i];
this.body.push(node);
}
if (this.async) {
preludeAsync = utils.parse(fs.readFileSync(this.preludeAsync));
_ref5 = preludeAsync.body;
for (_j = 0, _len1 = _ref5.length; _j < _len1; _j++) {
node = _ref5[_j];
this.body.push(node);
}
}
if (this.globalRequire) {
_ref6 = (utils.parse("global.require = require")).body;
for (_k = 0, _len2 = _ref6.length; _k < _len2; _k++) {
node = _ref6[_k];
this.body.push(node);
}
}
}
}
return Prelude;
})(Wrapper);
Define = (function(_super) {
__extends(Define, _super);
function Define(opts) {
var absolutePath, async, defineType, requireAs, strict, useStrict, _ref, _ref1, _ref2, _ref3;
if (opts == null) {
opts = {};
}
absolutePath = (_ref = opts.absolutePath) != null ? _ref : '';
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, '\\\\');
this.ast = utils.parse("// source: " + absolutePath + "\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.map