Repository: cordova-browser
Updated Branches:
  refs/heads/master 3fdec072e -> 1d2725bfc


http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/1d2725bf/node_modules/cordova-serve/node_modules/shelljs/src/rm.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/node_modules/shelljs/src/rm.js 
b/node_modules/cordova-serve/node_modules/shelljs/src/rm.js
deleted file mode 100644
index bd608cb..0000000
--- a/node_modules/cordova-serve/node_modules/shelljs/src/rm.js
+++ /dev/null
@@ -1,163 +0,0 @@
-var common = require('./common');
-var fs = require('fs');
-
-// Recursively removes 'dir'
-// Adapted from https://github.com/ryanmcgrath/wrench-js
-//
-// Copyright (c) 2010 Ryan McGrath
-// Copyright (c) 2012 Artur Adib
-//
-// Licensed under the MIT License
-// http://www.opensource.org/licenses/mit-license.php
-function rmdirSyncRecursive(dir, force) {
-  var files;
-
-  files = fs.readdirSync(dir);
-
-  // Loop through and delete everything in the sub-tree after checking it
-  for(var i = 0; i < files.length; i++) {
-    var file = dir + "/" + files[i],
-        currFile = fs.lstatSync(file);
-
-    if(currFile.isDirectory()) { // Recursive function back to the beginning
-      rmdirSyncRecursive(file, force);
-    }
-
-    else if(currFile.isSymbolicLink()) { // Unlink symlinks
-      if (force || isWriteable(file)) {
-        try {
-          common.unlinkSync(file);
-        } catch (e) {
-          common.error('could not remove file (code '+e.code+'): ' + file, 
true);
-        }
-      }
-    }
-
-    else // Assume it's a file - perhaps a try/catch belongs here?
-      if (force || isWriteable(file)) {
-        try {
-          common.unlinkSync(file);
-        } catch (e) {
-          common.error('could not remove file (code '+e.code+'): ' + file, 
true);
-        }
-      }
-  }
-
-  // Now that we know everything in the sub-tree has been deleted, we can 
delete the main directory.
-  // Huzzah for the shopkeep.
-
-  var result;
-  try {
-    // Retry on windows, sometimes it takes a little time before all the files 
in the directory are gone
-    var start = Date.now();
-    while (true) {
-      try {
-        result = fs.rmdirSync(dir);
-        if (fs.existsSync(dir)) throw { code: "EAGAIN" }
-        break;
-      } catch(er) {
-        // In addition to error codes, also check if the directory still 
exists and loop again if true
-        if (process.platform === "win32" && (er.code === "ENOTEMPTY" || 
er.code === "EBUSY" || er.code === "EPERM" || er.code === "EAGAIN")) {
-          if (Date.now() - start > 1000) throw er;
-        } else if (er.code === "ENOENT") {
-          // Directory did not exist, deletion was successful
-          break;
-        } else {
-          throw er;
-        }
-      }
-    }
-  } catch(e) {
-    common.error('could not remove directory (code '+e.code+'): ' + dir, true);
-  }
-
-  return result;
-} // rmdirSyncRecursive
-
-// Hack to determine if file has write permissions for current user
-// Avoids having to check user, group, etc, but it's probably slow
-function isWriteable(file) {
-  var writePermission = true;
-  try {
-    var __fd = fs.openSync(file, 'a');
-    fs.closeSync(__fd);
-  } catch(e) {
-    writePermission = false;
-  }
-
-  return writePermission;
-}
-
-//@
-//@ ### rm([options ,] file [, file ...])
-//@ ### rm([options ,] file_array)
-//@ Available options:
-//@
-//@ + `-f`: force
-//@ + `-r, -R`: recursive
-//@
-//@ Examples:
-//@
-//@ ```javascript
-//@ rm('-rf', '/tmp/*');
-//@ rm('some_file.txt', 'another_file.txt');
-//@ rm(['some_file.txt', 'another_file.txt']); // same as above
-//@ ```
-//@
-//@ Removes files. The wildcard `*` is accepted.
-function _rm(options, files) {
-  options = common.parseOptions(options, {
-    'f': 'force',
-    'r': 'recursive',
-    'R': 'recursive'
-  });
-  if (!files)
-    common.error('no paths given');
-
-  if (typeof files === 'string')
-    files = [].slice.call(arguments, 1);
-  // if it's array leave it as it is
-
-  files = common.expand(files);
-
-  files.forEach(function(file) {
-    if (!fs.existsSync(file)) {
-      // Path does not exist, no force flag given
-      if (!options.force)
-        common.error('no such file or directory: '+file, true);
-
-      return; // skip file
-    }
-
-    // If here, path exists
-
-    var stats = fs.lstatSync(file);
-    if (stats.isFile() || stats.isSymbolicLink()) {
-
-      // Do not check for file writing permissions
-      if (options.force) {
-        common.unlinkSync(file);
-        return;
-      }
-
-      if (isWriteable(file))
-        common.unlinkSync(file);
-      else
-        common.error('permission denied: '+file, true);
-
-      return;
-    } // simple file
-
-    // Path is an existing directory, but no -r flag given
-    if (stats.isDirectory() && !options.recursive) {
-      common.error('path is a directory', true);
-      return; // skip path
-    }
-
-    // Recursively remove existing directory
-    if (stats.isDirectory() && options.recursive) {
-      rmdirSyncRecursive(file, options.force);
-    }
-  }); // forEach(file)
-} // rm
-module.exports = _rm;

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/1d2725bf/node_modules/cordova-serve/node_modules/shelljs/src/sed.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/node_modules/shelljs/src/sed.js 
b/node_modules/cordova-serve/node_modules/shelljs/src/sed.js
deleted file mode 100644
index 65f7cb4..0000000
--- a/node_modules/cordova-serve/node_modules/shelljs/src/sed.js
+++ /dev/null
@@ -1,43 +0,0 @@
-var common = require('./common');
-var fs = require('fs');
-
-//@
-//@ ### sed([options ,] search_regex, replacement, file)
-//@ Available options:
-//@
-//@ + `-i`: Replace contents of 'file' in-place. _Note that no backups will be 
created!_
-//@
-//@ Examples:
-//@
-//@ ```javascript
-//@ sed('-i', 'PROGRAM_VERSION', 'v0.1.3', 'source.js');
-//@ sed(/.*DELETE_THIS_LINE.*\n/, '', 'source.js');
-//@ ```
-//@
-//@ Reads an input string from `file` and performs a JavaScript `replace()` on 
the input
-//@ using the given search regex and replacement string or function. Returns 
the new string after replacement.
-function _sed(options, regex, replacement, file) {
-  options = common.parseOptions(options, {
-    'i': 'inplace'
-  });
-
-  if (typeof replacement === 'string' || typeof replacement === 'function')
-    replacement = replacement; // no-op
-  else if (typeof replacement === 'number')
-    replacement = replacement.toString(); // fallback
-  else
-    common.error('invalid replacement string');
-
-  if (!file)
-    common.error('no file given');
-
-  if (!fs.existsSync(file))
-    common.error('no such file or directory: ' + file);
-
-  var result = fs.readFileSync(file, 'utf8').replace(regex, replacement);
-  if (options.inplace)
-    fs.writeFileSync(file, result, 'utf8');
-
-  return common.ShellString(result);
-}
-module.exports = _sed;

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/1d2725bf/node_modules/cordova-serve/node_modules/shelljs/src/tempdir.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/node_modules/shelljs/src/tempdir.js 
b/node_modules/cordova-serve/node_modules/shelljs/src/tempdir.js
deleted file mode 100644
index 45953c2..0000000
--- a/node_modules/cordova-serve/node_modules/shelljs/src/tempdir.js
+++ /dev/null
@@ -1,56 +0,0 @@
-var common = require('./common');
-var os = require('os');
-var fs = require('fs');
-
-// Returns false if 'dir' is not a writeable directory, 'dir' otherwise
-function writeableDir(dir) {
-  if (!dir || !fs.existsSync(dir))
-    return false;
-
-  if (!fs.statSync(dir).isDirectory())
-    return false;
-
-  var testFile = dir+'/'+common.randomFileName();
-  try {
-    fs.writeFileSync(testFile, ' ');
-    common.unlinkSync(testFile);
-    return dir;
-  } catch (e) {
-    return false;
-  }
-}
-
-
-//@
-//@ ### tempdir()
-//@
-//@ Examples:
-//@
-//@ ```javascript
-//@ var tmp = tempdir(); // "/tmp" for most *nix platforms
-//@ ```
-//@
-//@ Searches and returns string containing a writeable, platform-dependent 
temporary directory.
-//@ Follows Python's [tempfile 
algorithm](http://docs.python.org/library/tempfile.html#tempfile.tempdir).
-function _tempDir() {
-  var state = common.state;
-  if (state.tempDir)
-    return state.tempDir; // from cache
-
-  state.tempDir = writeableDir(os.tempDir && os.tempDir()) || // node 0.8+
-                  writeableDir(process.env['TMPDIR']) ||
-                  writeableDir(process.env['TEMP']) ||
-                  writeableDir(process.env['TMP']) ||
-                  writeableDir(process.env['Wimp$ScrapDir']) || // RiscOS
-                  writeableDir('C:\\TEMP') || // Windows
-                  writeableDir('C:\\TMP') || // Windows
-                  writeableDir('\\TEMP') || // Windows
-                  writeableDir('\\TMP') || // Windows
-                  writeableDir('/tmp') ||
-                  writeableDir('/var/tmp') ||
-                  writeableDir('/usr/tmp') ||
-                  writeableDir('.'); // last resort
-
-  return state.tempDir;
-}
-module.exports = _tempDir;

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/1d2725bf/node_modules/cordova-serve/node_modules/shelljs/src/test.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/node_modules/shelljs/src/test.js 
b/node_modules/cordova-serve/node_modules/shelljs/src/test.js
deleted file mode 100644
index 8a4ac7d..0000000
--- a/node_modules/cordova-serve/node_modules/shelljs/src/test.js
+++ /dev/null
@@ -1,85 +0,0 @@
-var common = require('./common');
-var fs = require('fs');
-
-//@
-//@ ### test(expression)
-//@ Available expression primaries:
-//@
-//@ + `'-b', 'path'`: true if path is a block device
-//@ + `'-c', 'path'`: true if path is a character device
-//@ + `'-d', 'path'`: true if path is a directory
-//@ + `'-e', 'path'`: true if path exists
-//@ + `'-f', 'path'`: true if path is a regular file
-//@ + `'-L', 'path'`: true if path is a symboilc link
-//@ + `'-p', 'path'`: true if path is a pipe (FIFO)
-//@ + `'-S', 'path'`: true if path is a socket
-//@
-//@ Examples:
-//@
-//@ ```javascript
-//@ if (test('-d', path)) { /* do something with dir */ };
-//@ if (!test('-f', path)) continue; // skip if it's a regular file
-//@ ```
-//@
-//@ Evaluates expression using the available primaries and returns 
corresponding value.
-function _test(options, path) {
-  if (!path)
-    common.error('no path given');
-
-  // hack - only works with unary primaries
-  options = common.parseOptions(options, {
-    'b': 'block',
-    'c': 'character',
-    'd': 'directory',
-    'e': 'exists',
-    'f': 'file',
-    'L': 'link',
-    'p': 'pipe',
-    'S': 'socket'
-  });
-
-  var canInterpret = false;
-  for (var key in options)
-    if (options[key] === true) {
-      canInterpret = true;
-      break;
-    }
-
-  if (!canInterpret)
-    common.error('could not interpret expression');
-
-  if (options.link) {
-    try {
-      return fs.lstatSync(path).isSymbolicLink();
-    } catch(e) {
-      return false;
-    }
-  }
-
-  if (!fs.existsSync(path))
-    return false;
-
-  if (options.exists)
-    return true;
-
-  var stats = fs.statSync(path);
-
-  if (options.block)
-    return stats.isBlockDevice();
-
-  if (options.character)
-    return stats.isCharacterDevice();
-
-  if (options.directory)
-    return stats.isDirectory();
-
-  if (options.file)
-    return stats.isFile();
-
-  if (options.pipe)
-    return stats.isFIFO();
-
-  if (options.socket)
-    return stats.isSocket();
-} // test
-module.exports = _test;

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/1d2725bf/node_modules/cordova-serve/node_modules/shelljs/src/to.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/node_modules/shelljs/src/to.js 
b/node_modules/cordova-serve/node_modules/shelljs/src/to.js
deleted file mode 100644
index f029999..0000000
--- a/node_modules/cordova-serve/node_modules/shelljs/src/to.js
+++ /dev/null
@@ -1,29 +0,0 @@
-var common = require('./common');
-var fs = require('fs');
-var path = require('path');
-
-//@
-//@ ### 'string'.to(file)
-//@
-//@ Examples:
-//@
-//@ ```javascript
-//@ cat('input.txt').to('output.txt');
-//@ ```
-//@
-//@ Analogous to the redirection operator `>` in Unix, but works with 
JavaScript strings (such as
-//@ those returned by `cat`, `grep`, etc). _Like Unix redirections, `to()` 
will overwrite any existing file!_
-function _to(options, file) {
-  if (!file)
-    common.error('wrong arguments');
-
-  if (!fs.existsSync( path.dirname(file) ))
-      common.error('no such file or directory: ' + path.dirname(file));
-
-  try {
-    fs.writeFileSync(file, this.toString(), 'utf8');
-  } catch(e) {
-    common.error('could not write to file (code '+e.code+'): '+file, true);
-  }
-}
-module.exports = _to;

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/1d2725bf/node_modules/cordova-serve/node_modules/shelljs/src/toEnd.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/node_modules/shelljs/src/toEnd.js 
b/node_modules/cordova-serve/node_modules/shelljs/src/toEnd.js
deleted file mode 100644
index f6d099d..0000000
--- a/node_modules/cordova-serve/node_modules/shelljs/src/toEnd.js
+++ /dev/null
@@ -1,29 +0,0 @@
-var common = require('./common');
-var fs = require('fs');
-var path = require('path');
-
-//@
-//@ ### 'string'.toEnd(file)
-//@
-//@ Examples:
-//@
-//@ ```javascript
-//@ cat('input.txt').toEnd('output.txt');
-//@ ```
-//@
-//@ Analogous to the redirect-and-append operator `>>` in Unix, but works with 
JavaScript strings (such as
-//@ those returned by `cat`, `grep`, etc).
-function _toEnd(options, file) {
-  if (!file)
-    common.error('wrong arguments');
-
-  if (!fs.existsSync( path.dirname(file) ))
-      common.error('no such file or directory: ' + path.dirname(file));
-
-  try {
-    fs.appendFileSync(file, this.toString(), 'utf8');
-  } catch(e) {
-    common.error('could not append to file (code '+e.code+'): '+file, true);
-  }
-}
-module.exports = _toEnd;

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/1d2725bf/node_modules/cordova-serve/node_modules/shelljs/src/which.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/node_modules/shelljs/src/which.js 
b/node_modules/cordova-serve/node_modules/shelljs/src/which.js
deleted file mode 100644
index 2822ecf..0000000
--- a/node_modules/cordova-serve/node_modules/shelljs/src/which.js
+++ /dev/null
@@ -1,83 +0,0 @@
-var common = require('./common');
-var fs = require('fs');
-var path = require('path');
-
-// Cross-platform method for splitting environment PATH variables
-function splitPath(p) {
-  for (i=1;i<2;i++) {}
-
-  if (!p)
-    return [];
-
-  if (common.platform === 'win')
-    return p.split(';');
-  else
-    return p.split(':');
-}
-
-function checkPath(path) {
-  return fs.existsSync(path) && fs.statSync(path).isDirectory() == false;
-}
-
-//@
-//@ ### which(command)
-//@
-//@ Examples:
-//@
-//@ ```javascript
-//@ var nodeExec = which('node');
-//@ ```
-//@
-//@ Searches for `command` in the system's PATH. On Windows looks for `.exe`, 
`.cmd`, and `.bat` extensions.
-//@ Returns string containing the absolute path to the command.
-function _which(options, cmd) {
-  if (!cmd)
-    common.error('must specify command');
-
-  var pathEnv = process.env.path || process.env.Path || process.env.PATH,
-      pathArray = splitPath(pathEnv),
-      where = null;
-
-  // No relative/absolute paths provided?
-  if (cmd.search(/\//) === -1) {
-    // Search for command in PATH
-    pathArray.forEach(function(dir) {
-      if (where)
-        return; // already found it
-
-      var attempt = path.resolve(dir + '/' + cmd);
-      if (checkPath(attempt)) {
-        where = attempt;
-        return;
-      }
-
-      if (common.platform === 'win') {
-        var baseAttempt = attempt;
-        attempt = baseAttempt + '.exe';
-        if (checkPath(attempt)) {
-          where = attempt;
-          return;
-        }
-        attempt = baseAttempt + '.cmd';
-        if (checkPath(attempt)) {
-          where = attempt;
-          return;
-        }
-        attempt = baseAttempt + '.bat';
-        if (checkPath(attempt)) {
-          where = attempt;
-          return;
-        }
-      } // if 'win'
-    });
-  }
-
-  // Command not found anywhere?
-  if (!checkPath(cmd) && !where)
-    return null;
-
-  where = where || path.resolve(cmd);
-
-  return common.ShellString(where);
-}
-module.exports = _which;

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/1d2725bf/node_modules/cordova-serve/package.json
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/package.json 
b/node_modules/cordova-serve/package.json
index 25d0c9d..2408589 100644
--- a/node_modules/cordova-serve/package.json
+++ b/node_modules/cordova-serve/package.json
@@ -1,6 +1,6 @@
 {
   "name": "cordova-serve",
-  "version": "0.1.3",
+  "version": "1.0.0",
   "description": "Apache Cordova server support for cordova-lib and 
cordova-browser.",
   "main": "serve.js",
   "repository": {
@@ -22,11 +22,9 @@
   },
   "dependencies": {
     "chalk": "^1.1.1",
-    "combined-stream": "^1.0.3",
-    "d8": "^0.4.4",
-    "mime": "^1.2.11",
-    "q": "^1.4.1",
-    "shelljs": "^0.5.3"
+    "compression": "^1.6.0",
+    "express": "^4.13.3",
+    "q": "^1.4.1"
   },
   "devDependencies": {
     "jshint": "^2.8.0"
@@ -38,10 +36,10 @@
     "node": ">= 0.12.0",
     "npm": ">= 2.5.1"
   },
-  "readme": "<!--\n#\n# Licensed to the Apache Software Foundation (ASF) under 
one\n# or more contributor license agreements.  See the NOTICE file\n# 
distributed with this work for additional information\n# regarding copyright 
ownership.  The ASF licenses this file\n# to you under the Apache License, 
Version 2.0 (the\n# \"License\"); you may not use this file except in 
compliance\n# with the License.  You may obtain a copy of the License at\n#\n# 
http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable 
law or agreed to in writing,\n# software distributed under the License is 
distributed on an\n# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 
ANY\n#  KIND, either express or implied.  See the License for the\n# specific 
language governing permissions and limitations\n# under the 
License.\n#\n-->\n\n# cordova-serve\nThis module can be used to serve up a 
Cordova application in the browser. It has no command-line, but rather is 
intended\nto be called using the
  following API:\n\n``` js\nvar serve = 
require('cordova-serve');\nserve.launchServer(opts);\nserve.servePlatform(platform,
 opts);\nserve.launchBrowser(ops);\nserve.sendStream(filePath, request, 
response[, readStream][, noCache]);\n```\n\n## launchServer()\n\n``` 
js\nlaunchServer(opts);\n```\n\nLaunches a server with the specified options. 
Parameters:\n\n* **opts**: Options, as described below.\n\n## 
servePlatform()\n\n``` js\nservePlatform(platform, opts);\n```\n\nLaunches a 
server that serves up any Cordova platform (e.g. `browser`, `android` etc) from 
the current project.\nParameters:\n\n* **opts**: Options, as described below. 
Note that for `servePlatform()`, the `root` value should be a Cordova 
project's\n  root folder, or any folder within it - `servePlatform()` will 
replace it with the platform's `www_dir` folder. If this\n  value is not 
specified, the *cwd* will be used.\n\n## launchBrowser()\n\n``` 
js\nlaunchBrowser(opts);\n```\n\nLaunches a browser window pointing to the sp
 ecified URL. The single parameter is an options object that supports 
the\nfollowing values (both optional):\n\n* **url**: The URL to open in the 
browser.\n* **target**: The name of the browser to launch. Can be any of the 
following: `chrome`, `chromium`, `firefox`, `ie`,\n  `opera`, `safari`. If no 
browser is specified, \n\n## sendStream()\n\n``` js\nsendStream(filePath, 
request, response[, readStream][, noCache]);\n```\n\nThe server uses this 
method to stream files, and it is provided as a convenience method you can use 
if you are\ncustomizing the stream by specifying `opts.streamHandler`. 
Parameters:\n\n* **filePath**: The absolute path to the file to be served 
(which will have been passed to your `streamHandler`).\n* **request**: The 
request object (which will have been passed to your `streamHandler`).\n* 
**response**: The response object (which will have been passed to your 
`streamHandler`).\n* **readStream**: (optional) A custom read stream, if 
required.\n* **noCache**: (option
 al) If true, browser caching will be disabled for this file (by setting 
response header\n  Cache-Control will be set to 'no-cache')\n\n## The *opts* 
Options Object\nThe opts object passed to `launchServer()` and 
`servePlatform()` supports the following values (all optional):\n\n* **root**: 
The file path on the local file system that is used as the root for the server, 
for default mapping of URL\n  path to local file system path.   \n* **port**: 
The port for the server. Note that if this port is already in use, it will be 
incremented until a free port\n  is found.\n* **urlPathHandler**: An optional 
method to provide custom handling for processing URLs and serving up the 
resulting data.\n  Can serve up the data itself using `response.write()`, or 
determine a custom local file path and call `serveFile()` to\n  serve it up, or 
do no processing and call `serveFile` with no params to treat `urlPath` as 
relative to the root.\n* **streamHandler**: An optional custom stream handler - 
`cordov
 a-serve` will by default stream files using\n  `sendStream()`, described 
above, which just streams files, but will first call this method, if provided, 
to\n  support custom streaming. This method is described in more detail 
below.\n* **serverExtender**: This method is called as soon as the server is 
created, so that the caller can do\n  additional things with the server (like 
attach to certain events, for example). This method is described in more\n  
detail below.\n\n## urlPathHandler()\nProvide this method if you need to do 
custom processing of URL paths (that is, custom mapping of URL path to local 
file\npath) and potentially directly handle serving up the resulting data. The 
signature of this method is as follows:\n\n``` js\nurlPathHandler(urlPath, 
request, response, do302, do404, serveFile)\n```\n\nParameters:\n\n* 
**urlPath**: The URL path to process. It is the value of 
`url.parse(request.url).pathname`.\n* **request**: The server request 
object.\n* **response**: The server res
 ponse object.\n* **do302**: A helper method to do a 302 HTTP response 
(redirection). It takes a single parameter - the URL to redirect to.\n* 
**do404**: A helper method to do a 404 HTTP response (not found).\n* 
**serveFile**: A helper method to serve up the resulting file. If 
`urlPathHandler()` doesn't write the response itself,\n  it should call this 
method either passing it the local file path to be served, or passing it 
nothing. In the latter case,\n  it will treat `urlPath` as relative to the 
root.\n\n## streamHandler()\nProvide this method if you wish to perform custom 
stream handling. The signature of this method is as follows:\n\n``` 
js\nstreamHandler(filePath, request, response)\n```\n\nParameters:\n\n* 
**filePath**: This is the path to the local file that will be streamed. It 
might be the value you returned from\n  urlPathProcessor(), in which case it 
doesn't necessarily have to reference an actual file: it might just be an\n  
identifier string that your custom stream handl
 er will recognize. If you are going to end up calling `sendStream()`,\n  it is 
useful if even a fake file name has a file extension, as that is used for mime 
type lookup.\n* **request**: The server request object.\n* **response**: The 
serve response object.\n\nReturn value:\n\nReturn `true` if you have handled 
the stream request, otherwise `false`.\n\n## serverExtender()\n\nIf you provide 
this method, it will be called as soon as the server is created. It allows you 
to attach additional\nfunctionality to the server, such has event handlers, web 
sockets etc.  The signature of this method is as follows:\n\n``` 
js\nserverExtender(server, root)\n```\n\nParameters:\n\n* **server**: A 
reference to the server (the result of calling `http.createServer()`).\n* 
**root**: The file path on the local file system that is used as the root for 
the server (if it was provided), for\n  default mapping of URL path to local 
file system path.\n\n",
+  "readme": "<!--\n#\n# Licensed to the Apache Software Foundation (ASF) under 
one\n# or more contributor license agreements.  See the NOTICE file\n# 
distributed with this work for additional information\n# regarding copyright 
ownership.  The ASF licenses this file\n# to you under the Apache License, 
Version 2.0 (the\n# \"License\"); you may not use this file except in 
compliance\n# with the License.  You may obtain a copy of the License at\n#\n# 
http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable 
law or agreed to in writing,\n# software distributed under the License is 
distributed on an\n# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF 
ANY\n#  KIND, either express or implied.  See the License for the\n# specific 
language governing permissions and limitations\n# under the 
License.\n#\n-->\n\n# cordova-serve\nThis module can be used to serve up a 
Cordova application in the browser. It has no command-line, but rather is 
intended\nto be called using the
  following API:\n\n``` js\nvar serve = 
require('cordova-serve');\nserve.launchServer(opts);\nserve.servePlatform(platform,
 opts);\nserve.launchBrowser(ops);\n```\n\n## launchServer()\n\n``` 
js\nlaunchServer(opts);\n```\n\nLaunches a server with the specified options. 
Parameters:\n\n* **opts**: Options, as described below.\n\n## 
servePlatform()\n\n``` js\nservePlatform(platform, opts);\n```\n\nLaunches a 
server that serves up any Cordova platform (e.g. `browser`, `android` etc) from 
the current project.\nParameters:\n\n* **opts**: Options, as described below. 
Note that for `servePlatform()`, the `root` value should be a Cordova 
project's\n  root folder, or any folder within it - `servePlatform()` will 
replace it with the platform's `www_dir` folder. If this\n  value is not 
specified, the *cwd* will be used.\n\n## launchBrowser()\n\n``` 
js\nlaunchBrowser(opts);\n```\n\nLaunches a browser window pointing to the 
specified URL. The single parameter is an options object that supports the\
 nfollowing values (both optional):\n\n* **url**: The URL to open in the 
browser.\n* **target**: The name of the browser to launch. Can be any of the 
following: `chrome`, `chromium`, `firefox`, `ie`,\n  `opera`, `safari`. If no 
browser is specified, \n\n## The *opts* Options Object\nThe opts object passed 
to `launchServer()` and `servePlatform()` supports the following values (all 
optional):\n\n* **root**: The file path on the local file system that is used 
as the root for the server, for default mapping of URL\n  path to local file 
system path.   \n* **port**: The port for the server. Note that if this port is 
already in use, it will be incremented until a free port\n  is found.\n* 
**router**: An `ExpressJS` router. If provided, this will be attached *before* 
default static handling.\n* **noLogOutput**: If `true`, turns off all log 
output. \n* **noServerInfo**: If `true`, cordova-serve won't output `Static 
file server running on...` message.\n* **events**: An `EventEmitter` to use f
 or logging. If provided, logging will be output using `events.emit('log', 
msg)`.\n  If not provided, `console.log()` will be used. Note that nothing will 
be output in either case if `noLogOutput` is `true`.\n",
   "readmeFilename": "README.md",
-  "_id": "cordova-serve@0.1.3",
-  "_shasum": "0c843197342cd4e85bdcd78d22887ec63a1a1dbf",
-  "_resolved": "file:CB-9547\\cordova-serve-0.1.3.tgz",
-  "_from": "cordova-serve@>=0.1.3 <0.2.0"
+  "_id": "cordova-serve@1.0.0",
+  "_shasum": "7fa1c40183d2b82adb792f9cb9e0d554a23eed85",
+  "_resolved": 
"https://registry.npmjs.org/cordova-serve/-/cordova-serve-1.0.0.tgz";,
+  "_from": "cordova-serve@>=1.0.0 <2.0.0"
 }

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/1d2725bf/node_modules/cordova-serve/serve.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/serve.js 
b/node_modules/cordova-serve/serve.js
index b477a7a..10d000a 100644
--- a/node_modules/cordova-serve/serve.js
+++ b/node_modules/cordova-serve/serve.js
@@ -17,9 +17,41 @@
  under the License.
  */
 
-module.exports = {
-    sendStream: require('./src/stream'),
-    servePlatform: require('./src/platform'),
-    launchServer: require('./src/server'),
-    launchBrowser: require('./src/browser')
+var chalk = require('chalk'),
+    compression = require('compression'),
+    express = require('express'),
+    server = require('./src/server');
+
+module.exports = function () {
+    return new CordovaServe();
 };
+
+function CordovaServe() {
+    this.app = express();
+
+    // Attach this before anything else to provide status output
+    this.app.use(function (req, res, next) {
+        res.on('finish', function () {
+            var color = this.statusCode == '404' ? chalk.red : chalk.green;
+            var msg = color(this.statusCode) + ' ' + this.req.originalUrl;
+            var encoding = this._headers && this._headers['content-encoding'];
+            if (encoding) {
+                msg += chalk.gray(' (' + encoding + ')');
+            }
+            server.log(msg);
+        });
+        next();
+    });
+
+    // Turn on compression
+    this.app.use(compression());
+
+    this.servePlatform = require('./src/platform');
+    this.launchServer = server;
+}
+
+module.exports.launchBrowser = require('./src/browser');
+
+// Expose some useful express statics
+module.exports.Router = express.Router;
+module.exports.static = express.static;

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/1d2725bf/node_modules/cordova-serve/src/platform.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/src/platform.js 
b/node_modules/cordova-serve/src/platform.js
index 940b71b..7abbb81 100644
--- a/node_modules/cordova-serve/src/platform.js
+++ b/node_modules/cordova-serve/src/platform.js
@@ -17,8 +17,7 @@
  under the License.
  */
 
-var server = require('./server'),
-    fs     = require('fs'),
+var fs     = require('fs'),
     Q      = require('q'),
     util   = require('./util');
 
@@ -31,6 +30,7 @@ var server = require('./server'),
  * @returns {*|promise}
  */
 module.exports = function (platform, opts) {
+    var that = this;
     return Q().then(function () {
         if (!platform) {
             throw new Error('A platform must be specified');
@@ -38,16 +38,14 @@ module.exports = function (platform, opts) {
 
         opts = opts || {};
         var projectRoot = findProjectRoot(opts.root);
-        var platformRoot = opts.root = util.getPlatformWwwRoot(projectRoot, 
platform);
+        that.projectRoot = projectRoot;
+
+        opts.root = util.getPlatformWwwRoot(projectRoot, platform);
         if (!fs.existsSync(opts.root)) {
             throw new Error('Project does not include the specified platform: 
' + platform);
         }
 
-        return server(opts).then(function (serverInfo) {
-            serverInfo.projectRoot = projectRoot;
-            serverInfo.platformRoot = platformRoot;
-            return serverInfo;
-        });
+        return that.launchServer(opts);
     });
 };
 

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/1d2725bf/node_modules/cordova-serve/src/server.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/src/server.js 
b/node_modules/cordova-serve/src/server.js
index ea31831..bb10a21 100644
--- a/node_modules/cordova-serve/src/server.js
+++ b/node_modules/cordova-serve/src/server.js
@@ -17,121 +17,51 @@
  under the License.
  */
 
-var chalk  = require('chalk'),
-    fs     = require('fs'),
-    http   = require('http'),
-    url    = require('url'),
-    path   = require('path'),
-    Q      = require('q');
+var chalk   = require('chalk'),
+    express = require('express'),
+    Q       = require('q');
 
 /**
  * @desc Launches a server with the specified options and optional custom 
handlers.
- * @param {{root: ?string, port: ?number, noLogOutput: ?bool, noServerInfo: 
?bool, urlPathHandler: ?function, streamHandler: ?function, serverExtender: 
?function}} opts
- *     urlPathHandler(urlPath, request, response, do302, do404, serveFile) - 
an optional method to provide custom handling for
- *         processing URLs and serving up the resulting data. Can serve up the 
data itself using response.write(), or determine
- *         a custom local file path and call serveFile to serve it up, or do 
no processing and call serveFile with no params to
- *         treat urlPath as relative to the root.
- *     streamHandler(filePath, request, response) - an optional custom stream 
handler, to stream whatever you want. If not
- *         provided, the file referenced by filePath will be streamed. Return 
true if the file is handled.
- *     serverExtender(server, root) - if provided, is called as soon as server 
is created so caller can attached to events etc.
+ * @param {{root: ?string, port: ?number, noLogOutput: ?bool, noServerInfo: 
?bool, router: ?express.Router, events: EventEmitter}} opts
  * @returns {*|promise}
  */
 module.exports = function (opts) {
     var deferred = Q.defer();
 
     opts = opts || {};
-    var root = opts.root;
     var port = opts.port || 8000;
 
-    var log = module.exports.log = function () {
+    var log = module.exports.log = function (msg) {
         if (!opts.noLogOutput) {
-            console.log.apply(console, arguments);
+            if (opts.events) {
+                opts.events.emit('log', msg);
+            } else {
+                console.log(msg);
+            }
         }
     };
 
-    var server = http.createServer(function (request, response) {
-        function do404() {
-            log(chalk.red('404 ') + request.url);
-            response.writeHead(404, {'Content-Type': 'text/plain'});
-            response.write('404 Not Found\n');
-            response.end();
-        }
-
-        function do302(where) {
-            log(chalk.green('302 ') + request.url);
-            response.setHeader('Location', where);
-            response.writeHead(302, {'Content-Type': 'text/plain'});
-            response.end();
-        }
-
-        function do304() {
-            log(chalk.green('304 ') + request.url);
-            response.writeHead(304, {'Content-Type': 'text/plain'});
-            response.end();
-        }
-
-        function isFileChanged(path) {
-            var mtime = fs.statSync(path).mtime,
-                itime = request.headers['if-modified-since'];
-            return !itime || new Date(mtime) > new Date(itime);
-        }
-
-        var urlPath = url.parse(request.url).pathname;
+    var app = this.app;
+    var server = require('http').Server(app);
+    this.server = server;
 
-        if (opts.urlPathHandler) {
-            opts.urlPathHandler(urlPath, request, response, do302, do404, 
serveFile);
-        } else {
-            serveFile();
-        }
-
-        function serveFile(filePath) {
-            if (!filePath) {
-                if (!root) {
-                    throw new Error('No server root directory HAS BEEN 
specified!');
-                }
-                filePath = path.join(root, urlPath);
-            }
+    if (opts.router) {
+        app.use(opts.router);
+    }
 
-            fs.exists(filePath, function (exists) {
-                if (!exists) {
-                    do404();
-                    return;
-                }
-                if (fs.statSync(filePath).isDirectory()) {
-                    var index = path.join(filePath, 'index.html');
-                    if (fs.existsSync(index)) {
-                        filePath = index;
-                    }
-                }
-                if (fs.statSync(filePath).isDirectory()) {
-                    if (!/\/$/.test(urlPath)) {
-                        do302(request.url + '/');
-                        return;
-                    }
-                    log(chalk.green('200 ') + request.url);
-                    response.writeHead(200, {'Content-Type': 'text/html'});
-                    response.write('<html><head><title>Directory listing of ' 
+ urlPath + '</title></head>');
-                    response.write('<h3>Items in this directory</h3>');
-                    response.write('<ul>');
-                    fs.readdirSync(filePath).forEach(function (file) {
-                        response.write('<li><a href="' + file + '">' + file + 
'</a></li>\n');
-                    });
+    if (opts.root) {
+        this.root = opts.root;
+        app.use(express.static(opts.root));
+    }
 
-                    response.write('</ul>');
-                    response.end();
-                } else if (!isFileChanged(filePath)) {
-                    do304();
-                } else {
-                    var streamHandler = opts.streamHandler || 
require('./stream');
-                    streamHandler(filePath, request, response);
-                }
-            });
-        }
-    }).on('listening', function () {
+    var that = this;
+    server.listen(port).on('listening', function () {
+        that.port = port;
         if (!opts.noServerInfo) {
             log('Static file server running on: ' + 
chalk.green('http://localhost:' + port) + ' (CTRL + C to shut down)');
         }
-        deferred.resolve({server: server, port: port});
+        deferred.resolve();
     }).on('error', function (e) {
         if (e && e.toString().indexOf('EADDRINUSE') !== -1) {
             port++;
@@ -139,11 +69,7 @@ module.exports = function (opts) {
         } else {
             deferred.reject(e);
         }
-    }).listen(port);
-
-    if (opts.serverExtender) {
-        opts.serverExtender(server, root);
-    }
+    });
 
     return deferred.promise;
 };

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/1d2725bf/node_modules/cordova-serve/src/stream.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/src/stream.js 
b/node_modules/cordova-serve/src/stream.js
deleted file mode 100644
index dd6ebaf..0000000
--- a/node_modules/cordova-serve/src/stream.js
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- 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 chalk = require('chalk'),
-    fs = require('fs'),
-    mime = require('mime'),
-    zlib = require('zlib'),
-    server = require('./server');
-
-// d8 is a date parsing and formatting micro-framework
-// Used only for RFC 2822 formatting
-require('d8');
-require('d8/locale/en-US');
-
-/**
- * Streams a file
- * @param {string} filePath - the file to stream (if a readStream is provided, 
this can be a dummy file name to provide mime type)
- * @param {http.IncomingMessage} request - request object provided by request 
event.
- * @param {http.ServerResponse} response - response object provided by request 
event.
- * @param {ReadStream} [readStream] - an optional read stream (for custom 
handling).
- * @param {boolean} [noCache] - if true, response header Cache-Control will be 
set to 'no-cache'.
- * @returns {ReadStream} - the provided ReadStream, otherwise one created for 
the specified file.
- */
-module.exports = function (filePath, request, response, readStream, noCache) {
-    if ((typeof readStream) === 'boolean') {
-        noCache = readStream;
-        readStream = null;
-    }
-
-    var mimeType = mime.lookup(filePath);
-    var respHeaders = {
-        'Content-Type': mimeType
-    };
-
-    if (!readStream) {
-        readStream = fs.createReadStream(filePath);
-    }
-
-    var acceptEncoding = request.headers['accept-encoding'] || '';
-    var encoding = '';
-    if (acceptEncoding.match(/\bgzip\b/)) {
-        encoding ='(gzip)';
-        respHeaders['content-encoding'] = 'gzip';
-        readStream = readStream.pipe(zlib.createGzip());
-    } else if (acceptEncoding.match(/\bdeflate\b/)) {
-        encoding ='(deflate)';
-        respHeaders['content-encoding'] = 'deflate';
-        readStream = readStream.pipe(zlib.createDeflate());
-    }
-
-    respHeaders['Last-Modified'] = new 
Date(fs.statSync(filePath).mtime).format('r');
-    if (noCache) {
-        respHeaders['Cache-Control'] = 'no-store';
-    }
-    server.log(chalk.green('200 ') + request.url + ' ' + encoding);
-    response.writeHead(200, respHeaders);
-    readStream.pipe(response);
-    return readStream;
-};

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/1d2725bf/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index d2e1710..0c567f9 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,7 @@
   },
   "dependencies": {
     "adm-zip": "0.4.4",
-    "cordova-serve": "^0.1.2",
+    "cordova-serve": "^1.0.0",
     "nopt": "~3",
     "q": "^1.4.1",
     "shelljs": "^0.1.4"


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to