Browserify for Commandfusion

113 views
Skip to first unread message

Zain

unread,
Jan 29, 2014, 11:05:22 PM1/29/14
to comman...@googlegroups.com

Has anyone tried Browserify with the Javascript for CF? I made a small test and it seems to work.  But I am not sure if it will adversely affect the app as a whole. There is a lot of potential benefit if this is 'approved' within CF. Below is my example if others are willing to try. You need to install node.js/npm and browserify first.

main.js

var foo = require('./foo.js'); // module.exports = function (n) { return n * 222 }
var _ =  require('./underscore-min.js'); // download from underscore.org
CF.userMain = function() {
    // Watch for network status, get initial status
   CF.watch(CF.NetworkStatusChangeEvent, onNetworkStatusChange, true);
    console.log(foo(2)); // console will output result: 444
};

// Callback function for network status change
function onNetworkStatusChange(networkStatus) {
   if (networkStatus.hasNetwork) {
       var networkLog = "";
       _.each(networkStatus, function(value, key, networkStatus) {
           if (value.length !== 0) {
               networkLog += "> " + key + " : " + value + "\r";
           }
           console.log(networkLog);
       });
       CF.setJoin("s1", networkLog);
   } else {
       CF.log("Device is disconnected from the network");
   }
}

I browserified main.js into bundle.js using the command below:

browserify main.js > bundle.js

I added bundle.js into my .gui using the Script Manager and upload to my iPad.
Zain

thechad

unread,
Jan 30, 2014, 2:35:31 AM1/30/14
to comman...@googlegroups.com
Very interesting...can you give some examples on what this would bring and why I might use it?

Florent Pillet

unread,
Jan 30, 2014, 2:47:51 AM1/30/14
to comman...@googlegroups.com
There's no reason this wouldn't work. Remember that when remote debugging, you will be debugging against the source code produced by Browserify, not your original source code (so with all the dependancies included).

FWIW, you could even write your code with CoffeeScript or similar. But obviously, since we don't bundle the original source code and don't support sourcemaps, it makes debugging more complicated.

Florent

--
You received this message because you are subscribed to the Google Groups "CommandFusion Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to commandfusio...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Zain

unread,
Jan 30, 2014, 4:47:29 AM1/30/14
to comman...@googlegroups.com
thechad,  as you can see in the sample I am using the underscore.js module. It brings tons of methods for collections so it makes programming easier. Also there are many modules in the world of nodejs that are really useful in JS programming. 

The use of 'require' helps to manage module dependencies as I dislike using the Script Manager to attach the .js files and browserify allows me to do all through my favourite editor Sublime Text. When you have lot of modules, the Script Manager is not friendly.

I am looking into improving my workflow and do more work via .js and the editor rather than guiDesigner. Another thing I am looking at is creating a .json file for all external systems and use grunt.js to output it into a .gui. 

Zain

thechad

unread,
Jan 30, 2014, 8:05:41 AM1/30/14
to comman...@googlegroups.com

The use of 'require' helps to manage module dependencies as I dislike using the Script Manager to attach the .js files and browserify allows me to do all through my favourite editor Sublime Text. When you have lot of modules, the Script Manager is not friendly.

I am looking into improving my workflow and do more work via .js and the editor rather than guiDesigner. Another thing I am looking at is creating a .json file for all external systems and use grunt.js to output it into a .gui. 

Zain

Thanks Zain.  I absolutely get what you are saying with the require. Nice.  

Will follow this as I am slowly getting more comfortable with js.

Thanks for posting this info.

Grid Sound and Screen

unread,
Apr 26, 2014, 12:32:18 PM4/26/14
to comman...@googlegroups.com
Created an example Gulp / Browserify project for CommandFusion you all might be interested in, check it out here and let me know what you think. Feel free to file issues for bugs and feature requests.

Reply all
Reply to author
Forward
0 new messages