Skip to content

Instantly share code, notes, and snippets.

@gorkunov
Created December 1, 2011 12:35
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gorkunov/1416405 to your computer and use it in GitHub Desktop.
Nodejs adapter for ExtJS (collection extjs dependencies)
var appFolder = process.argv[2];
var prefix = process.argv[3];
var idle = false;
//emulate several browser objects for correct loading ext-core
navigator = {
userAgent: 'nodejs',
platform: 'linux'
};
document = {
getElementsByTagName: function(tag) {
return [''];
},
attachEvent: function() {
},
documentElement: {
style: {
}
}
};
window = {
navigator: navigator,
location: {},
attachEvent: function() {
}
};
top = {
};
require(appFolder + '/app/vendor/extjs/ext-core-debug.js');
//stub Ext.EventManager
Ext.EventManager.un = function () {
};
//override loadScriptFile for Loader
Ext.Loader.loadScriptFile = function(url, onLoad, onError, scope, synchronous) {
this.isLoading = true;
require(appFolder + "/" + 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) {
if(idle) {
var appFiles = [],
vendorFiles = [],
file;
this.history.forEach(function(val) {
file = prefix + Ext.Loader.getPath(val).replace(/^\//, "");
if(/vendor/.test(file)) {
vendorFiles.push(file);
} else {
appFiles.push(file);
}
});
console.log(vendorFiles.join("\n"));
console.log(appFiles.join("\n"));
this.completed = true;
process.exit(0);
}
}
tmp.apply(this, arguments);
};
require(appFolder + '/app/app.js');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment