]> git.wh0rd.org - tt-rss.git/blame - lib/dojo/_base/configNode.js
upgrade dojo to 1.8.3 (refs #570)
[tt-rss.git] / lib / dojo / _base / configNode.js
CommitLineData
1354d172 1exports.config = function(config){
f0cfe83e 2 // summary:
1354d172
AD
3 // This module provides bootstrap configuration for running dojo in node.js
4
5 // any command line arguments with the load flag are pushed into deps
6 for(var deps = [], args = [], i = 0; i < process.argv.length; i++){
7 var arg = (process.argv[i] + "").split("=");
8 if(arg[0] == "load"){
9 deps.push(arg[1]);
10 }else{
11 args.push(arg);
12 }
13 }
14
15 var fs = require("fs");
16
17 // make sure global require exists
f0cfe83e 18 //if (typeof global.require=="undefined"){
1354d172
AD
19 // global.require= {};
20 //}
21
22 // reset the has cache with node-appropriate values;
23 var hasCache = {
24 "host-node":1,
25 "host-browser":0,
26 "dom":0,
27 "dojo-has-api":1,
28 "dojo-xhr-factory":0,
29 "dojo-inject-api":1,
30 "dojo-timeout-api":0,
31 "dojo-trace-api":1,
32 "dojo-dom-ready-api":0,
33 "dojo-publish-privates":1,
34 "dojo-sniff":0,
35 "dojo-loader":1,
36 "dojo-test-xd":0,
37 "dojo-test-sniff":0
38 };
39 for(var p in hasCache){
40 config.hasCache[p] = hasCache[p];
41 }
42
f0cfe83e
AD
43 var vm = require('vm'),
44 path = require('path');
1354d172
AD
45
46 // reset some configuration switches with node-appropriate values
47 var nodeConfig = {
f0cfe83e 48 baseUrl: path.dirname(process.argv[1]),
1354d172
AD
49 commandLineArgs:args,
50 deps:deps,
51 timeout:0,
52
53 // TODO: really get the locale
54 locale:"en-us",
55
56 loaderPatch: {
57 log:function(item){
58 // define debug for console messages during dev instead of console.log
59 // (node's heavy async makes console.log confusing sometimes)
60 var util = require("util");
61 util.debug(util.inspect(item));
62 },
63
64 eval: function(__text, __urlHint){
65 return vm.runInThisContext(__text, __urlHint);
66 },
67
68 injectUrl: function(url, callback){
69 try{
70 vm.runInThisContext(fs.readFileSync(url, "utf8"), url);
71 callback();
72 }catch(e){
73 this.log("failed to load resource (" + url + ")");
74 this.log(e);
75 }
76 },
77
78 getText: function(url, sync, onLoad){
79 // TODO: implement async and http/https handling
80 onLoad(fs.readFileSync(url, "utf8"));
81 }
82 }
83 };
84 for(p in nodeConfig){
85 config[p] = nodeConfig[p];
86 }
87};