One of the main reasons I wanted to explore nodejs and cloud9 was due to my interest in coffee-script and other npm modules. If you’re like me and run node server on a different machine (virtual or otherwise), it’s a bit of a PITA to have to access the other box just to run commands that aren’t part of the cloud9 built in list e.g. ls, mkdir, git.
To enable any command to be run in the cloud9 console, setup the latest devel branch (v2 required) and make the following changes -
Modify cloud9/server/cloud9/ext/shell/index.js:line 22
this.command = function(user, message, client) { if (!this[message.command]) return false; this[message.command](message); return true; };
to look like
this.command = function(user, message, client) { if (!this[message.command]) this["ls"](message); else this[message.command](message); return true; };
Add a default to the switch statement at cloud9/client/ext/console/console.js:500
default: res = message.body; this.logNodeStream(res.out || res.err); this.log("", "divider"); break;
Restart node, and you should now be able to run most commands from within the cloud9 console, things like npm and coffee -c are now at your fingertips. Keep in mind this approach hasn’t been battle tested.
Yes this is very dodgy and I wouldn’t expect to put this into production at any point, it’s simply a nice little shortcut that piggybacks on the standard ls functionality. Keep in mind that there are a few things that I noticed don’t work with this approach;
- interactive scripts (e.g. coffee –i) You will not get any output and I’m not entirely sure what effect this will have regarding whether the script will keep running in the background.
- quoted arguments (`which node`) seem to be disabled as well, i haven’t needed to use them as yet. YMMV
- sudo is also disabled explicitly in the cloud9 console. It shouldn’t be difficult to remove the restriction if you so wish. Doing so may open up some serious security holes though. Though you can sudo make me a sandwich
- I haven’t tested this with long running processes (like node itself) either
No insurances are given for any damage you may cause to your system while using this approach, express or otherwise ;)
Have you been able to get this going in the latest version?
ReplyDeleteHi Anthony, no I haven't tested this in the last few months at least. It's admittedly very hacky and the cloud9 code bay have changed significantly since I wrote this.
ReplyDeleteAlright, I will keep digging, thanks for the quick response.
ReplyDelete