mark
mark

Reputation: 62734

How can I load a json file in the dojo application build profile?

I have the following dojo build profile:

var profile = (function () {
    return {
        basePath: "./Scripts",
        releaseDir: "./bin",
        releaseName: "",
        action: "release",
        mini: true,
        layerOptimize: "closure",
        optimize: "closure",
        cssOptimize: "comments",
        localeList: false,
        packages: [
            {
                name: "dojo",
                location: "l:/dojo-debug/1.10.4/dojo"
            },
            {
                name: "dijit",
                location: "l:/dojo-debug/1.10.4/dijit"
            },
            {
                name: "dojox",
                location: "l:/dojo-debug/1.10.4/dojox"
            },
            ...
        ],
        layers: ...
    };
})();

Now, I need to read values from some json file, so I am looking for something like this:

var profile = (function () {
    var versions = SomeHowReadTheContentsOf("ThirdPartyJsLibRootMap.json");
    return {
        basePath: "./Scripts",
        releaseDir: "./bin",
        releaseName: "",
        action: "release",
        mini: true,
        layerOptimize: "closure",
        optimize: "closure",
        cssOptimize: "comments",
        localeList: false,
        packages: [
            {
                name: "dojo",
                location: "l:/dojo-debug/" + versions["dojo-debug"] + "/dojo"
            },
            {
                name: "dijit",
                location: "l:/dojo-debug/" + versions["dojo-debug"] + "/dijit"
            },
            {
                name: "dojox",
                location: "l:/dojo-debug/" + versions["dojo-debug"] + "/dojox"
            }
            ...
        ],
        layers: ...
    };
})();

For the life of me I am failing to find the way to do it.

Any ideas?

EDIT

My command line is: node L:\dojo-debug\1.10.4\dojo\dojo.js load=build --profile .\package.profile.js

EDIT2

I have added a console log of all the properties of require, below is the result:

has = undefined
isXdUrl = undefined
initSyncLoader = undefined
eval = undefined
signal = undefined
on = undefined
map = undefined
rawConfig = undefined
legacyMode = undefined
async = undefined
waitms = undefined
baseUrl = undefined
idle = undefined
toAbsMid = undefined
toUrl = undefined
log = undefined
trace = undefined
injectUrl = undefined
getText = undefined
nodeRequire = undefined
uid = undefined
cache = undefined
packs = undefined
paths = undefined
aliases = undefined
modules = undefined
execQ = undefined
defQ = undefined
waiting = undefined
mapProgs = undefined
pathsMapProg = undefined
listenerQueues = undefined
computeMapProg = undefined
computeAliases = undefined
runMapProg = undefined
compactPath = undefined
getModuleInfo = undefined
boot = undefined
scopeify = undefined

So nodeRequire is there, but its value is undefined. Something is wrong.

Upvotes: 0

Views: 353

Answers (1)

Bryan Forbes
Bryan Forbes

Reputation: 71

If you are running the Dojo builder with NodeJS, you have access to its require via require.nodeRequire. Within a build profile file, you also have access to a variable called selfPath which is the absolute directory name of the profile file you have passed to the builder (it's similar to __dirname in a node module). Putting these two things together and assuming ThirdPartyJsLibRootMap.json is a sibling of your build profile:

var profile = (function () {
    var req = require.nodeRequire;
    var path = req('path');
    var versions = req(path.join(selfPath, 'ThirdPartyJsLibRootMap.json'));
    return {
        ...
    };
})();

Upvotes: 1

Related Questions