PDA

View Full Version : Get Ext.Loader.history via Node.js



uzver
17 May 2011, 10:36 AM
I made simple nodejs script for getting app dependencies list. It's useful for backend server integration without using Sencha SDK(e.g. rails with jammit gem).


var appDir = process.argv[2];
//emulate several browser objects for correct loading ext-core
navigator = {
userAgent: 'nodejs',
platform: 'linux'
}
//stub document
document = {
getElementsByTagName: function(tag) {
return [''];
},
attachEvent: function() {
},
documentElement: {
style: {
}
}
}
//stub window
window = {
navigator: navigator,
attachEvent: function() {
}
}
top = {
}

require(appDir + '/vendor/extjs/ext-core.js')
//stub Ext.EventManager
Ext.EventManager.un = function () {
}
//set loader
Ext.Loader.setConfig({
enabled: true,
paths: {
'Ext' : 'vendor/extjs/src',
'app' : 'app'
}
});
//override loadScriptFile for Loader
Ext.Loader.loadScriptFile = function(url, onLoad, onError, scope, synchronous) {
this.isLoading = true;
require(appDir + "/" + url.replace(/^\//, ""));
onLoad.call(scope);
}
//ovride triggerReady for exiting when loading process is completed
var tmp = Ext.Loader.triggerReady;
Ext.Loader.triggerReady = function() {
if(!this.completed && this.queue.length == 0 && this.optionalRequires.length == 0) {
var files = [];
this.history.forEach(function(val) {
files.push(Ext.Loader.getPath(val));
});
this.completed = true;
//return to console list of dependencies
console.log(files.join("\n"));
while (!process.stdout.flush());
process.exit(0);
}
tmp.apply(this, arguments);
};
//load main js app file
require(appDir + '/app/app.js');

Usage:


nodejs script.js project_dir/public

crisp
1 Dec 2011, 1:41 AM
I'm trying to run this on 4.0.7 on Mac Os Nodejs and I'me getting the following error:


node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot read property 'protocol' of undefined
at /Users/crisp/Sites/extplay/js/ext/ext-dev.js:9324:50
at Object.<anonymous> (/Users/crisp/Sites/extplay/js/ext/ext-dev.js:10125:2)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)
at Module.load (module.js:334:31)
at Function._load (module.js:293:12)
at require (module.js:346:19)
at Object.<anonymous> (/Users/crisp/Sites/extplay/build.js:28:1)
at Module._compile (module.js:402:26)
at Object..js (module.js:408:10)

What version of ext are you running ?

uzver
1 Dec 2011, 4:35 AM
Adopted for extjs v4.0.7 and nodejs v0.6.2

https://gist.github.com/1416405