UNPKG

requisite

Version:
141 lines (118 loc) 4.25 kB
// Generated by CoffeeScript 1.12.4 var Define, Module, Prelude, Wrapper, codegen, fs, parse, path, walk, 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'); codegen = require('./codegen'); parse = require('./parse'); walk = require('./walk'); Wrapper = (function() { function Wrapper() { this.ast = parse(''); this.body = this.ast.body; } Wrapper.prototype.walk = function(fn) { return walk(this.ast, fn); }; Wrapper.prototype.toString = function(opts) { return 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.bare = (ref = opts.bare) != null ? ref : false; 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'); this.includeAsync = (ref4 = opts.includeAsync) != null ? ref4 : false; Prelude.__super__.constructor.call(this); if (!this.bare) { this.ast = 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 = 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.includeAsync) { preludeAsync = 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 = (parse('global.require = rqzt')).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 = parse("// source: " + sourcePath + "\nrqzt." + defineType + "(\"" + requireAs + "\", function(module, exports, __dirname, __filename, process) {\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