Skip to content
Permalink
Browse files
Merge branch 'next'
  • Loading branch information
gtanner committed Mar 22, 2013
2 parents 4ebae85 + a17c205 commit 6c844bc806293d8265b4ccb91919ccdfe4ac3c96
Showing 6 changed files with 86 additions and 32 deletions.
@@ -110,4 +110,3 @@ platforms.forEach(function(platform) {
}
});
});

@@ -36,6 +36,7 @@ module.exports = {
plugin: require('./src/plugin'),
plugins: require('./src/plugin'),
serve: require('./src/serve'),
ripple: require('./src/ripple'),
on: function() {
cordova_events.on.apply(cordova_events, arguments);
},
@@ -19,6 +19,8 @@ Project-Level Commands
serve <platform> [port] ........... runs a local web server for the www/ directory of the given platform
the default port is 8000
note that you must edit the native code to point at the server!
ripple <platform> [port] .......... uses the serve command as a base and then wraps the server
with ripple to test your app in your desktop browser.
help .............................. shows this!

Example usage
@@ -31,7 +31,9 @@
"ncallbacks":"1.0.0",
"request":"2.11.4",
"semver":"1.1.0",
"prompt":"0.2.7"
"prompt":"0.2.7",
"ripple-emulator":">=0.9.15",
"open": "0.0.3"
},
"devDependencies": {
"jasmine-node":"1.1.x"
@@ -0,0 +1,53 @@

/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
var serve = require('./serve'),
ripple = require('ripple-emulator'),
open = require('open');

module.exports = function (platform, port) {
port = port || 8000;

serve.config(platform, port, function (cfg) {
ripple.emulate.start({
path: cfg.paths,
port: port
});

var device;

switch (platform) {
case "blackberry":
device = "Z10";
break;
case "ios":
device = "IPhone5";
break;
case "android":
device = "NexusS";
break;
default:
device = "XVGA";
break;
}

var uri = "http://localhost:" + port + "?enableripple=cordova-2.0.0-" + device;
open(uri);
});
};
@@ -79,6 +79,17 @@ function launch_server(www, platform_www, port) {
}

module.exports = function serve (platform, port) {
var returnValue = {};

module.exports.config(platform, port, function (config) {
returnValue.server = launch_server(config.paths[0], config.paths[1], port);
});

// Hack for testing despite its async nature.
return returnValue;
};

module.exports.config = function (platform, port, callback) {
var projectRoot = cordova_util.isCordova(process.cwd());

if (!projectRoot) {
@@ -100,46 +111,32 @@ module.exports = function serve (platform, port) {

// If we got to this point, the given platform is valid.

// Default port is 8000 if not given. This is also the default of the Python module.
port = port || 8000;
var result = {
paths: [],
// Default port is 8000 if not given. This is also the default of the Python module.
port: port || 8000
};

// Top-level www directory.
var www = projectRoot + path.sep + 'www';
result.paths.push(projectRoot + path.sep + 'www');

var parser, platformPath;
var parser;

// Hack for testing despite its async nature.
var returnValue = {};
switch (platform) {
case 'android':
platformPath = path.join(projectRoot, 'platforms', 'android');
parser = new android_parser(platformPath);

// Update the related platform project from the config
parser.update_project(cfg);
var platform_www = parser.www_dir();
returnValue.server = launch_server(www, platform_www, port);
parser = new android_parser(path.join(projectRoot, 'platforms', platform));
break;
case 'blackberry-10':
platformPath = path.join(projectRoot, 'platforms', 'blackberry-10');
parser = new blackberry_parser(platformPath);

// Update the related platform project from the config
parser.update_project(cfg, function() {
// Shell it
returnValue.server = launch_server(www, parser.www_dir(), port);
});
parser = new blackberry_parser(path.join(projectRoot, 'platforms', platform));
break;
case 'ios':
platformPath = path.join(projectRoot, 'platforms', 'ios');
js = path.join(__dirname, '..', 'lib', 'ios', 'CordovaLib', 'javascript', 'cordova.ios.js');
parser = new ios_parser(platformPath);
// Update the related platform project from the config
parser.update_project(cfg, function() {
returnValue.server = launch_server(www, parser.www_dir(), port);
});
parser = new ios_parser(path.join(projectRoot, 'platforms', platform));
break;
}
return returnValue;
};

// Update the related platform project from the config
parser.update_project(cfg, function() {
result.paths.push(parser.www_dir());
callback(result);
});
}

0 comments on commit 6c844bc

Please sign in to comment.