source: Dev/trunk/src/client/dojo/_base/configNode.js

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.0 KB
Line 
1exports.config = function(config){
2        // summary:
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
18        //if (typeof global.require=="undefined"){
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
43        var vm = require('vm'),
44                path = require('path');
45
46        // reset some configuration switches with node-appropriate values
47        var nodeConfig = {
48                baseUrl: path.dirname(process.argv[1]),
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};
Note: See TracBrowser for help on using the repository browser.