store config in package.json or .local-web-server.json
This commit is contained in:
34
ws.js
34
ws.js
@ -4,8 +4,10 @@ require("console-dope");
|
|||||||
var connect = require("connect"),
|
var connect = require("connect"),
|
||||||
http = require("http"),
|
http = require("http"),
|
||||||
util = require("util"),
|
util = require("util"),
|
||||||
|
fs = require("fs"),
|
||||||
Thing = require("nature").Thing,
|
Thing = require("nature").Thing,
|
||||||
w = require("wodge");
|
w = require("wodge"),
|
||||||
|
path = require("path");
|
||||||
|
|
||||||
var usage = "usage: ws [--directory|-d <directory>] [--port|-p <port>] [--log-format|-f dev|default|short|tiny]";
|
var usage = "usage: ws [--directory|-d <directory>] [--port|-p <port>] [--log-format|-f dev|default|short|tiny]";
|
||||||
|
|
||||||
@ -15,6 +17,14 @@ function halt(message){
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleServerError(err){
|
||||||
|
if (err.code === "EADDRINUSE"){
|
||||||
|
halt("port " + argv.port + " is already is use");
|
||||||
|
} else {
|
||||||
|
halt(err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
parse command-line args
|
parse command-line args
|
||||||
*/
|
*/
|
||||||
@ -29,14 +39,22 @@ var argv = new Thing()
|
|||||||
})
|
})
|
||||||
.set(process.argv);
|
.set(process.argv);
|
||||||
|
|
||||||
function handleServerError(err){
|
/*
|
||||||
if (err.code === "EADDRINUSE"){
|
Include any options from "package.json", ".local-web-server.json" or "~/.local-web-server.json", in that order
|
||||||
halt("port " + argv.port + " is already is use");
|
*/
|
||||||
} else {
|
var pkgPath = path.join(process.cwd(), "package.json"),
|
||||||
halt(err.message);
|
lwsPath = path.join(process.cwd(), ".local-web-server.json"),
|
||||||
}
|
homePath = path.join(w.getHomeDir(), ".local-web-server.json");
|
||||||
|
if (fs.existsSync(pkgPath)){
|
||||||
|
argv.set(require(pkgPath)["local-web-server"]);
|
||||||
}
|
}
|
||||||
|
if (fs.existsSync(lwsPath)){
|
||||||
|
argv.set(require(lwsPath));
|
||||||
|
}
|
||||||
|
if (fs.existsSync(homePath)){
|
||||||
|
argv.set(require(homePath));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Die here if invalid args received
|
Die here if invalid args received
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user