2014-11-29 17:30:24 +00:00
|
|
|
|
|
|
|
var fs = require("fs");
|
|
|
|
var vm = require("vm");
|
|
|
|
var path = require("path");
|
|
|
|
|
2015-01-29 13:49:01 +00:00
|
|
|
var run = function (src) {
|
|
|
|
global.require = require;
|
|
|
|
vm.runInThisContext(fs.readFileSync(src), src);
|
|
|
|
}
|
|
|
|
|
2014-11-29 17:30:24 +00:00
|
|
|
var loadSrc = function (mainFile, outputDir, devModule) {
|
|
|
|
var googDir = path.join(outputDir, "goog");
|
|
|
|
var optNone = false;
|
|
|
|
if (outputDir) {
|
|
|
|
optNone = fs.existsSync(path.join(googDir, "deps.js"));
|
|
|
|
}
|
|
|
|
if (optNone) {
|
|
|
|
var cwd = process.cwd();
|
2015-01-29 13:49:01 +00:00
|
|
|
if (!global.goog) {
|
|
|
|
global.goog = {};
|
|
|
|
}
|
2014-11-29 17:30:24 +00:00
|
|
|
global.CLOSURE_IMPORT_SCRIPT = function (src) {
|
2015-01-29 13:49:01 +00:00
|
|
|
var s = path.resolve(path.resolve(cwd, path.join(googDir, src)));
|
|
|
|
run(s);
|
2014-11-29 17:30:24 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2015-01-29 13:49:01 +00:00
|
|
|
run(path.join(googDir, "base.js"));
|
|
|
|
run(path.join(outputDir, "cljs_deps.js"));
|
2014-11-29 17:30:24 +00:00
|
|
|
goog.require(devModule);
|
|
|
|
} else {
|
2015-01-29 13:49:01 +00:00
|
|
|
run(mainFile);
|
2014-11-29 17:30:24 +00:00
|
|
|
}
|
|
|
|
return optNone;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.load = loadSrc;
|