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);
|
|
|
|
}
|
|
|
|
|
2015-03-22 10:49:23 +00:00
|
|
|
var imported = {};
|
|
|
|
|
|
|
|
var loadSrc = function (mainFile, outputDir, devFile) {
|
2014-11-29 17:30:24 +00:00
|
|
|
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)));
|
2015-03-22 10:49:23 +00:00
|
|
|
if (!(s in imported)) {
|
|
|
|
imported[s] = true;
|
|
|
|
run(s);
|
|
|
|
return true;
|
|
|
|
}
|
2014-11-29 17:30:24 +00:00
|
|
|
};
|
|
|
|
|
2015-01-29 13:49:01 +00:00
|
|
|
run(path.join(googDir, "base.js"));
|
|
|
|
run(path.join(outputDir, "cljs_deps.js"));
|
2015-03-22 10:49:23 +00:00
|
|
|
run(path.join(outputDir, devFile));
|
2014-11-29 17:30:24 +00:00
|
|
|
} else {
|
2015-01-29 13:49:01 +00:00
|
|
|
run(mainFile);
|
2014-11-29 17:30:24 +00:00
|
|
|
}
|
|
|
|
return optNone;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.load = loadSrc;
|