Skip to content

Commit

Permalink
use defaults.xml for workspace dirs without a .settings file; tweaked…
Browse files Browse the repository at this point in the history
… defaults; bump version to 0.1.4
  • Loading branch information
KylePDavis committed Nov 17, 2013
1 parent ba5a013 commit dd85396
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Installation

TODO
----
* c9: use defaults.xml for new workspaces that do not already have a ".settings" file
* c9: save history of most recently used workspace directories
* c9: open workspaces save on quit, restore on load
* c9: workspace tab close button
Expand Down
6 changes: 3 additions & 3 deletions defaults.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<settings time="1381674957257">
<general animateui="true" revealfile="false" confirmexit="false">
<general animateui="true" revealfile="true" confirmexit="false">
<keybindings preset="auto"/>
</general>
<auto>
Expand All @@ -17,9 +17,9 @@
</auto>
<breakpoints/>
<beautify>
<jsbeautify preserveempty="true" keeparrayindentation="false" jslinthappy="false" braces="end-expand" space_before_conditional="true" unescape_strings="true"/>
<jsbeautify preserveempty="true" keeparrayindentation="false" jslinthappy="false" braces="collapse" space_before_conditional="true" unescape_strings="true"/>
</beautify>
<editors>
<code stripws="false"/>
<code stripws="true"/>
</editors>
</settings>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "C9",
"version": "0.1.3",
"version": "0.1.4",
"description": "A wrapper app for running the Cloud9 IDE locally",
"main": "app://c9/www/index.html",
"repository": {
Expand Down
59 changes: 46 additions & 13 deletions www/lib/Servers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/*jshint browser:true, node:true*/
var path = require("path"),
fs = require("fs"),
net = require("net"),
childProcess = require("child_process"),
readline = require("readline"),
gui = process.gui || require("nw.gui"),
async = require("async"),
Config = require("./Config").init(),
Expand Down Expand Up @@ -28,6 +31,12 @@ var Servers = module.exports = {

_nextPort: Config.current.basePort,

/**
* Find the next available TCP port
* @method findNextPort
* @static
* @param callback {Function} A function that will be called back with the port once it has been created; i.e., `callback(port)`
**/
findNextPort: function findNextPort(callback){
Log.dbg("Servers.findNextPort port=%s available?", Servers._nextPort);
var svr = net.createServer()
Expand Down Expand Up @@ -63,37 +72,61 @@ var Servers = module.exports = {
// parse args
if(typeof dir !== "string") throw new Error("Servers.start arg #1 must be workspace dir string");
if(options instanceof Function) callback = options, options = undefined;
// resolve options
if(options === undefined) options = {};

// resolve options that can be determined syncronously
if(!(options.ip && typeof options.ip === "string")) options.ip = Config.current.ip;
async.series( // resolution of some options must be done asyncly

// resolve more options, prepare workspace, and start server
async.series(
[
function findPort(next){
if(options.port) return next();
Servers.findNextPort(function(port){

function resolveOptionPort(next) {
if (options.port) return next();
Servers.findNextPort(function(port) {
options.port = port;
return next();
});
},
function findDebugPort(next){
if(options.debugPort) return next();
Servers.findNextPort(function(debugPort){

function resolveOptionDebugPort(next) {
if (options.debugPort) return next();
Servers.findNextPort(function(debugPort) {
options.debugPort = debugPort;
return next();
});
}

],
function resolvedOptions(err){

function donePreparing(err){
if(err) return callback(err);
var childProcess = require("child_process"),
readline = require("readline"),
appDir = process.cwd(),

var appDir = process.cwd(),
nodeEnvDir = appDir + "/nodeenv",
nodeBin = nodeEnvDir + "/bin/node",
nodeArgs = [appDir + "/cloud9/server.js", appDir + "/serverConfig", "-w", dir];
process.env.IP = options.ip || Config.current.ip;

// prepare workspace default settings if possible
var defaultSettingsFile = path.join(appDir, "defaults.xml"),
settingsFile = path.join(dir, ".settings");
try {
var defaultSettingsData = fs.readFileSync(defaultSettingsFile);
fs.writeFileSync(settingsFile, defaultSettingsData, {
flag: "wx"
});
} catch (prepErr) {
var ignoredErrorCodes = ["EEXIST", "EACCES"];
console.error("SERVER WORKSPACE PREP ERROR:", {e:prepErr});
if (ignoredErrorCodes.indexOf(prepErr.code) === -1) throw prepErr;
}

// send some options through environment vars
process.env.IP = options.ip;
process.env.PORT = options.port;
process.env.DEBUG_PORT = options.debugPort;

// start process
Log.out("Starting new C9 server process: ", {bin:nodeBin, args:nodeArgs, env:JSON.parse(JSON.stringify(process.env))});
var server = childProcess.spawn(nodeBin, nodeArgs, {
env: process.env
Expand Down

0 comments on commit dd85396

Please sign in to comment.