cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [03/16] cordova-browser git commit: Update 'cordova run browser' command to use cordova-serve module.
Date Sat, 20 Jun 2015 19:33:30 GMT
http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/0044fe33/node_modules/cordova-serve/src/browser.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/src/browser.js b/node_modules/cordova-serve/src/browser.js
new file mode 100644
index 0000000..5b3b40e
--- /dev/null
+++ b/node_modules/cordova-serve/src/browser.js
@@ -0,0 +1,100 @@
+/**
+ 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 exec = require('./exec'),
+    Q = require('q');
+
+/**
+ * Launches the specified browser with the given URL.
+ * Based on https://github.com/domenic/opener
+ * @param {{target: ?string, url: ?string, dataDir: ?string}} opts - parameters:
+ *   target - the target browser - ie, chrome, safari, opera, firefox or chromium
+ *   url - the url to open in the browser
+ *   dataDir - a data dir to provide to Chrome (can be used to force it to open in a new
window)
+ * @return {Q} Promise to launch the specified browser
+ */
+module.exports = function (opts) {
+    //target, url, dataDir
+    var target = opts.target || 'chrome';
+    var url = opts.url || '';
+
+    return getBrowser(target, opts.dataDir).then(function (browser) {
+        var args;
+        switch (process.platform) {
+            case 'darwin':
+                args = ['open'];
+                if (target == 'chrome') {
+                    // Chrome needs to be launched in a new window. Other browsers, particularly,
opera does not work with this.        
+                    args.push('-n');
+                }
+                args.push('-a', browser);
+                break;
+            case 'win32':
+                // On Windows, we really want to use the "start" command. But, the rules
regarding arguments with spaces, and 
+                // escaping them with quotes, can get really arcane. So the easiest way to
deal with this is to pass off the 
+                // responsibility to "cmd /c", which has that logic built in. 
+                // 
+                // Furthermore, if "cmd /c" double-quoted the first parameter, then "start"
will interpret it as a window title, 
+                // so we need to add a dummy empty-string window title: http://stackoverflow.com/a/154090/3191

+                args = ['cmd /c start ""', browser];
+                break;
+            case 'linux':
+                // if a browser is specified, launch it with the url as argument
+                // otherwise, use xdg-open.
+                args = [browser];
+                break;
+        }
+        args.push(url);
+        var command = args.join(' ');
+        console.log('Executing command: ' + command);
+        return exec(command);
+    });
+};
+
+function getBrowser(target, dataDir) {
+    dataDir = dataDir || 'temp_chrome_user_data_dir_for_cordova';
+
+    var chromeArgs = ' --user-data-dir=/tmp/' + dataDir;
+    var browsers = {
+        'win32': {
+            'ie': 'iexplore',
+            'chrome': 'chrome --user-data-dir=%TEMP%\\' + dataDir,
+            'safari': 'safari',
+            'opera': 'opera',
+            'firefox': 'firefox'
+        },
+        'darwin': {
+            'chrome': '"Google Chrome" --args' + chromeArgs,
+            'safari': 'safari',
+            'firefox': 'firefox',
+            'opera': 'opera'
+        },
+        'linux' : {
+            'chrome': 'google-chrome' + chromeArgs ,
+            'chromium': 'chromium-browser' + chromeArgs,
+            'firefox': 'firefox',
+            'opera': 'opera'
+        }
+    };
+    target = target.toLowerCase();
+    if (target in browsers[process.platform]) {
+        return Q(browsers[process.platform][target]);
+    }
+    return Q.reject('Browser target not supported: ' + target);
+}

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/0044fe33/node_modules/cordova-serve/src/exec.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/src/exec.js b/node_modules/cordova-serve/src/exec.js
new file mode 100644
index 0000000..d1c02a4
--- /dev/null
+++ b/node_modules/cordova-serve/src/exec.js
@@ -0,0 +1,46 @@
+/*
+ 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 child_process = require('child_process'),
+    Q             = require('q');
+
+/**
+ * Executes the command specified.
+ * @param  {string} cmd Command to execute
+ * @param  {[string]}  opt_cwd Current working directory
+ * @return {Q} promise a promise that either resolves with the stdout, or rejects with an
error message and the stderr.
+ */
+module.exports = function (cmd, opt_cwd) {
+    var d = Q.defer();
+    try {
+        child_process.exec(cmd, {cwd: opt_cwd, maxBuffer: 1024000}, function (err, stdout,
stderr) {
+            if (err) {
+                d.reject(new Error('Error executing "' + cmd + '": ' + stderr));
+            }
+            else {
+                d.resolve(stdout);
+            }
+        });
+    } catch (e) {
+        console.error('error caught: ' + e);
+        d.reject(e);
+    }
+    return d.promise;
+};
+

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/0044fe33/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
new file mode 100644
index 0000000..12b169b
--- /dev/null
+++ b/node_modules/cordova-serve/src/platform.js
@@ -0,0 +1,59 @@
+/**
+ 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 server = require('./server'),
+    fs     = require('fs'),
+    Q      = require('q'),
+    util   = require('./util');
+
+/**
+ * Launches a server where the root points to the specified platform in a Cordova project.
+ * @param {string} platform - Cordova platform to serve.
+ * @param {{root: ?string, port: ?number, urlPathProcessor: ?function, streamHandler: ?function,
serverExtender: ?function}} opts
+ *   root - cordova project directory, or any directory within it. If not specified, cwd
is used. This will be modified to point to the platform's www_dir.
+ *   All other values are passed unaltered to launchServer().
+ * @returns {*|promise}
+ */
+module.exports = function (platform, opts) {
+    return Q().then(function () {
+        if (!platform) {
+            throw new Error('A platform must be specified');
+        }
+
+        opts = opts || {};
+        opts.root = util.getPlatformWwwRoot(findProjectRoot(opts.root), platform);
+        if (!fs.existsSync(opts.root)) {
+            throw new Error('Project does not include the specified platform: ' + platform);
+        }
+
+        return server(opts);
+    });
+};
+
+function findProjectRoot(path) {
+    var projectRoot = util.cordovaProjectRoot(path);
+    if (!projectRoot) {
+        if (!path) {
+            throw new Error('Current directory does not appear to be in a Cordova project.');
+        } else {
+            throw new Error('Directory "' + path + '" does not appear to be in a Cordova
project.');
+        }
+    }
+    return projectRoot;
+}

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/0044fe33/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
new file mode 100644
index 0000000..eafacc1
--- /dev/null
+++ b/node_modules/cordova-serve/src/server.js
@@ -0,0 +1,141 @@
+/**
+ 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 fs     = require('fs'),
+    http   = require('http'),
+    url    = require('url'),
+    path   = require('path'),
+    Q      = require('q'),
+    stream = require('./stream');
+
+/**
+ * @desc Launches a server with the specified options and optional custom handlers.
+ * @param {{root: ?string, port: ?number, 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.
+ * @returns {*|promise}
+ */
+module.exports = function (opts) {
+    var deferred = Q.defer();
+
+    opts = opts || {};
+    var root = opts.root;
+    var port = opts.port || 8000;
+
+    var server = http.createServer(function (request, response) {
+        function do404() {
+            console.log('404 ' + request.url);
+            response.writeHead(404, {'Content-Type': 'text/plain'});
+            response.write('404 Not Found\n');
+            response.end();
+        }
+
+        function do302(where) {
+            console.log('302 ' + request.url);
+            response.setHeader('Location', where);
+            response.writeHead(302, {'Content-Type': 'text/plain'});
+            response.end();
+        }
+
+        function do304() {
+            console.log('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;
+
+        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);
+            }
+
+            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;
+                    }
+                    console.log('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');
+                    });
+
+                    response.write('</ul>');
+                    response.end();
+                } else if (!isFileChanged(filePath)) {
+                    do304();
+                } else {
+                    var streamHandler = opts.streamHandler || stream;
+                    streamHandler(filePath, request, response);
+                }
+            });
+        }
+    }).on('listening', function () {
+        console.log('Static file server running on port ' + port + ' (i.e. http://localhost:'
+ port + ')\nCTRL + C to shut down');
+        deferred.resolve({server: server, port: port});
+    }).on('error', function (e) {
+        if (e && e.toString().indexOf('EADDRINUSE') !== -1) {
+            port++;
+            server.listen(port);
+        } 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/0044fe33/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
new file mode 100644
index 0000000..b16de62
--- /dev/null
+++ b/node_modules/cordova-serve/src/stream.js
@@ -0,0 +1,72 @@
+/**
+ 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 fs = require('fs'),
+    mime = require('mime'),
+    zlib = require('zlib');
+
+// 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'] || '';
+    if (acceptEncoding.match(/\bgzip\b/)) {
+        console.log('gzip');
+        respHeaders['content-encoding'] = 'gzip';
+        readStream = readStream.pipe(zlib.createGzip());
+    } else if (acceptEncoding.match(/\bdeflate\b/)) {
+        console.log('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-cache';
+    }
+    console.log('200 ' + request.url + ' (' + filePath + ')');
+    response.writeHead(200, respHeaders);
+    readStream.pipe(response);
+    return readStream;
+};

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/0044fe33/node_modules/cordova-serve/src/util.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-serve/src/util.js b/node_modules/cordova-serve/src/util.js
new file mode 100644
index 0000000..8fb076b
--- /dev/null
+++ b/node_modules/cordova-serve/src/util.js
@@ -0,0 +1,104 @@
+/**
+ 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 fs   = require('fs'),
+    path = require('path');
+
+// Some helpful utility stuff copied from cordova-lib. This is a bit nicer than taking a
dependency on cordova-lib just
+// to get this minimal stuff. Hopefully we won't need the platform stuff (finding platform
www_dir) once it is moved
+// into the actual platform.
+
+var platforms = {
+    amazon_fireos: {www_dir: 'assets/www'},
+    android: {www_dir: 'assets/www'},
+    blackberry10: {www_dir: 'www'},
+    browser: {www_dir: 'www'},
+    firefoxos: {www_dir: 'www'},
+    ios: {www_dir: 'www'},
+    ubuntu: {www_dir: 'www'},
+    windows: {www_dir: 'www'},
+    wp8: {www_dir: 'www'}
+};
+
+/**
+ * @desc Look for a Cordova project's root directory, starting at the specified directory
(or CWD if none specified).
+ * @param {string=} dir - the directory to start from (we check this directory then work
up), or CWD if none specified.
+ * @returns {string} - the Cordova project's root directory, or null if not found.
+ */
+function cordovaProjectRoot(dir) {
+    if (!dir) {
+        // Prefer PWD over cwd so that symlinked dirs within your PWD work correctly.
+        var pwd = process.env.PWD;
+        var cwd = process.cwd();
+        if (pwd && pwd != cwd && pwd != 'undefined') {
+            return cordovaProjectRoot(pwd) || cordovaProjectRoot(cwd);
+        }
+        return cordovaProjectRoot(cwd);
+    }
+
+    var bestReturnValueSoFar = null;
+    for (var i = 0; i < 1000; ++i) {
+        var result = isRootDir(dir);
+        if (result === 2) {
+            return dir;
+        }
+        if (result === 1) {
+            bestReturnValueSoFar = dir;
+        }
+        var parentDir = path.normalize(path.join(dir, '..'));
+        // Detect fs root.
+        if (parentDir == dir) {
+            return bestReturnValueSoFar;
+        }
+        dir = parentDir;
+    }
+    return null;
+}
+
+function getPlatformWwwRoot(cordovaProjectRoot, platformName) {
+    var platform = platforms[platformName];
+    if (!platform) {
+        throw new Error ('Unrecognized platform: ' + platformName);
+    }
+    return path.join(cordovaProjectRoot, 'platforms', platformName, platform.www_dir);
+}
+
+function isRootDir(dir) {
+    if (fs.existsSync(path.join(dir, 'www'))) {
+        if (fs.existsSync(path.join(dir, 'config.xml'))) {
+            // For sure is.
+            if (fs.existsSync(path.join(dir, 'platforms'))) {
+                return 2;
+            } else {
+                return 1;
+            }
+        }
+        // Might be (or may be under platforms/).
+        if (fs.existsSync(path.join(dir, 'www', 'config.xml'))) {
+            return 1;
+        }
+    }
+    return 0;
+}
+
+module.exports = {
+    cordovaProjectRoot: cordovaProjectRoot,
+    getPlatformWwwRoot: getPlatformWwwRoot,
+    platforms: platforms
+};

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/0044fe33/node_modules/mime/LICENSE
----------------------------------------------------------------------
diff --git a/node_modules/mime/LICENSE b/node_modules/mime/LICENSE
deleted file mode 100644
index 451fc45..0000000
--- a/node_modules/mime/LICENSE
+++ /dev/null
@@ -1,19 +0,0 @@
-Copyright (c) 2010 Benjamin Thomas, Robert Kieffer
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/0044fe33/node_modules/mime/README.md
----------------------------------------------------------------------
diff --git a/node_modules/mime/README.md b/node_modules/mime/README.md
deleted file mode 100644
index 6ca19bd..0000000
--- a/node_modules/mime/README.md
+++ /dev/null
@@ -1,66 +0,0 @@
-# mime
-
-Comprehensive MIME type mapping API. Includes all 600+ types and 800+ extensions defined
by the Apache project, plus additional types submitted by the node.js community.
-
-## Install
-
-Install with [npm](http://github.com/isaacs/npm):
-
-    npm install mime
-
-## API - Queries
-
-### mime.lookup(path)
-Get the mime type associated with a file, if no mime type is found `application/octet-stream`
is returned. Performs a case-insensitive lookup using the extension in `path` (the substring
after the last '/' or '.').  E.g.
-
-    var mime = require('mime');
-
-    mime.lookup('/path/to/file.txt');         // => 'text/plain'
-    mime.lookup('file.txt');                  // => 'text/plain'
-    mime.lookup('.TXT');                      // => 'text/plain'
-    mime.lookup('htm');                       // => 'text/html'
-
-### mime.default_type
-Sets the mime type returned when `mime.lookup` fails to find the extension searched for.
(Default is `application/octet-stream`.)
-
-### mime.extension(type)
-Get the default extension for `type`
-
-    mime.extension('text/html');                 // => 'html'
-    mime.extension('application/octet-stream');  // => 'bin'
-
-### mime.charsets.lookup()
-
-Map mime-type to charset
-
-    mime.charsets.lookup('text/plain');        // => 'UTF-8'
-
-(The logic for charset lookups is pretty rudimentary.  Feel free to suggest improvements.)
-
-## API - Defining Custom Types
-
-The following APIs allow you to add your own type mappings within your project.  If you feel
a type should be included as part of node-mime, see [requesting new types](https://github.com/broofa/node-mime/wiki/Requesting-New-Types).
-
-### mime.define()
-
-Add custom mime/extension mappings
-
-    mime.define({
-        'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
-        'application/x-my-type': ['x-mt', 'x-mtt'],
-        // etc ...
-    });
-
-    mime.lookup('x-sft');                 // => 'text/x-some-format'
-
-The first entry in the extensions array is returned by `mime.extension()`. E.g.
-
-    mime.extension('text/x-some-format'); // => 'x-sf'
-
-### mime.load(filepath)
-
-Load mappings from an Apache ".types" format file
-
-    mime.load('./my_project.types');
-
-The .types file format is simple -  See the `types` dir for examples.

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/0044fe33/node_modules/mime/mime.js
----------------------------------------------------------------------
diff --git a/node_modules/mime/mime.js b/node_modules/mime/mime.js
deleted file mode 100644
index 48be0c5..0000000
--- a/node_modules/mime/mime.js
+++ /dev/null
@@ -1,114 +0,0 @@
-var path = require('path');
-var fs = require('fs');
-
-function Mime() {
-  // Map of extension -> mime type
-  this.types = Object.create(null);
-
-  // Map of mime type -> extension
-  this.extensions = Object.create(null);
-}
-
-/**
- * Define mimetype -> extension mappings.  Each key is a mime-type that maps
- * to an array of extensions associated with the type.  The first extension is
- * used as the default extension for the type.
- *
- * e.g. mime.define({'audio/ogg', ['oga', 'ogg', 'spx']});
- *
- * @param map (Object) type definitions
- */
-Mime.prototype.define = function (map) {
-  for (var type in map) {
-    var exts = map[type];
-
-    for (var i = 0; i < exts.length; i++) {
-      if (process.env.DEBUG_MIME && this.types[exts]) {
-        console.warn(this._loading.replace(/.*\//, ''), 'changes "' + exts[i] + '" extension
type from ' +
-          this.types[exts] + ' to ' + type);
-      }
-
-      this.types[exts[i]] = type;
-    }
-
-    // Default extension is the first one we encounter
-    if (!this.extensions[type]) {
-      this.extensions[type] = exts[0];
-    }
-  }
-};
-
-/**
- * Load an Apache2-style ".types" file
- *
- * This may be called multiple times (it's expected).  Where files declare
- * overlapping types/extensions, the last file wins.
- *
- * @param file (String) path of file to load.
- */
-Mime.prototype.load = function(file) {
-
-  this._loading = file;
-  // Read file and split into lines
-  var map = {},
-      content = fs.readFileSync(file, 'ascii'),
-      lines = content.split(/[\r\n]+/);
-
-  lines.forEach(function(line) {
-    // Clean up whitespace/comments, and split into fields
-    var fields = line.replace(/\s*#.*|^\s*|\s*$/g, '').split(/\s+/);
-    map[fields.shift()] = fields;
-  });
-
-  this.define(map);
-
-  this._loading = null;
-};
-
-/**
- * Lookup a mime type based on extension
- */
-Mime.prototype.lookup = function(path, fallback) {
-  var ext = path.replace(/.*[\.\/\\]/, '').toLowerCase();
-
-  return this.types[ext] || fallback || this.default_type;
-};
-
-/**
- * Return file extension associated with a mime type
- */
-Mime.prototype.extension = function(mimeType) {
-  var type = mimeType.match(/^\s*([^;\s]*)(?:;|\s|$)/)[1].toLowerCase();
-  return this.extensions[type];
-};
-
-// Default instance
-var mime = new Mime();
-
-// Load local copy of
-// http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
-mime.load(path.join(__dirname, 'types/mime.types'));
-
-// Load additional types from node.js community
-mime.load(path.join(__dirname, 'types/node.types'));
-
-// Default type
-mime.default_type = mime.lookup('bin');
-
-//
-// Additional API specific to the default instance
-//
-
-mime.Mime = Mime;
-
-/**
- * Lookup a charset based on mime type.
- */
-mime.charsets = {
-  lookup: function(mimeType, fallback) {
-    // Assume text types are utf8
-    return (/^text\//).test(mimeType) ? 'UTF-8' : fallback;
-  }
-};
-
-module.exports = mime;

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/0044fe33/node_modules/mime/package.json
----------------------------------------------------------------------
diff --git a/node_modules/mime/package.json b/node_modules/mime/package.json
deleted file mode 100644
index 2bcd450..0000000
--- a/node_modules/mime/package.json
+++ /dev/null
@@ -1,38 +0,0 @@
-{
-  "author": {
-    "name": "Robert Kieffer",
-    "email": "robert@broofa.com",
-    "url": "http://github.com/broofa"
-  },
-  "contributors": [
-    {
-      "name": "Benjamin Thomas",
-      "email": "benjamin@benjaminthomas.org",
-      "url": "http://github.com/bentomas"
-    }
-  ],
-  "dependencies": {},
-  "description": "A comprehensive library for mime-type mapping",
-  "devDependencies": {},
-  "keywords": [
-    "util",
-    "mime"
-  ],
-  "main": "mime.js",
-  "name": "mime",
-  "repository": {
-    "url": "https://github.com/broofa/node-mime",
-    "type": "git"
-  },
-  "version": "1.2.11",
-  "readme": "# mime\n\nComprehensive MIME type mapping API. Includes all 600+ types and 800+
extensions defined by the Apache project, plus additional types submitted by the node.js community.\n\n##
Install\n\nInstall with [npm](http://github.com/isaacs/npm):\n\n    npm install mime\n\n##
API - Queries\n\n### mime.lookup(path)\nGet the mime type associated with a file, if no mime
type is found `application/octet-stream` is returned. Performs a case-insensitive lookup using
the extension in `path` (the substring after the last '/' or '.').  E.g.\n\n    var mime =
require('mime');\n\n    mime.lookup('/path/to/file.txt');         // => 'text/plain'\n
   mime.lookup('file.txt');                  // => 'text/plain'\n    mime.lookup('.TXT');
                     // => 'text/plain'\n    mime.lookup('htm');                      
// => 'text/html'\n\n### mime.default_type\nSets the mime type returned when `mime.lookup`
fails to find the extension searched for. (Default is `application/octet-
 stream`.)\n\n### mime.extension(type)\nGet the default extension for `type`\n\n    mime.extension('text/html');
                // => 'html'\n    mime.extension('application/octet-stream');  // =>
'bin'\n\n### mime.charsets.lookup()\n\nMap mime-type to charset\n\n    mime.charsets.lookup('text/plain');
       // => 'UTF-8'\n\n(The logic for charset lookups is pretty rudimentary.  Feel free
to suggest improvements.)\n\n## API - Defining Custom Types\n\nThe following APIs allow you
to add your own type mappings within your project.  If you feel a type should be included
as part of node-mime, see [requesting new types](https://github.com/broofa/node-mime/wiki/Requesting-New-Types).\n\n###
mime.define()\n\nAdd custom mime/extension mappings\n\n    mime.define({\n        'text/x-some-format':
['x-sf', 'x-sft', 'x-sfml'],\n        'application/x-my-type': ['x-mt', 'x-mtt'],\n      
 // etc ...\n    });\n\n    mime.lookup('x-sft');                 // => 'text/x-some-format'\n\nThe
first en
 try in the extensions array is returned by `mime.extension()`. E.g.\n\n    mime.extension('text/x-some-format');
// => 'x-sf'\n\n### mime.load(filepath)\n\nLoad mappings from an Apache \".types\" format
file\n\n    mime.load('./my_project.types');\n\nThe .types file format is simple -  See the
`types` dir for examples.\n",
-  "readmeFilename": "README.md",
-  "bugs": {
-    "url": "https://github.com/broofa/node-mime/issues"
-  },
-  "homepage": "https://github.com/broofa/node-mime",
-  "_id": "mime@1.2.11",
-  "_shasum": "58203eed86e3a5ef17aed2b7d9ebd47f0a60dd10",
-  "_resolved": "https://registry.npmjs.org/mime/-/mime-1.2.11.tgz",
-  "_from": "mime@1.2.11"
-}

http://git-wip-us.apache.org/repos/asf/cordova-browser/blob/0044fe33/node_modules/mime/test.js
----------------------------------------------------------------------
diff --git a/node_modules/mime/test.js b/node_modules/mime/test.js
deleted file mode 100644
index 2cda1c7..0000000
--- a/node_modules/mime/test.js
+++ /dev/null
@@ -1,84 +0,0 @@
-/**
- * Usage: node test.js
- */
-
-var mime = require('./mime');
-var assert = require('assert');
-var path = require('path');
-
-function eq(a, b) {
-  console.log('Test: ' + a + ' === ' + b);
-  assert.strictEqual.apply(null, arguments);
-}
-
-console.log(Object.keys(mime.extensions).length + ' types');
-console.log(Object.keys(mime.types).length + ' extensions\n');
-
-//
-// Test mime lookups
-//
-
-eq('text/plain', mime.lookup('text.txt'));     // normal file
-eq('text/plain', mime.lookup('TEXT.TXT'));     // uppercase
-eq('text/plain', mime.lookup('dir/text.txt')); // dir + file
-eq('text/plain', mime.lookup('.text.txt'));    // hidden file
-eq('text/plain', mime.lookup('.txt'));         // nameless
-eq('text/plain', mime.lookup('txt'));          // extension-only
-eq('text/plain', mime.lookup('/txt'));         // extension-less ()
-eq('text/plain', mime.lookup('\\txt'));        // Windows, extension-less
-eq('application/octet-stream', mime.lookup('text.nope')); // unrecognized
-eq('fallback', mime.lookup('text.fallback', 'fallback')); // alternate default
-
-//
-// Test extensions
-//
-
-eq('txt', mime.extension(mime.types.text));
-eq('html', mime.extension(mime.types.htm));
-eq('bin', mime.extension('application/octet-stream'));
-eq('bin', mime.extension('application/octet-stream '));
-eq('html', mime.extension(' text/html; charset=UTF-8'));
-eq('html', mime.extension('text/html; charset=UTF-8 '));
-eq('html', mime.extension('text/html; charset=UTF-8'));
-eq('html', mime.extension('text/html ; charset=UTF-8'));
-eq('html', mime.extension('text/html;charset=UTF-8'));
-eq('html', mime.extension('text/Html;charset=UTF-8'));
-eq(undefined, mime.extension('unrecognized'));
-
-//
-// Test node.types lookups
-//
-
-eq('application/font-woff', mime.lookup('file.woff'));
-eq('application/octet-stream', mime.lookup('file.buffer'));
-eq('audio/mp4', mime.lookup('file.m4a'));
-eq('font/opentype', mime.lookup('file.otf'));
-
-//
-// Test charsets
-//
-
-eq('UTF-8', mime.charsets.lookup('text/plain'));
-eq(undefined, mime.charsets.lookup(mime.types.js));
-eq('fallback', mime.charsets.lookup('application/octet-stream', 'fallback'));
-
-//
-// Test for overlaps between mime.types and node.types
-//
-
-var apacheTypes = new mime.Mime(), nodeTypes = new mime.Mime();
-apacheTypes.load(path.join(__dirname, 'types/mime.types'));
-nodeTypes.load(path.join(__dirname, 'types/node.types'));
-
-var keys = [].concat(Object.keys(apacheTypes.types))
-             .concat(Object.keys(nodeTypes.types));
-keys.sort();
-for (var i = 1; i < keys.length; i++) {
-  if (keys[i] == keys[i-1]) {
-    console.warn('Warning: ' +
-      'node.types defines ' + keys[i] + '->' + nodeTypes.types[keys[i]] +
-      ', mime.types defines ' + keys[i] + '->' + apacheTypes.types[keys[i]]);
-  }
-}
-
-console.log('\nOK');


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


Mime
View raw message