cordova-serve
Advanced tools
Comparing version 0.1.2 to 0.1.3
{ | ||
"name": "cordova-serve", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Apache Cordova server support for cordova-lib and cordova-browser.", | ||
@@ -22,2 +22,3 @@ "main": "serve.js", | ||
"dependencies": { | ||
"chalk": "^1.1.1", | ||
"combined-stream": "^1.0.3", | ||
@@ -27,3 +28,3 @@ "d8": "^0.4.4", | ||
"q": "^1.4.1", | ||
"shelljs": "^0.5.1" | ||
"shelljs": "^0.5.3" | ||
}, | ||
@@ -30,0 +31,0 @@ "devDependencies": { |
@@ -23,3 +23,9 @@ <!-- | ||
### 0.1.3 (Aug 22, 2015) | ||
* Clean up cordova-serve console output. | ||
* CB-9546 cordova-serve.servePlatform() should provide project folders | ||
* CB-9545 Cordova-serve's 'noCache' option does not work in IE. | ||
* Add support for --target=edge to launch app in Edge browser. | ||
### 0.1.2 (June 15, 2015) | ||
Initial release |
@@ -33,3 +33,2 @@ /** | ||
module.exports = function (opts) { | ||
//target, url, dataDir | ||
var target = opts.target || 'chrome'; | ||
@@ -40,2 +39,4 @@ var url = opts.url || ''; | ||
var args; | ||
var urlAdded = false; | ||
switch (process.platform) { | ||
@@ -56,3 +57,9 @@ case 'darwin': | ||
// 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 | ||
// 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]; | ||
@@ -66,5 +73,7 @@ break; | ||
} | ||
args.push(url); | ||
if (!urlAdded) { | ||
args.push(url); | ||
} | ||
var command = args.join(' '); | ||
console.log('Executing command: ' + command); | ||
return exec(command); | ||
@@ -84,3 +93,4 @@ }); | ||
'opera': 'opera', | ||
'firefox': 'firefox' | ||
'firefox': 'firefox', | ||
'edge': 'microsoft-edge' | ||
}, | ||
@@ -87,0 +97,0 @@ 'darwin': { |
@@ -40,3 +40,4 @@ /** | ||
opts = opts || {}; | ||
opts.root = util.getPlatformWwwRoot(findProjectRoot(opts.root), platform); | ||
var projectRoot = findProjectRoot(opts.root); | ||
var platformRoot = opts.root = util.getPlatformWwwRoot(projectRoot, platform); | ||
if (!fs.existsSync(opts.root)) { | ||
@@ -46,3 +47,7 @@ throw new Error('Project does not include the specified platform: ' + platform); | ||
return server(opts); | ||
return server(opts).then(function (serverInfo) { | ||
serverInfo.projectRoot = projectRoot; | ||
serverInfo.platformRoot = platformRoot; | ||
return serverInfo; | ||
}); | ||
}); | ||
@@ -49,0 +54,0 @@ }; |
@@ -20,12 +20,12 @@ /** | ||
var fs = require('fs'), | ||
var chalk = require('chalk'), | ||
fs = require('fs'), | ||
http = require('http'), | ||
url = require('url'), | ||
path = require('path'), | ||
Q = require('q'), | ||
stream = require('./stream'); | ||
Q = require('q'); | ||
/** | ||
* @desc Launches a server with the specified options and optional custom handlers. | ||
* @param {{root: ?string, port: ?number, urlPathHandler: ?function, streamHandler: ?function, serverExtender: ?function}} opts | ||
* @param {{root: ?string, port: ?number, noLogOutput: ?bool, noServerInfo: ?bool, urlPathHandler: ?function, streamHandler: ?function, serverExtender: ?function}} opts | ||
* urlPathHandler(urlPath, request, response, do302, do404, serveFile) - an optional method to provide custom handling for | ||
@@ -47,5 +47,11 @@ * processing URLs and serving up the resulting data. Can serve up the data itself using response.write(), or determine | ||
var log = module.exports.log = function () { | ||
if (!opts.noLogOutput) { | ||
console.log.apply(console, arguments); | ||
} | ||
}; | ||
var server = http.createServer(function (request, response) { | ||
function do404() { | ||
console.log('404 ' + request.url); | ||
log(chalk.red('404 ') + request.url); | ||
response.writeHead(404, {'Content-Type': 'text/plain'}); | ||
@@ -57,3 +63,3 @@ response.write('404 Not Found\n'); | ||
function do302(where) { | ||
console.log('302 ' + request.url); | ||
log(chalk.green('302 ') + request.url); | ||
response.setHeader('Location', where); | ||
@@ -65,3 +71,3 @@ response.writeHead(302, {'Content-Type': 'text/plain'}); | ||
function do304() { | ||
console.log('304 ' + request.url); | ||
log(chalk.green('304 ') + request.url); | ||
response.writeHead(304, {'Content-Type': 'text/plain'}); | ||
@@ -109,3 +115,3 @@ response.end(); | ||
} | ||
console.log('200 ' + request.url); | ||
log(chalk.green('200 ') + request.url); | ||
response.writeHead(200, {'Content-Type': 'text/html'}); | ||
@@ -124,3 +130,3 @@ response.write('<html><head><title>Directory listing of ' + urlPath + '</title></head>'); | ||
} else { | ||
var streamHandler = opts.streamHandler || stream; | ||
var streamHandler = opts.streamHandler || require('./stream'); | ||
streamHandler(filePath, request, response); | ||
@@ -131,3 +137,5 @@ } | ||
}).on('listening', function () { | ||
console.log('Static file server running on port ' + port + ' (i.e. http://localhost:' + port + ')\nCTRL + C to shut down'); | ||
if (!opts.noServerInfo) { | ||
log('Static file server running on: ' + chalk.green('http://localhost:' + port) + ' (CTRL + C to shut down)'); | ||
} | ||
deferred.resolve({server: server, port: port}); | ||
@@ -134,0 +142,0 @@ }).on('error', function (e) { |
@@ -20,5 +20,7 @@ /** | ||
var fs = require('fs'), | ||
var chalk = require('chalk'), | ||
fs = require('fs'), | ||
mime = require('mime'), | ||
zlib = require('zlib'); | ||
zlib = require('zlib'), | ||
server = require('./server'); | ||
@@ -55,8 +57,9 @@ // d8 is a date parsing and formatting micro-framework | ||
var acceptEncoding = request.headers['accept-encoding'] || ''; | ||
var encoding = ''; | ||
if (acceptEncoding.match(/\bgzip\b/)) { | ||
console.log('gzip'); | ||
encoding ='(gzip)'; | ||
respHeaders['content-encoding'] = 'gzip'; | ||
readStream = readStream.pipe(zlib.createGzip()); | ||
} else if (acceptEncoding.match(/\bdeflate\b/)) { | ||
console.log('deflate'); | ||
encoding ='(deflate)'; | ||
respHeaders['content-encoding'] = 'deflate'; | ||
@@ -68,5 +71,5 @@ readStream = readStream.pipe(zlib.createDeflate()); | ||
if (noCache) { | ||
respHeaders['Cache-Control'] = 'no-cache'; | ||
respHeaders['Cache-Control'] = 'no-store'; | ||
} | ||
console.log('200 ' + request.url + ' (' + filePath + ')'); | ||
server.log(chalk.green('200 ') + request.url + ' ' + encoding); | ||
response.writeHead(200, respHeaders); | ||
@@ -73,0 +76,0 @@ readStream.pipe(response); |
30498
511
6
+ Addedchalk@^1.1.1
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
Updatedshelljs@^0.5.3