You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ripple.apache.org by gt...@apache.org on 2013/10/21 04:42:40 UTC
[11/15] git commit: Handle when calling `ripple emulate` for v3.0
Handle when calling `ripple emulate` for v3.0
- Will route to platform/android/assets/www
- Will run `cordova prepare` when first loading ripple
Project: http://git-wip-us.apache.org/repos/asf/incubator-ripple/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ripple/commit/af934027
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ripple/tree/af934027
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ripple/diff/af934027
Branch: refs/heads/next
Commit: af934027bc2ec7f7761f8c25fc1765934fafb6a5
Parents: b873ced
Author: Gord Tanner <gt...@gmail.com>
Authored: Thu Oct 3 22:05:43 2013 -0400
Committer: Gord Tanner <gt...@gmail.com>
Committed: Thu Oct 3 22:05:43 2013 -0400
----------------------------------------------------------------------
lib/server/emulate.js | 14 ++++++++++++++
lib/server/emulate/hosted.js | 15 ++++++++++++++-
2 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/af934027/lib/server/emulate.js
----------------------------------------------------------------------
diff --git a/lib/server/emulate.js b/lib/server/emulate.js
index d59a7fa..1bd6d15 100644
--- a/lib/server/emulate.js
+++ b/lib/server/emulate.js
@@ -22,6 +22,8 @@ var proxy = require('./proxy'),
server = require('./index'),
colors = require('colors'),
express = require('express'),
+ fs = require('fs'),
+ path = require('path'),
hosted = require('./emulate/hosted');
colors.mode = "console";
@@ -58,6 +60,18 @@ module.exports = {
app.use(hosted.inject(options));
if (!options.remote) {
+ try {
+ fs.statSync(path.join(options.path, ".cordova"))
+ console.log("Cordova 3.0 Project detected...");
+ var platforms = fs.readdirSync(path.join(options.path, "platforms"));
+ if (platforms.indexOf('android') >= 0) {
+ options.cordova = true;
+ options.path = [path.join(options.path, "platforms", "android", "assets", "www")];
+ }
+ } catch (e) {
+ //Not a cordova project
+ }
+
options.path.forEach(function (path) {
app.use("/", express.static(path));
});
http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/af934027/lib/server/emulate/hosted.js
----------------------------------------------------------------------
diff --git a/lib/server/emulate/hosted.js b/lib/server/emulate/hosted.js
index 11631e8..0d2f6b2 100644
--- a/lib/server/emulate/hosted.js
+++ b/lib/server/emulate/hosted.js
@@ -21,6 +21,7 @@
var fs = require('fs'),
path = require('path'),
request = require('request'),
+ exec = require('child_process').exec,
url = require('url'),
HEAD_TAG = /<\s*head\s*>/,
@@ -137,7 +138,7 @@ function localInjection(opts) {
});
}
- return function (req, res, next) {
+ function handle(req, res, next) {
// TODO: DRY (see proxyRemote function)
if (req.query.enableripple) {
res.sendfile(path.join(HOSTED_PKG_DIR, "index.html"));
@@ -158,6 +159,18 @@ function localInjection(opts) {
next();
}
};
+
+ return function (req, res, next) {
+ if (req.query.enableripple && opts.cordova) {
+ console.log('refreshing project ..');
+ exec('cordova prepare', function () {
+ handle(req, res, next);
+ });
+ }
+ else {
+ handle(req, res, next);
+ }
+ }
}
module.exports = {