PDA

View Full Version : Can you run SDK commands via rhino?



nvoxland
7 Jun 2011, 5:46 AM
I'm looking to auto-generate combined/compressed javascript within my java application when the all-classes.js URL is first requested (sort of like how jsp files are parsed and compiled when first executed).

So basically, I am needing to automate a call to "sencha create jsb -a http://localhost/path/to/application/index.php -p app.jsb3" and "sencha build -p app.jsb3 -d ." server-side.

It sort of works by executing the jsdb directly, but I am having problems with the process not actually exiting consistently.

Since it is a java application, I think it would be nice to simply be able to use the rhino javascript engine to execute the command/sencha.js directly since it would be running in-process and so I would have better control over how it is executing and will not have to worry about platform differences.

Does anyone know if rhino would be able to run the create and build commands? Or is there jsdb-specific javascript in there?

Nathan

kite
7 Jun 2011, 6:36 AM
Sencha SDK Tools uses Phantom JS (http://www.phantomjs.org/) to get dependencies list, this is "headless WebKit with JavaScript API" and this isn't java-application.
I don't think ExtJS 4.0 works correctly with Rhino js-engine... even more - Phino isn't HTML parser, so it's impossible to pass index.html to it.

To compress javascript you can use YUI compressor directly from Java. To get dependency list of js-files - you need to run phantomjs or any similar tool (it's not so hard to do this through System.exec or ProcessBuilder).

mschwartz
7 Jun 2011, 6:44 AM
Sencha SDK Tools uses Phantom JS (http://www.phantomjs.org/) to get dependencies list, this is "headless WebKit with JavaScript API" and this isn't java-application.
I don't think ExtJS 4.0 works correctly with Rhino js-engine... even more - Phino isn't HTML parser, so it's impossible to pass index.html to it.

To compress javascript you can use YUI compressor directly from Java. To get dependency list of js-files - you need to run phantomjs or any similar tool (it's not so hard to do this through System.exec or ProcessBuilder).

Rhino has E4X, so it could deal with HTML documents just fine.

kite
7 Jun 2011, 6:57 AM
Rhino has E4X, so it could deal with HTML documents just fine.
HTML != XML and even HTML != XHTML. And API for XML in JavaScript isn't what we need - to receive full dependency list it's need to create full DOM and run whole JavaScript, like in browser.
Have you tried to run ExtJS application under Rhino? ;)

nvoxland
7 Jun 2011, 7:20 AM
I don't need the whole ExtJS application to run under rhino, all I would need is the ability to get the "create jsb" and "build" commands to run. It does appear that the "create jsb" does run the all the initialization javascript, so we may need to be careful about what is in the init methods, but it seems like it should be possible.

ext-app-builder.bat uses phantomjs, but command and jsbuilder both use jsdb. Any idea why the difference? Are they using jsdb just as a javascript engine? Or are there calls in there to jsdb-specific functions like Stream and Process?

Nathan

Nathan

mschwartz
7 Jun 2011, 7:40 AM
HTML != XML and even HTML != XHTML. And API for XML in JavaScript isn't what we need - to receive full dependency list it's need to create full DOM and run whole JavaScript, like in browser.
Have you tried to run ExtJS application under Rhino? ;)

Rhino is just a JavaScript interpreter, it does not have the DOM implementation of a browser. So of course ExtJS won't run in it without adding something like JSDOM or env.js.

But I didn't see that as an issue... See this:


I don't need the whole ExtJS application to run under rhino, all I would need is the ability to get the "create jsb" and "build" commands to run. It does appear that the "create jsb" does run the all the initialization javascript, so we may need to be careful about what is in the init methods, but it seems like it should be possible.

ext-app-builder.bat uses phantomjs, but command and jsbuilder both use jsdb. Any idea why the difference? Are they using jsdb just as a javascript engine? Or are there calls in there to jsdb-specific functions like Stream and Process?

Nathan

Nathan

Not sure why you'd want to use Rhino, since it's 30x to 100x slower than the major browsers' JS engines. What it does have is threading, so you could do things in parallel...

kite
7 Jun 2011, 7:44 AM
I don't need the whole ExtJS application to run under rhino, all I would need is the ability to get the "create jsb""create jsb" in order to get dependency list runs whole ExtJS application inside PhantomJS (using WebKit engine).
So only with Rhino you cannot do "create jsb", if you will use PhantomJS - you don't need Rhino (PhantomJS can do everything that Rhino can).
I don't why Sencha use jsdb for for parsing argument and printing help instead of phantomjs, like as I don't know why they include Hammer JS and don't use it at all.
As for me, for building I created a simple js-script that returns deps list (a few lines from ext-app-builder.js), and in other shell script run it under phantomjs, create single file and compress with Yahoo js-compressor - result the same as after "sencha create jsb" && "sencha build", but everything is simple and works without problems everywhere (including Linux x64).

nvoxland
7 Jun 2011, 1:23 PM
The reason I was looking at rhino is because I am already running inside a java environment, and I am trying to avoid forking a new process even at the expense of having a slow JS interpreter.

I hadn't realized ext did as much execution of your app in order to do "create jsb", and I see that ext-app-builder.js has references to phantom.fs, so it looks like rhino is not going to be an option.

I'll probably just have to see if I can do a better job of external-process management from java.

Nathan

kite
7 Jun 2011, 2:12 PM
I hadn't realized ext did as much execution of your app in order to do "create jsb", and I see that ext-app-builder.js has references to phantom.fs, so it looks like rhino is not going to be an option.This isn't big problem - you can write own ext-app-builder.js and use stdout instead of file i/o. The main problem in that fact, that you need to fully load your page like browsers do this, and only after this you can retrieve object Ext.Loader.history. Only in this case and if you correctly setup "require"d classes you will get full dependency list. Rhino can't do this. You should use js-engine only from one of supported by ExtJS browsers.
Execute external process in Java is very simple - good luck. :)

wiznia
11 Aug 2011, 1:43 AM
So is it possible to not use jsdb and use phantom instead???<br>Does someone knows how it's done?

kite
20 Aug 2011, 10:26 AM
So is it possible to not use jsdb and use phantom instead???<br>Does someone knows how it's done?Try to read this:
http://www.sencha.com/forum/showthread.php?136032-SDKTOOLS-3-buggy-Sencha-SDK-Tools/page2