You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2017/08/12 08:01:52 UTC
[01/12] cordova-serve git commit: re-arrange code in src/, use Promise,
default target gets open'd [Forced Update!]
Repository: cordova-serve
Updated Branches:
refs/heads/master 1119b5eb9 -> 338a86baf (forced update)
re-arrange code in src/, use Promise, default target gets open'd
Project: http://git-wip-us.apache.org/repos/asf/cordova-serve/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-serve/commit/ef88237f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-serve/tree/ef88237f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-serve/diff/ef88237f
Branch: refs/heads/master
Commit: ef88237fda44dffd25ba9ae2953253b6af038553
Parents: 0c2fbd9
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Thu Jun 29 10:44:35 2017 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Thu Jun 29 10:44:35 2017 -0700
----------------------------------------------------------------------
package.json | 3 +-
serve.js | 57 -------------------------------
src/browser.js | 97 +++++++++++++++++++++++++++++------------------------
src/exec.js | 37 ++++++++++----------
src/main.js | 57 +++++++++++++++++++++++++++++++
5 files changed, 132 insertions(+), 119 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/ef88237f/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 26671d1..464fe36 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "cordova-serve",
"version": "1.0.2-dev",
"description": "Apache Cordova server support for cordova-lib and cordova-browser.",
- "main": "serve.js",
+ "main": "src/main.js",
"repository": {
"type": "git",
"url": "https://github.com/apache/cordova-lib"
@@ -22,6 +22,7 @@
"chalk": "^1.1.1",
"compression": "^1.6.0",
"express": "^4.13.3",
+ "open": "0.0.5",
"q": "^1.4.1",
"shelljs": "^0.5.3"
},
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/ef88237f/serve.js
----------------------------------------------------------------------
diff --git a/serve.js b/serve.js
deleted file mode 100644
index 10d000a..0000000
--- a/serve.js
+++ /dev/null
@@ -1,57 +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'),
- 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-serve/blob/ef88237f/src/browser.js
----------------------------------------------------------------------
diff --git a/src/browser.js b/src/browser.js
index 2b08afb..b27ab8b 100644
--- a/src/browser.js
+++ b/src/browser.js
@@ -18,9 +18,10 @@
*/
var child_process = require('child_process'),
- exec = require('./exec'),
fs = require('fs'),
- Q = require('q');
+ Q = require('q'),
+ open = require('open'),
+ exec = require('./exec');
var NOT_INSTALLED = 'The browser target is not installed: %target%';
var NOT_SUPPORTED = 'The browser target is not supported: %target%';
@@ -35,54 +36,64 @@ var NOT_SUPPORTED = 'The browser target is not supported: %target%';
* @return {Q} Promise to launch the specified browser
*/
module.exports = function (opts) {
+
var target = opts.target || 'chrome';
var url = opts.url || '';
target = target.toLowerCase();
- return getBrowser(target, opts.dataDir).then(function (browser) {
- var args;
-
- var urlAdded = false;
- 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
-
- if (target === 'edge') {
- browser += ':' + url;
- urlAdded = true;
+ if(target === 'default') {
+ return open(url);
+ }
+ else {
+
+ return getBrowser(target, opts.dataDir).then(function (browser) {
+ var args;
+
+ var urlAdded = false;
+
+
+ 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
+
+ if (target === 'edge') {
+ browser += ':' + url;
+ urlAdded = true;
+ }
+
+ 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 = ['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;
- }
+ if (!urlAdded) {
+ args.push(url);
+ }
+ var command = args.join(' ');
- if (!urlAdded) {
- args.push(url);
- }
- var command = args.join(' ');
- return exec(command).catch(function (error) {
- // Assume any error means that the browser is not installed and display that as a more friendly error.
- throw new Error(NOT_INSTALLED.replace('%target%', target));
- });
- });
+ return exec(command).catch(function (error) {
+ // Assume any error means that the browser is not installed and display that as a more friendly error.
+ throw new Error(NOT_INSTALLED.replace('%target%', target));
+ });
+ });
+ }
};
function getBrowser(target, dataDir) {
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/ef88237f/src/exec.js
----------------------------------------------------------------------
diff --git a/src/exec.js b/src/exec.js
index d1c02a4..d3f2e44 100644
--- a/src/exec.js
+++ b/src/exec.js
@@ -17,30 +17,31 @@
under the License.
*/
-var child_process = require('child_process'),
- Q = require('q');
+var child_process = require('child_process');
/**
* 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.
+ * @return {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;
+ return new Promise(function(resolve,reject){
+ try {
+ var opt = {cwd: opt_cwd, maxBuffer: 1024000};
+ child_process.exec(cmd,opt,function (err, stdout, stderr) {
+ if (err) {
+ reject(new Error('Error executing "' + cmd + '": ' + stderr));
+ }
+ else {
+ resolve(stdout);
+ }
+ });
+ }
+ catch (e) {
+ console.error('error caught: ' + e);
+ reject(e);
+ }
+ });
};
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/ef88237f/src/main.js
----------------------------------------------------------------------
diff --git a/src/main.js b/src/main.js
new file mode 100644
index 0000000..01c5add
--- /dev/null
+++ b/src/main.js
@@ -0,0 +1,57 @@
+/**
+ 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'),
+ compression = require('compression'),
+ express = require('express');
+
+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 + ')');
+ }
+ require('./server').log(msg);
+ });
+ next();
+ });
+
+ // Turn on compression
+ this.app.use(compression());
+
+ this.servePlatform = require('./platform');
+ this.launchServer = require('./server');
+ this.launchBrowser = require('./browser');
+}
+
+// module.exports.launchBrowser = require('./browser');
+
+// Expose some useful express statics
+module.exports.Router = express.Router;
+module.exports.static = express.static;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[06/12] cordova-serve git commit: Convert src/browser to use Promise
api
Posted by pu...@apache.org.
Convert src/browser to use Promise api
Project: http://git-wip-us.apache.org/repos/asf/cordova-serve/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-serve/commit/6d8eadc6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-serve/tree/6d8eadc6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-serve/diff/6d8eadc6
Branch: refs/heads/master
Commit: 6d8eadc6439a6460f1bd81691c0ee802be25debd
Parents: 20737ed
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Thu Jun 29 15:04:13 2017 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Thu Jun 29 15:05:24 2017 -0700
----------------------------------------------------------------------
src/browser.js | 226 +++++++++++++++++++++++++++++-----------------------
1 file changed, 126 insertions(+), 100 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/6d8eadc6/src/browser.js
----------------------------------------------------------------------
diff --git a/src/browser.js b/src/browser.js
index b27ab8b..cf4c92b 100644
--- a/src/browser.js
+++ b/src/browser.js
@@ -17,9 +17,10 @@
under the License.
*/
+/* globals Promise: true */
+
var child_process = require('child_process'),
fs = require('fs'),
- Q = require('q'),
open = require('open'),
exec = require('./exec');
@@ -33,7 +34,7 @@ var NOT_SUPPORTED = 'The browser target is not supported: %target%';
* 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
+ * @return {Promise} Promise to launch the specified browser
*/
module.exports = function (opts) {
@@ -42,57 +43,55 @@ module.exports = function (opts) {
target = target.toLowerCase();
if(target === 'default') {
- return open(url);
+ open(url);
+ return Promise.resolve();
}
else {
-
return getBrowser(target, opts.dataDir).then(function (browser) {
var args;
-
var urlAdded = false;
+ 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
+
+ if (target === 'edge') {
+ browser += ':' + url;
+ urlAdded = true;
+ }
- 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
-
- if (target === 'edge') {
- browser += ':' + url;
- urlAdded = true;
- }
-
- 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 = ['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;
+ }
- if (!urlAdded) {
- args.push(url);
- }
- var command = args.join(' ');
+ if (!urlAdded) {
+ args.push(url);
+ }
+ var command = args.join(' ');
- return exec(command).catch(function (error) {
- // Assume any error means that the browser is not installed and display that as a more friendly error.
- throw new Error(NOT_INSTALLED.replace('%target%', target));
- });
+ return exec(command).catch(function (error) {
+ // Assume any error means that the browser is not installed and display that as a more friendly error.
+ throw new Error(NOT_INSTALLED.replace('%target%', target));
});
+ });
}
};
@@ -122,83 +121,110 @@ function getBrowser(target, dataDir) {
'opera': 'opera'
}
};
+
if (target in browsers[process.platform]) {
var browser = browsers[process.platform][target];
- if (process.platform === 'win32') {
- // Windows displays a dialog if the browser is not installed. We'd prefer to avoid that.
- return checkBrowserExistsWindows(browser, target).then(function () {
- return browser;
- });
- } else {
- return Q(browser);
- }
+ return checkBrowserExistsWindows(browser, target).then(function () {
+ return Promise.resolve(browser);
+ });
}
- return Q.reject(NOT_SUPPORTED.replace('%target%', target));
+ else {
+ return Promise.reject(NOT_SUPPORTED.replace('%target%', target));
+ }
+
}
function checkBrowserExistsWindows(browser, target) {
- var promise = target === 'edge' ? edgeSupported() : browserInstalled(browser);
- return promise.catch(function (error) {
- return Q.reject((error && error.toString() || NOT_INSTALLED).replace('%target%', target));
+ var promise = new Promise(function (resolve, reject){
+ // Windows displays a dialog if the browser is not installed. We'd prefer to avoid that.
+ if (process.platform === 'win32') {
+ if(target === 'edge') {
+ edgeSupported().then(function () {
+ resolve();
+ })
+ .catch(function(err){
+ reject((err && err.toString() || NOT_INSTALLED).replace('%target%', target));
+ });
+ }
+ else {
+ browserInstalled(browser).then(function() {
+ resolve();
+ })
+ .catch(function(err) {
+ reject((err && err.toString() || NOT_INSTALLED).replace('%target%', target));
+ });
+ }
+ }
+ else {
+ resolve();
+ }
+
});
+ return promise;
}
function edgeSupported() {
- var d = Q.defer();
-
- child_process.exec('ver', function (err, stdout, stderr) {
- if (err || stderr) {
- d.reject(err || stderr);
- } else {
- var windowsVersion = stdout.match(/([0-9.])+/g)[0];
- if (parseInt(windowsVersion) < 10) {
- d.reject('The browser target is not supported on this version of Windows: %target%');
+ var prom = new Promise(function(resolve,reject){
+ child_process.exec('ver', function (err, stdout, stderr) {
+ if (err || stderr) {
+ reject(err || stderr);
} else {
- d.resolve();
+ var windowsVersion = stdout.match(/([0-9.])+/g)[0];
+ if (parseInt(windowsVersion) < 10) {
+ reject('The browser target is not supported on this version of Windows: %target%');
+ } else {
+ resolve();
+ }
}
- }
+ });
});
- return d.promise;
+ return prom;
}
var regItemPattern = /\s*\(Default\)\s+(REG_SZ)\s+([^\s].*)\s*/;
function browserInstalled(browser) {
- // On Windows, the 'start' command searches the path then 'App Paths' in the registry. We do the same here. Note
- // that the start command uses the PATHEXT environment variable for the list of extensions to use if no extension is
- // provided. We simplify that to just '.EXE' since that is what all the supported browsers use.
-
- // Check path (simple but usually won't get a hit)
- if (require('shelljs').which(browser)) {
- return Q.resolve();
- }
-
- var d = Q.defer();
-
- child_process.exec('reg QUERY "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\' + browser.split(' ')[0] + '.EXE" /v ""', function (err, stdout, stderr) {
- if (err || stderr) {
- // The registry key does not exist, which just means the app is not installed.
- d.reject();
- } else {
- var result = regItemPattern.exec(stdout);
- if (!result) {
- // The registry key exists, but has no default value, which means the app is not installed (note that we
- // don't expect to hit this, since we'll just get a default value of '(value not set)', but that will
- // fail the fs.exists() test below to give us the expected result).
- d.reject();
- } else {
- fs.exists(trimRegPath(result[2]), function (exists) {
- if (exists) {
- d.resolve();
- } else {
- // The default value is not a file that exists, which means the app is not installed.
- d.reject();
+ // On Windows, the 'start' command searches the path then 'App Paths' in the registry.
+ // We do the same here. Note that the start command uses the PATHEXT environment variable
+ // for the list of extensions to use if no extension is provided. We simplify that to just '.EXE'
+ // since that is what all the supported browsers use. Check path (simple but usually won't get a hit)
+
+ var promise = new Promise(function(resolve,reject) {
+ if (require('shelljs').which(browser)) {
+ return resolve();
+ }
+ else {
+ var regQPre = 'reg QUERY "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\';
+ var regQPost = '.EXE" /v ""';
+ var regQuery = regQPre + browser.split(' ')[0] + regQPost;
+
+ child_process.exec(regQuery , function (err, stdout, stderr) {
+ if (err) {
+ // The registry key does not exist, which just means the app is not installed.
+ reject();
+ }
+ else {
+ var result = regItemPattern.exec(stdout);
+ if (!result) {
+ // The registry key exists, but has no default value, which means the app is not
+ // installed (note that we don't expect to hit this, since we'll just get a default
+ // value of '(value not set)', but that will fail the fs.existsSync() test below
+ // to give us the expected result).
+ reject();
}
- });
- }
+ else {
+ if(fs.existsSync(trimRegPath(result[2]))) {
+ resolve();
+ }
+ else {
+ // The default value is not a file that exists, which means the app is not installed.
+ reject();
+ }
+ }
+ }
+ });
}
});
-
- return d.promise;
+ return promise;
}
function trimRegPath(path) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[05/12] cordova-serve git commit: allow global Promise
Posted by pu...@apache.org.
allow global Promise
Project: http://git-wip-us.apache.org/repos/asf/cordova-serve/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-serve/commit/20737ed4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-serve/tree/20737ed4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-serve/diff/20737ed4
Branch: refs/heads/master
Commit: 20737ed49b6c70a754a3ed5fc1aaf630afa3e82c
Parents: fd32d32
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Thu Jun 29 14:06:35 2017 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Thu Jun 29 14:12:27 2017 -0700
----------------------------------------------------------------------
src/exec.js | 7 +++++++
1 file changed, 7 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/20737ed4/src/exec.js
----------------------------------------------------------------------
diff --git a/src/exec.js b/src/exec.js
index 2ab268d..9f3a625 100644
--- a/src/exec.js
+++ b/src/exec.js
@@ -31,7 +31,14 @@ module.exports = function (cmd, opt_cwd) {
return new Promise(function(resolve,reject){
try {
var opt = {cwd: opt_cwd, maxBuffer: 1024000};
+ var timerID = 0;
+ if(process.platform === 'linux') {
+ timerID = setTimeout(function(){
+ resolve('linux-timeout');
+ },5000);
+ }
child_process.exec(cmd,opt,function (err, stdout, stderr) {
+ clearTimeout(timerID);
if (err) {
reject(new Error('Error executing "' + cmd + '": ' + stderr));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[10/12] cordova-serve git commit: cleanup quotes and semicolons
Posted by pu...@apache.org.
cleanup quotes and semicolons
Project: http://git-wip-us.apache.org/repos/asf/cordova-serve/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-serve/commit/5bd008b3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-serve/tree/5bd008b3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-serve/diff/5bd008b3
Branch: refs/heads/master
Commit: 5bd008b37eb9e5dabf6343c5422e2b9c71bbd79a
Parents: db1ae55
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri Jun 30 18:02:54 2017 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Fri Jun 30 18:02:54 2017 -0700
----------------------------------------------------------------------
spec/server.spec.js | 4 ++--
src/platform.js | 2 ++
src/server.js | 5 +++--
3 files changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/5bd008b3/spec/server.spec.js
----------------------------------------------------------------------
diff --git a/spec/server.spec.js b/spec/server.spec.js
index fb35c1f..f1b056a 100644
--- a/spec/server.spec.js
+++ b/spec/server.spec.js
@@ -36,11 +36,11 @@ describe('server', function() {
expect(result).toBeDefined();
expectPromise(result);
result.then(function(res) {
- console.log("success : " + res);
+ // console.log("success : " + res);
done();
});
result.catch(function(err){
- console.log("error : " + err);
+ // console.log("error : " + err);
done();
});
});
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/5bd008b3/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 27f72b4..26f9c4b 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -17,6 +17,8 @@
under the License.
*/
+/* globals Promise: true */
+
var fs = require('fs'),
util = require('./util');
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/5bd008b3/src/server.js
----------------------------------------------------------------------
diff --git a/src/server.js b/src/server.js
index 03bf5fe..f423f2e 100644
--- a/src/server.js
+++ b/src/server.js
@@ -17,6 +17,8 @@
under the License.
*/
+/* globals Promise: true */
+
var chalk = require('chalk'),
express = require('express');
@@ -60,12 +62,11 @@ module.exports = function (opts) {
// If we have a project root, make that available as a static root also. This can be useful in cases where source
// files that have been transpiled (such as TypeScript) are located under the project root on a path that mirrors
// the the transpiled file's path under the platform root and is pointed to by a map file.
- console.log("pr " + that.projectRoot)
if (that.projectRoot) {
app.use(express.static(that.projectRoot));
}
- var listener = server.listen(port)
+ var listener = server.listen(port);
listener.on('listening', function () {
that.port = port;
var message = 'Static file server running on: ' + chalk.green('http://localhost:' + port) + ' (CTRL + C to shut down)';
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[02/12] cordova-serve git commit: Add License, Contributing, Notice,
pr-template, ...
Posted by pu...@apache.org.
Add License, Contributing, Notice, pr-template, ...
Project: http://git-wip-us.apache.org/repos/asf/cordova-serve/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-serve/commit/4608607b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-serve/tree/4608607b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-serve/diff/4608607b
Branch: refs/heads/master
Commit: 4608607b12a44c8410ad41c6f5be5bf25a48fc08
Parents: ef88237
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Thu Jun 29 11:07:52 2017 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Thu Jun 29 11:07:52 2017 -0700
----------------------------------------------------------------------
.github/PULL_REQUEST_TEMPLATE.md | 20 ++++
.jscs.json | 24 ++++
CONTRIBUTION.md | 37 +++++++
LICENSE | 202 ++++++++++++++++++++++++++++++++++
NOTICE | 5 +
5 files changed, 288 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/4608607b/.github/PULL_REQUEST_TEMPLATE.md
----------------------------------------------------------------------
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 0000000..4364ffb
--- /dev/null
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,20 @@
+<!--
+Please make sure the checklist boxes are all checked before submitting the PR. The checklist
+is intended as a quick reference, for complete details please see our Contributor Guidelines:
+http://cordova.apache.org/contribute/contribute_guidelines.html
+Thanks!
+-->
+
+### Platforms affected
+
+
+### What does this PR do?
+
+
+### What testing has been done on this change?
+
+
+### Checklist
+- [ ] [Reported an issue](http://cordova.apache.org/contribute/issues.html) in the JIRA database
+- [ ] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
+- [ ] Added automated test coverage as appropriate for this change.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/4608607b/.jscs.json
----------------------------------------------------------------------
diff --git a/.jscs.json b/.jscs.json
new file mode 100644
index 0000000..64b1d67
--- /dev/null
+++ b/.jscs.json
@@ -0,0 +1,24 @@
+{
+ "disallowMixedSpacesAndTabs": true,
+ "disallowTrailingWhitespace": true,
+ "validateLineBreaks": "LF",
+ "validateIndentation": 4,
+ "requireLineFeedAtFileEnd": true,
+
+ "disallowSpaceAfterPrefixUnaryOperators": true,
+ "disallowSpaceBeforePostfixUnaryOperators": true,
+ "requireSpaceAfterLineComment": true,
+ "requireCapitalizedConstructors": true,
+
+ "disallowSpacesInNamedFunctionExpression": {
+ "beforeOpeningRoundBrace": true
+ },
+
+ "requireSpaceAfterKeywords": [
+ "if",
+ "else",
+ "for",
+ "while",
+ "do"
+ ]
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/4608607b/CONTRIBUTION.md
----------------------------------------------------------------------
diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md
new file mode 100644
index 0000000..51584be
--- /dev/null
+++ b/CONTRIBUTION.md
@@ -0,0 +1,37 @@
+<!--
+#
+# 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.
+#
+-->
+
+# Contributing to Apache Cordova
+
+Anyone can contribute to Cordova. And we need your contributions.
+
+There are multiple ways to contribute: report bugs, improve the docs, and
+contribute code.
+
+For instructions on this, start with the
+[contribution overview](http://cordova.apache.org/contribute/).
+
+The details are explained there, but the important items are:
+ - Sign and submit an Apache ICLA (Contributor License Agreement).
+ - Have a Jira issue open that corresponds to your contribution.
+ - Run the tests so your patch doesn't break existing functionality.
+
+We look forward to your contributions!
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/4608607b/LICENSE
----------------------------------------------------------------------
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..7a4a3ea
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/4608607b/NOTICE
----------------------------------------------------------------------
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..6ad25ec
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,5 @@
+Apache Cordova
+Copyright 2017 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[09/12] cordova-serve git commit: remove 'q' dependence completely.
Added server.spec
Posted by pu...@apache.org.
remove 'q' dependence completely. Added server.spec
Project: http://git-wip-us.apache.org/repos/asf/cordova-serve/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-serve/commit/db1ae551
Tree: http://git-wip-us.apache.org/repos/asf/cordova-serve/tree/db1ae551
Diff: http://git-wip-us.apache.org/repos/asf/cordova-serve/diff/db1ae551
Branch: refs/heads/master
Commit: db1ae5518dbf0938da1035dc386102946b821add
Parents: 2be7e2b
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri Jun 30 17:56:59 2017 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Fri Jun 30 17:56:59 2017 -0700
----------------------------------------------------------------------
package.json | 1 -
spec/server.spec.js | 47 ++++++++++++++++++++++++
src/platform.js | 28 ++++++++------
src/server.js | 96 +++++++++++++++++++++++++-----------------------
4 files changed, 115 insertions(+), 57 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/db1ae551/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 4d20d9d..7df53cd 100644
--- a/package.json
+++ b/package.json
@@ -28,7 +28,6 @@
"compression": "^1.6.0",
"express": "^4.13.3",
"open": "0.0.5",
- "q": "^1.4.1",
"shelljs": "^0.5.3"
},
"devDependencies": {
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/db1ae551/spec/server.spec.js
----------------------------------------------------------------------
diff --git a/spec/server.spec.js b/spec/server.spec.js
new file mode 100644
index 0000000..fb35c1f
--- /dev/null
+++ b/spec/server.spec.js
@@ -0,0 +1,47 @@
+/**
+ 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("../src/server");
+
+function expectPromise(obj){
+ // 3 slightly different ways of verifying a promise
+ expect(typeof obj.then).toBe('function');
+ expect(obj instanceof Promise).toBe(true);
+ expect(obj).toBe(Promise.resolve(obj));
+}
+
+describe('server', function() {
+
+ it('exists and has expected properties', function() {
+ expect(server).toBeDefined();
+ expect(typeof server).toBe('function');
+ });
+
+ it('should return a promise', function(done) {
+ var result = server({port:8008,noServerInfo:1});
+ expect(result).toBeDefined();
+ expectPromise(result);
+ result.then(function(res) {
+ console.log("success : " + res);
+ done();
+ });
+ result.catch(function(err){
+ console.log("error : " + err);
+ done();
+ });
+ });
+});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/db1ae551/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 7abbb81..27f72b4 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -18,7 +18,6 @@
*/
var fs = require('fs'),
- Q = require('q'),
util = require('./util');
/**
@@ -30,23 +29,30 @@ var fs = require('fs'),
* @returns {*|promise}
*/
module.exports = function (platform, opts) {
+
+ // note: `this` is actually an instance of main.js CordovaServe
+ // this module is a mixin
var that = this;
- return Q().then(function () {
+ var retPromise = new Promise(function(resolve,reject){
if (!platform) {
- throw new Error('A platform must be specified');
+ reject('Error: A platform must be specified');
}
+ else {
+ opts = opts || {};
+ var projectRoot = findProjectRoot(opts.root);
+ that.projectRoot = projectRoot;
+ opts.root = util.getPlatformWwwRoot(projectRoot, platform);
- opts = opts || {};
- var projectRoot = findProjectRoot(opts.root);
- 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);
+ if (!fs.existsSync(opts.root)) {
+ reject('Error: Project does not include the specified platform: ' + platform);
+ }
+ else {
+ return that.launchServer(opts);
+ }
}
- return that.launchServer(opts);
});
+ return retPromise;
};
function findProjectRoot(path) {
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/db1ae551/src/server.js
----------------------------------------------------------------------
diff --git a/src/server.js b/src/server.js
index 9040d2b..03bf5fe 100644
--- a/src/server.js
+++ b/src/server.js
@@ -18,8 +18,7 @@
*/
var chalk = require('chalk'),
- express = require('express'),
- Q = require('q');
+ express = require('express');
/**
* @desc Launches a server with the specified options and optional custom handlers.
@@ -27,56 +26,63 @@ var chalk = require('chalk'),
* @returns {*|promise}
*/
module.exports = function (opts) {
- var deferred = Q.defer();
- opts = opts || {};
- var port = opts.port || 8000;
+ var that = this;
+ var promise = new Promise(function(resolve,reject){
- var log = module.exports.log = function (msg) {
- if (!opts.noLogOutput) {
- if (opts.events) {
- opts.events.emit('log', msg);
- } else {
- console.log(msg);
- }
- }
- };
-
- var app = this.app;
- var server = require('http').Server(app);
- this.server = server;
+ opts = opts || {};
+ var port = opts.port || 8000;
- if (opts.router) {
- app.use(opts.router);
- }
+ var log = module.exports.log = function (msg) {
+ if (!opts.noLogOutput) {
+ if (opts.events) {
+ opts.events.emit('log', msg);
+ }
+ else {
+ console.log(msg);
+ }
+ }
+ };
- if (opts.root) {
- this.root = opts.root;
- app.use(express.static(opts.root));
- }
+ var app = that.app;
+ var server = require('http').Server(app);
+ that.server = server;
- // If we have a project root, make that available as a static root also. This can be useful in cases where source
- // files that have been transpiled (such as TypeScript) are located under the project root on a path that mirrors
- // the the transpiled file's path under the platform root and is pointed to by a map file.
- if (this.projectRoot) {
- app.use(express.static(this.projectRoot));
- }
+ if (opts.router) {
+ app.use(opts.router);
+ }
- 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)');
+ if (opts.root) {
+ that.root = opts.root;
+ app.use(express.static(opts.root));
}
- deferred.resolve();
- }).on('error', function (e) {
- if (e && e.toString().indexOf('EADDRINUSE') !== -1) {
- port++;
- server.listen(port);
- } else {
- deferred.reject(e);
+
+ // If we have a project root, make that available as a static root also. This can be useful in cases where source
+ // files that have been transpiled (such as TypeScript) are located under the project root on a path that mirrors
+ // the the transpiled file's path under the platform root and is pointed to by a map file.
+ console.log("pr " + that.projectRoot)
+ if (that.projectRoot) {
+ app.use(express.static(that.projectRoot));
}
- });
- return deferred.promise;
+ var listener = server.listen(port)
+ listener.on('listening', function () {
+ that.port = port;
+ var message = 'Static file server running on: ' + chalk.green('http://localhost:' + port) + ' (CTRL + C to shut down)';
+ if (!opts.noServerInfo) {
+ log(message);
+ }
+ resolve(message);
+ });
+ listener.on('error', function (e) {
+ if (e && e.toString().indexOf('EADDRINUSE') > -1) {
+ port++;
+ server.listen(port);
+ }
+ else {
+ reject(e);
+ }
+ });
+ });
+ return promise;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[07/12] cordova-serve git commit: added browser tests,
new dep on rewire because of the way open() works
Posted by pu...@apache.org.
added browser tests, new dep on rewire because of the way open() works
Project: http://git-wip-us.apache.org/repos/asf/cordova-serve/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-serve/commit/f5ef63d3
Tree: http://git-wip-us.apache.org/repos/asf/cordova-serve/tree/f5ef63d3
Diff: http://git-wip-us.apache.org/repos/asf/cordova-serve/diff/f5ef63d3
Branch: refs/heads/master
Commit: f5ef63d332f78cae4b8fde5855c279a6c479e2e1
Parents: 6d8eadc
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Thu Jun 29 17:51:33 2017 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Thu Jun 29 18:03:25 2017 -0700
----------------------------------------------------------------------
package.json | 3 +-
spec/browser.spec.js | 71 +++++++++++++++++++++++++++++++++++++++++++++++
src/browser.js | 1 +
3 files changed, 74 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/f5ef63d3/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index ea460a7..4d20d9d 100644
--- a/package.json
+++ b/package.json
@@ -33,7 +33,8 @@
},
"devDependencies": {
"jasmine": "^2.5.2",
- "jshint": "^2.8.0"
+ "jshint": "^2.8.0",
+ "rewire": "^2.5.2"
},
"engines": {
"node": ">=4.0.0",
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/f5ef63d3/spec/browser.spec.js
----------------------------------------------------------------------
diff --git a/spec/browser.spec.js b/spec/browser.spec.js
new file mode 100644
index 0000000..aaa0fce
--- /dev/null
+++ b/spec/browser.spec.js
@@ -0,0 +1,71 @@
+/**
+ 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');
+var rewire = require('rewire');
+
+var browser = rewire("../src/browser");
+
+function expectPromise(obj){
+ // 3 slightly different ways of verifying a promise
+ expect(typeof obj.then).toBe('function');
+ expect(obj instanceof Promise).toBe(true);
+ expect(obj).toBe(Promise.resolve(obj));
+}
+
+describe('browser', function() {
+
+ beforeEach(function(){
+ spyOn(child_process,'exec').and.callFake(function(cmd,options,callback){
+ callback && callback(null,"success",null);
+ });
+ });
+
+ it('exists and has expected properties', function() {
+ expect(browser).toBeDefined();
+ expect(typeof browser).toBe('function');
+ });
+
+ it('should return a promise', function(done) {
+ var result = browser();
+ expect(result).toBeDefined();
+ expectPromise(result);
+ result.then(function(res) {
+ done();
+ });
+ });
+
+ it('should call open() when target is `default`', function(done) {
+
+ var mockOpen = jasmine.createSpy('mockOpen');
+ var origOpen = browser.__get__('open'); // so we can be nice and restore it later
+
+ browser.__set__('open',mockOpen);
+
+ var mockUrl = 'this is the freakin url';
+
+ var result = browser({target:'default',url:mockUrl});
+ expect(result).toBeDefined();
+ expectPromise(result);
+ result.then(function(res) {
+ done();
+ });
+
+ expect(mockOpen).toHaveBeenCalledWith(mockUrl);
+ browser.__set__('open', origOpen);
+
+ });
+});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/f5ef63d3/src/browser.js
----------------------------------------------------------------------
diff --git a/src/browser.js b/src/browser.js
index cf4c92b..aca1127 100644
--- a/src/browser.js
+++ b/src/browser.js
@@ -38,6 +38,7 @@ var NOT_SUPPORTED = 'The browser target is not supported: %target%';
*/
module.exports = function (opts) {
+ opts = opts || {};
var target = opts.target || 'chrome';
var url = opts.url || '';
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[04/12] cordova-serve git commit: allow global Promise
Posted by pu...@apache.org.
allow global Promise
Project: http://git-wip-us.apache.org/repos/asf/cordova-serve/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-serve/commit/fd32d32f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-serve/tree/fd32d32f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-serve/diff/fd32d32f
Branch: refs/heads/master
Commit: fd32d32ff3f23fbd97a5d8180c20f4aafa0c44ce
Parents: 5ab863a
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Thu Jun 29 11:52:51 2017 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Thu Jun 29 11:52:51 2017 -0700
----------------------------------------------------------------------
src/exec.js | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/fd32d32f/src/exec.js
----------------------------------------------------------------------
diff --git a/src/exec.js b/src/exec.js
index d3f2e44..2ab268d 100644
--- a/src/exec.js
+++ b/src/exec.js
@@ -17,6 +17,8 @@
under the License.
*/
+/* globals Promise: true */
+
var child_process = require('child_process');
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[11/12] cordova-serve git commit: Redo change to eslint instead of
jshint
Posted by pu...@apache.org.
Redo change to eslint instead of jshint
Project: http://git-wip-us.apache.org/repos/asf/cordova-serve/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-serve/commit/cef6a945
Tree: http://git-wip-us.apache.org/repos/asf/cordova-serve/tree/cef6a945
Diff: http://git-wip-us.apache.org/repos/asf/cordova-serve/diff/cef6a945
Branch: refs/heads/master
Commit: cef6a94592629f8e49ab428e868e795727c20c00
Parents: 5bd008b
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Sat Aug 12 01:00:46 2017 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Sat Aug 12 01:00:46 2017 -0700
----------------------------------------------------------------------
package.json | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/cef6a945/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 7df53cd..9e7f29d 100644
--- a/package.json
+++ b/package.json
@@ -5,8 +5,8 @@
"main": "src/main.js",
"scripts": {
"jasmine": "jasmine JASMINE_CONFIG_PATH=spec/jasmine.json",
- "jshint": "node node_modules/jshint/bin/jshint src",
- "test": "npm run jshint && npm run jasmine"
+ "eslint": "node node_modules/eslint/bin/eslint ./src",
+ "test": "npm run eslint && npm run jasmine"
},
"repository": {
"type": "git",
@@ -32,7 +32,13 @@
},
"devDependencies": {
"jasmine": "^2.5.2",
- "jshint": "^2.8.0",
+ "eslint": "^4.0.0",
+ "eslint-config-semistandard": "^11.0.0",
+ "eslint-config-standard": "^10.2.1",
+ "eslint-plugin-import": "^2.3.0",
+ "eslint-plugin-node": "^5.0.0",
+ "eslint-plugin-promise": "^3.5.0",
+ "eslint-plugin-standard": "^3.0.1",
"rewire": "^2.5.2"
},
"engines": {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[12/12] cordova-serve git commit: fix linting errors
Posted by pu...@apache.org.
fix linting errors
Project: http://git-wip-us.apache.org/repos/asf/cordova-serve/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-serve/commit/338a86ba
Tree: http://git-wip-us.apache.org/repos/asf/cordova-serve/tree/338a86ba
Diff: http://git-wip-us.apache.org/repos/asf/cordova-serve/diff/338a86ba
Branch: refs/heads/master
Commit: 338a86bafdd42e83081caf03d57c19e4bd800982
Parents: cef6a94
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Sat Aug 12 01:01:26 2017 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Sat Aug 12 01:01:26 2017 -0700
----------------------------------------------------------------------
src/browser.js | 166 ++++++++++++++++++++++++++-------------------------
src/exec.js | 17 +++---
src/main.js | 10 ++--
src/platform.js | 18 +++---
src/server.js | 14 ++---
src/util.js | 16 ++---
6 files changed, 119 insertions(+), 122 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/338a86ba/src/browser.js
----------------------------------------------------------------------
diff --git a/src/browser.js b/src/browser.js
index aca1127..07a93ac 100644
--- a/src/browser.js
+++ b/src/browser.js
@@ -19,10 +19,10 @@
/* globals Promise: true */
-var child_process = require('child_process'),
- fs = require('fs'),
- open = require('open'),
- exec = require('./exec');
+var child_process = require('child_process');
+var fs = require('fs');
+var open = require('open');
+var exec = require('./exec');
var NOT_INSTALLED = 'The browser target is not installed: %target%';
var NOT_SUPPORTED = 'The browser target is not supported: %target%';
@@ -43,60 +43,65 @@ module.exports = function (opts) {
var url = opts.url || '';
target = target.toLowerCase();
- if(target === 'default') {
+ if (target === 'default') {
open(url);
return Promise.resolve();
- }
- else {
+ } else {
return getBrowser(target, opts.dataDir).then(function (browser) {
var args;
var urlAdded = false;
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
-
- if (target === 'edge') {
- browser += ':' + url;
- urlAdded = true;
- }
+ 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
+
+ if (target === 'edge') {
+ browser += ':' + url;
+ urlAdded = true;
+ }
- 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 = ['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;
}
if (!urlAdded) {
args.push(url);
}
var command = args.join(' ');
-
- return exec(command).catch(function (error) {
+ var result = exec(command);
+ result.catch(function () {
// Assume any error means that the browser is not installed and display that as a more friendly error.
throw new Error(NOT_INSTALLED.replace('%target%', target));
});
+ return result;
+
+ // return exec(command).catch(function (error) {
+ // // Assume any error means that the browser is not installed and display that as a more friendly error.
+ // throw new Error(NOT_INSTALLED.replace('%target%', target));
+ // });
});
}
};
-function getBrowser(target, dataDir) {
+function getBrowser (target, dataDir) {
dataDir = dataDir || 'temp_chrome_user_data_dir_for_cordova';
var chromeArgs = ' --user-data-dir=/tmp/' + dataDir;
@@ -128,35 +133,46 @@ function getBrowser(target, dataDir) {
return checkBrowserExistsWindows(browser, target).then(function () {
return Promise.resolve(browser);
});
- }
- else {
+ } else {
return Promise.reject(NOT_SUPPORTED.replace('%target%', target));
}
}
-function checkBrowserExistsWindows(browser, target) {
- var promise = new Promise(function (resolve, reject){
+// err might be null, in which case defaultMsg is used.
+// target MUST be defined or an error is thrown.
+function getErrorMessage (err, target, defaultMsg) {
+ var errMessage;
+ if (err) {
+ errMessage = err.toString();
+ } else {
+ errMessage = defaultMsg;
+ }
+ return errMessage.replace('%target%', target);
+}
+
+function checkBrowserExistsWindows (browser, target) {
+ var promise = new Promise(function (resolve, reject) {
// Windows displays a dialog if the browser is not installed. We'd prefer to avoid that.
if (process.platform === 'win32') {
- if(target === 'edge') {
+ if (target === 'edge') {
edgeSupported().then(function () {
resolve();
})
- .catch(function(err){
- reject((err && err.toString() || NOT_INSTALLED).replace('%target%', target));
- });
- }
- else {
- browserInstalled(browser).then(function() {
+ .catch(function (err) {
+ var errMessage = getErrorMessage(err, target, NOT_INSTALLED);
+ reject(errMessage);
+ });
+ } else {
+ browserInstalled(browser).then(function () {
resolve();
})
- .catch(function(err) {
- reject((err && err.toString() || NOT_INSTALLED).replace('%target%', target));
- });
+ .catch(function (err) {
+ var errMessage = getErrorMessage(err, target, NOT_INSTALLED);
+ reject(errMessage);
+ });
}
- }
- else {
+ } else {
resolve();
}
@@ -164,15 +180,15 @@ function checkBrowserExistsWindows(browser, target) {
return promise;
}
-function edgeSupported() {
- var prom = new Promise(function(resolve,reject){
+function edgeSupported () {
+ var prom = new Promise(function (resolve, reject) {
child_process.exec('ver', function (err, stdout, stderr) {
if (err || stderr) {
reject(err || stderr);
} else {
var windowsVersion = stdout.match(/([0-9.])+/g)[0];
if (parseInt(windowsVersion) < 10) {
- reject('The browser target is not supported on this version of Windows: %target%');
+ reject(new Error('The browser target is not supported on this version of Windows: %target%'));
} else {
resolve();
}
@@ -183,43 +199,31 @@ function edgeSupported() {
}
var regItemPattern = /\s*\(Default\)\s+(REG_SZ)\s+([^\s].*)\s*/;
-function browserInstalled(browser) {
+function browserInstalled (browser) {
// On Windows, the 'start' command searches the path then 'App Paths' in the registry.
// We do the same here. Note that the start command uses the PATHEXT environment variable
// for the list of extensions to use if no extension is provided. We simplify that to just '.EXE'
// since that is what all the supported browsers use. Check path (simple but usually won't get a hit)
- var promise = new Promise(function(resolve,reject) {
+ var promise = new Promise(function (resolve, reject) {
if (require('shelljs').which(browser)) {
return resolve();
- }
- else {
- var regQPre = 'reg QUERY "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\';
+ } else {
+ var regQPre = 'reg QUERY "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\';
var regQPost = '.EXE" /v ""';
var regQuery = regQPre + browser.split(' ')[0] + regQPost;
- child_process.exec(regQuery , function (err, stdout, stderr) {
+ child_process.exec(regQuery, function (err, stdout, stderr) {
if (err) {
// The registry key does not exist, which just means the app is not installed.
- reject();
- }
- else {
+ reject(err);
+ } else {
var result = regItemPattern.exec(stdout);
- if (!result) {
- // The registry key exists, but has no default value, which means the app is not
- // installed (note that we don't expect to hit this, since we'll just get a default
- // value of '(value not set)', but that will fail the fs.existsSync() test below
- // to give us the expected result).
- reject();
- }
- else {
- if(fs.existsSync(trimRegPath(result[2]))) {
- resolve();
- }
- else {
- // The default value is not a file that exists, which means the app is not installed.
- reject();
- }
+ if (fs.existsSync(trimRegPath(result[2]))) {
+ resolve();
+ } else {
+ // The default value is not a file that exists, which means the app is not installed.
+ reject(new Error(NOT_INSTALLED));
}
}
});
@@ -228,7 +232,7 @@ function browserInstalled(browser) {
return promise;
}
-function trimRegPath(path) {
+function trimRegPath (path) {
// Trim quotes and whitespace
return path.replace(/^[\s"]+|[\s"]+$/g, '');
}
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/338a86ba/src/exec.js
----------------------------------------------------------------------
diff --git a/src/exec.js b/src/exec.js
index 9f3a625..76d4d0c 100644
--- a/src/exec.js
+++ b/src/exec.js
@@ -28,29 +28,26 @@ var child_process = require('child_process');
* @return {Promise} a promise that either resolves with the stdout, or rejects with an error message and the stderr.
*/
module.exports = function (cmd, opt_cwd) {
- return new Promise(function(resolve,reject){
+ return new Promise(function (resolve, reject) {
try {
var opt = {cwd: opt_cwd, maxBuffer: 1024000};
var timerID = 0;
- if(process.platform === 'linux') {
- timerID = setTimeout(function(){
+ if (process.platform === 'linux') {
+ timerID = setTimeout(function () {
resolve('linux-timeout');
- },5000);
+ }, 5000);
}
- child_process.exec(cmd,opt,function (err, stdout, stderr) {
+ child_process.exec(cmd, opt, function (err, stdout, stderr) {
clearTimeout(timerID);
if (err) {
reject(new Error('Error executing "' + cmd + '": ' + stderr));
- }
- else {
+ } else {
resolve(stdout);
}
});
- }
- catch (e) {
+ } catch (e) {
console.error('error caught: ' + e);
reject(e);
}
});
};
-
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/338a86ba/src/main.js
----------------------------------------------------------------------
diff --git a/src/main.js b/src/main.js
index 01c5add..d8b41bd 100644
--- a/src/main.js
+++ b/src/main.js
@@ -17,21 +17,21 @@
under the License.
*/
-var chalk = require('chalk'),
- compression = require('compression'),
- express = require('express');
+var chalk = require('chalk');
+var compression = require('compression');
+var express = require('express');
module.exports = function () {
return new CordovaServe();
};
-function 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 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) {
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/338a86ba/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 26f9c4b..99a4f87 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -19,8 +19,8 @@
/* globals Promise: true */
-var fs = require('fs'),
- util = require('./util');
+var fs = require('fs');
+var util = require('./util');
/**
* Launches a server where the root points to the specified platform in a Cordova project.
@@ -35,20 +35,18 @@ module.exports = function (platform, opts) {
// note: `this` is actually an instance of main.js CordovaServe
// this module is a mixin
var that = this;
- var retPromise = new Promise(function(resolve,reject){
+ var retPromise = new Promise(function (resolve, reject) {
if (!platform) {
- reject('Error: A platform must be specified');
- }
- else {
+ reject(new Error('Error: A platform must be specified'));
+ } else {
opts = opts || {};
var projectRoot = findProjectRoot(opts.root);
that.projectRoot = projectRoot;
opts.root = util.getPlatformWwwRoot(projectRoot, platform);
if (!fs.existsSync(opts.root)) {
- reject('Error: Project does not include the specified platform: ' + platform);
- }
- else {
+ reject(new Error('Error: Project does not include the specified platform: ' + platform));
+ } else {
return that.launchServer(opts);
}
}
@@ -57,7 +55,7 @@ module.exports = function (platform, opts) {
return retPromise;
};
-function findProjectRoot(path) {
+function findProjectRoot (path) {
var projectRoot = util.cordovaProjectRoot(path);
if (!projectRoot) {
if (!path) {
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/338a86ba/src/server.js
----------------------------------------------------------------------
diff --git a/src/server.js b/src/server.js
index f423f2e..8f4e9ee 100644
--- a/src/server.js
+++ b/src/server.js
@@ -19,8 +19,8 @@
/* globals Promise: true */
-var chalk = require('chalk'),
- express = require('express');
+var chalk = require('chalk');
+var express = require('express');
/**
* @desc Launches a server with the specified options and optional custom handlers.
@@ -29,8 +29,8 @@ var chalk = require('chalk'),
*/
module.exports = function (opts) {
- var that = this;
- var promise = new Promise(function(resolve,reject){
+ var that = this;
+ var promise = new Promise(function (resolve, reject) {
opts = opts || {};
var port = opts.port || 8000;
@@ -39,8 +39,7 @@ module.exports = function (opts) {
if (!opts.noLogOutput) {
if (opts.events) {
opts.events.emit('log', msg);
- }
- else {
+ } else {
console.log(msg);
}
}
@@ -79,8 +78,7 @@ module.exports = function (opts) {
if (e && e.toString().indexOf('EADDRINUSE') > -1) {
port++;
server.listen(port);
- }
- else {
+ } else {
reject(e);
}
});
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/338a86ba/src/util.js
----------------------------------------------------------------------
diff --git a/src/util.js b/src/util.js
index 8fb076b..242e96f 100644
--- a/src/util.js
+++ b/src/util.js
@@ -17,8 +17,8 @@
under the License.
*/
-var fs = require('fs'),
- path = require('path');
+var fs = require('fs');
+var 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
@@ -41,12 +41,12 @@ var platforms = {
* @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) {
+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') {
+ if (pwd && pwd !== cwd && pwd !== 'undefined') {
return cordovaProjectRoot(pwd) || cordovaProjectRoot(cwd);
}
return cordovaProjectRoot(cwd);
@@ -63,7 +63,7 @@ function cordovaProjectRoot(dir) {
}
var parentDir = path.normalize(path.join(dir, '..'));
// Detect fs root.
- if (parentDir == dir) {
+ if (parentDir === dir) {
return bestReturnValueSoFar;
}
dir = parentDir;
@@ -71,15 +71,15 @@ function cordovaProjectRoot(dir) {
return null;
}
-function getPlatformWwwRoot(cordovaProjectRoot, platformName) {
+function getPlatformWwwRoot (cordovaProjectRoot, platformName) {
var platform = platforms[platformName];
if (!platform) {
- throw new Error ('Unrecognized platform: ' + platformName);
+ throw new Error('Unrecognized platform: ' + platformName);
}
return path.join(cordovaProjectRoot, 'platforms', platformName, platform.www_dir);
}
-function isRootDir(dir) {
+function isRootDir (dir) {
if (fs.existsSync(path.join(dir, 'www'))) {
if (fs.existsSync(path.join(dir, 'config.xml'))) {
// For sure is.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[03/12] cordova-serve git commit: setup testing
Posted by pu...@apache.org.
setup testing
Project: http://git-wip-us.apache.org/repos/asf/cordova-serve/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-serve/commit/5ab863a7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-serve/tree/5ab863a7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-serve/diff/5ab863a7
Branch: refs/heads/master
Commit: 5ab863a715ad6f70b52208fa8b7f008fdb16bccc
Parents: 4608607
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Thu Jun 29 11:27:14 2017 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Thu Jun 29 11:27:14 2017 -0700
----------------------------------------------------------------------
package.json | 10 ++++++----
spec/jasmine.json | 8 ++++++++
spec/main.spec.js | 39 +++++++++++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/5ab863a7/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 464fe36..ea460a7 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,11 @@
"version": "1.0.2-dev",
"description": "Apache Cordova server support for cordova-lib and cordova-browser.",
"main": "src/main.js",
+ "scripts": {
+ "jasmine": "jasmine JASMINE_CONFIG_PATH=spec/jasmine.json",
+ "jshint": "node node_modules/jshint/bin/jshint src",
+ "test": "npm run jshint && npm run jasmine"
+ },
"repository": {
"type": "git",
"url": "https://github.com/apache/cordova-lib"
@@ -27,12 +32,9 @@
"shelljs": "^0.5.3"
},
"devDependencies": {
+ "jasmine": "^2.5.2",
"jshint": "^2.8.0"
},
- "scripts": {
- "jshint": "node node_modules/jshint/bin/jshint src",
- "test": "npm run jshint"
- },
"engines": {
"node": ">=4.0.0",
"npm": ">= 2.5.1"
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/5ab863a7/spec/jasmine.json
----------------------------------------------------------------------
diff --git a/spec/jasmine.json b/spec/jasmine.json
new file mode 100644
index 0000000..a5605d2
--- /dev/null
+++ b/spec/jasmine.json
@@ -0,0 +1,8 @@
+{
+ "spec_dir": "spec",
+ "spec_files": [
+ "**/*[sS]pec.js"
+ ],
+ "stopSpecOnExpectationFailure": false,
+ "random": false
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/5ab863a7/spec/main.spec.js
----------------------------------------------------------------------
diff --git a/spec/main.spec.js b/spec/main.spec.js
new file mode 100644
index 0000000..b9acb5d
--- /dev/null
+++ b/spec/main.spec.js
@@ -0,0 +1,39 @@
+/**
+ 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 main = require("..");
+
+describe('main', function() {
+
+ it('exists and has expected properties', function() {
+ expect(main).toBeDefined();
+ expect(main.Router).toBeDefined();
+ expect(main.static).toBeDefined();
+ });
+
+ it('is creatable',function() {
+ var instance = main();
+ expect(instance.servePlatform).toBeDefined();
+ expect(typeof instance.servePlatform).toBe('function');
+
+ expect(instance.launchServer).toBeDefined();
+ expect(typeof instance.launchServer).toBe('function');
+
+ expect(instance.launchBrowser).toBeDefined();
+ expect(typeof instance.launchBrowser).toBe('function');
+ });
+});
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[08/12] cordova-serve git commit: reduce mockery,
exec fails on windows which makes the test fail
Posted by pu...@apache.org.
reduce mockery, exec fails on windows which makes the test fail
Project: http://git-wip-us.apache.org/repos/asf/cordova-serve/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-serve/commit/2be7e2b5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-serve/tree/2be7e2b5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-serve/diff/2be7e2b5
Branch: refs/heads/master
Commit: 2be7e2b5858ab4c7b6dadbf22a43568050a23a37
Parents: f5ef63d
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Fri Jun 30 17:07:36 2017 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Fri Jun 30 17:07:36 2017 -0700
----------------------------------------------------------------------
spec/browser.spec.js | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-serve/blob/2be7e2b5/spec/browser.spec.js
----------------------------------------------------------------------
diff --git a/spec/browser.spec.js b/spec/browser.spec.js
index aaa0fce..6fc9a74 100644
--- a/spec/browser.spec.js
+++ b/spec/browser.spec.js
@@ -28,12 +28,6 @@ function expectPromise(obj){
describe('browser', function() {
- beforeEach(function(){
- spyOn(child_process,'exec').and.callFake(function(cmd,options,callback){
- callback && callback(null,"success",null);
- });
- });
-
it('exists and has expected properties', function() {
expect(browser).toBeDefined();
expect(typeof browser).toBe('function');
@@ -46,6 +40,9 @@ describe('browser', function() {
result.then(function(res) {
done();
});
+ result.catch(function(err){
+ done();
+ });
});
it('should call open() when target is `default`', function(done) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org