2012-08-14 14:59:10 +00:00
|
|
|
exports.config = function(config){
|
2013-03-18 06:26:24 +00:00
|
|
|
// summary:
|
2012-08-14 14:59:10 +00:00
|
|
|
// This module provides bootstrap configuration for running dojo in node.js
|
|
|
|
|
|
|
|
// any command line arguments with the load flag are pushed into deps
|
|
|
|
for(var deps = [], args = [], i = 0; i < process.argv.length; i++){
|
|
|
|
var arg = (process.argv[i] + "").split("=");
|
|
|
|
if(arg[0] == "load"){
|
|
|
|
deps.push(arg[1]);
|
2017-01-20 17:29:59 +00:00
|
|
|
}else if(arg[0] == "mapPackage") {
|
|
|
|
var parts = arg[1].split(":"),
|
|
|
|
name = parts[0],
|
|
|
|
location=parts[1],
|
|
|
|
isPrexisting = false;
|
|
|
|
|
|
|
|
for (var j = 0; j < config.packages.length; j++) {
|
|
|
|
var pkg = config.packages[j];
|
|
|
|
if (pkg.name === name) {
|
|
|
|
pkg.location = location;
|
|
|
|
isPrexisting = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isPrexisting) {
|
|
|
|
config.packages.push({
|
|
|
|
name: name,
|
|
|
|
location: location
|
|
|
|
});
|
|
|
|
}
|
2012-08-14 14:59:10 +00:00
|
|
|
}else{
|
|
|
|
args.push(arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var fs = require("fs");
|
|
|
|
|
|
|
|
// make sure global require exists
|
2013-03-18 06:26:24 +00:00
|
|
|
//if (typeof global.require=="undefined"){
|
2012-08-14 14:59:10 +00:00
|
|
|
// global.require= {};
|
|
|
|
//}
|
|
|
|
|
|
|
|
// reset the has cache with node-appropriate values;
|
|
|
|
var hasCache = {
|
|
|
|
"host-node":1,
|
|
|
|
"host-browser":0,
|
|
|
|
"dom":0,
|
|
|
|
"dojo-has-api":1,
|
|
|
|
"dojo-xhr-factory":0,
|
|
|
|
"dojo-inject-api":1,
|
|
|
|
"dojo-timeout-api":0,
|
|
|
|
"dojo-trace-api":1,
|
|
|
|
"dojo-dom-ready-api":0,
|
|
|
|
"dojo-publish-privates":1,
|
|
|
|
"dojo-sniff":0,
|
|
|
|
"dojo-loader":1,
|
|
|
|
"dojo-test-xd":0,
|
|
|
|
"dojo-test-sniff":0
|
|
|
|
};
|
|
|
|
for(var p in hasCache){
|
|
|
|
config.hasCache[p] = hasCache[p];
|
|
|
|
}
|
|
|
|
|
2013-03-18 06:26:24 +00:00
|
|
|
var vm = require('vm'),
|
|
|
|
path = require('path');
|
2012-08-14 14:59:10 +00:00
|
|
|
|
|
|
|
// reset some configuration switches with node-appropriate values
|
|
|
|
var nodeConfig = {
|
2013-03-18 06:26:24 +00:00
|
|
|
baseUrl: path.dirname(process.argv[1]),
|
2012-08-14 14:59:10 +00:00
|
|
|
commandLineArgs:args,
|
|
|
|
deps:deps,
|
|
|
|
timeout:0,
|
|
|
|
|
|
|
|
// TODO: really get the locale
|
|
|
|
locale:"en-us",
|
|
|
|
|
|
|
|
loaderPatch: {
|
|
|
|
log:function(item){
|
|
|
|
// define debug for console messages during dev instead of console.log
|
|
|
|
// (node's heavy async makes console.log confusing sometimes)
|
|
|
|
var util = require("util");
|
|
|
|
util.debug(util.inspect(item));
|
|
|
|
},
|
|
|
|
|
|
|
|
eval: function(__text, __urlHint){
|
|
|
|
return vm.runInThisContext(__text, __urlHint);
|
|
|
|
},
|
|
|
|
|
|
|
|
injectUrl: function(url, callback){
|
|
|
|
try{
|
|
|
|
vm.runInThisContext(fs.readFileSync(url, "utf8"), url);
|
|
|
|
callback();
|
|
|
|
}catch(e){
|
|
|
|
this.log("failed to load resource (" + url + ")");
|
|
|
|
this.log(e);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getText: function(url, sync, onLoad){
|
|
|
|
// TODO: implement async and http/https handling
|
|
|
|
onLoad(fs.readFileSync(url, "utf8"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
for(p in nodeConfig){
|
|
|
|
config[p] = nodeConfig[p];
|
|
|
|
}
|
|
|
|
};
|