b2g-scripts
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -0,1 +1,4 @@ | ||
# 0.3.0 | ||
* server can now accept multiple app directories to serve from. | ||
# 0.2.1 | ||
@@ -2,0 +5,0 @@ * server's port option can now handle :7777 as a port. |
{ | ||
"name": "b2g-scripts", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"author": "James Lal <jlal@mozilla.com>", | ||
@@ -5,0 +5,0 @@ "description": "B2G/Gaia Helper Scripts", |
@@ -6,2 +6,9 @@ var Server = require('../lib/script')({ | ||
options: { | ||
dir: { | ||
alias: 'd', | ||
desc: 'App directories may be passed multiple times relative to gaia root', | ||
default: ['apps/'] | ||
}, | ||
gaia: { | ||
@@ -25,4 +32,20 @@ alias: 'g', | ||
fs = require('fs'), | ||
dirs = [], | ||
port = parseInt(argv.port.toString().replace(/[^0-9]/g, '')); | ||
if (argv.dir) { | ||
if(typeof(argv.dir) === 'string') { | ||
argv.dir = [argv.dir]; | ||
} | ||
dirs = argv.dir; | ||
} else { | ||
dirs = ['apps/']; | ||
} | ||
if(dirs.length === 0) { | ||
console.error('\nERROR: You must pass --dir or --gaia to provide a list of apps to serve.\n'); | ||
this.help(1); | ||
} | ||
if (!fsPath.existsSync(argv.gaia)) { | ||
@@ -33,7 +56,24 @@ console.error('Invalid path: ', argv.gaia); | ||
console.log(port); | ||
var apps = {}; | ||
var apps = fs.readdirSync(fsPath.join(argv.gaia, 'apps')); | ||
dirs.forEach(function(dir) { | ||
var path = fsPath.join(argv.gaia, dir), | ||
appList = fs.readdirSync(path); | ||
appList.forEach(function(app) { | ||
if (app.indexOf('.') === 0) { | ||
return; | ||
} | ||
apps[app] = dir; | ||
}); | ||
}); | ||
var file = new(static.Server)(argv.gaia); | ||
var key; | ||
for(key in apps) { | ||
console.log('SERVE: ' + key + ' from appdir: ' + apps[key]); | ||
} | ||
require('http').createServer(function (request, response) { | ||
@@ -44,4 +84,4 @@ request.addListener('end', function () { | ||
if(apps.indexOf(app) !== -1) { | ||
request.url = fsPath.join('/apps', app, request.url); | ||
if(apps[app]) { | ||
request.url = fsPath.join('/' + apps[app], app, request.url); | ||
file.serve( | ||
@@ -48,0 +88,0 @@ request, response |
13030
361