cli options, readme

This commit is contained in:
Lloyd Brookes
2013-06-15 00:41:43 +01:00
parent 98b5a1ec21
commit d196cd3463
3 changed files with 57 additions and 23 deletions

View File

@ -18,4 +18,23 @@ $ ws [port]
``` ```
The `port` arg is optional, the default is 8000. The `port` arg is optional, the default is 8000.
Use with Logstalgia
===================
The `default` log format is compatible with [logstalgia](http://code.google.com/p/logstalgia/).
Write your log output to disk:
```sh
$ ws --logger default > web.log
```
Then visualise in logstalgia:
```sh
$ logstalgia web.log
```
Or pipe directly into logstalgia for real-time visualisation:
```sh
$ ws --logger default | logstalgia -
```
[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/050b17b4263c08f12a2a9d9bbda80025 "githalytics.com")](http://githalytics.com/75lb/local-web-server) [![githalytics.com alpha](https://cruel-carlota.pagodabox.com/050b17b4263c08f12a2a9d9bbda80025 "githalytics.com")](http://githalytics.com/75lb/local-web-server)

View File

@ -1,14 +1,15 @@
{ {
"name": "local-web-server", "name": "local-web-server",
"version": "0.1.3", "version": "0.1.4",
"description": "Local web server", "description": "Local web server",
"bin": { "bin": {
"ws": "./server.js" "ws": "./server.js"
}, },
"repository": "https://github.com/75lb/local-web-server", "repository": "https://github.com/75lb/local-web-server",
"author": "Lloyd Brookes", "author": "Lloyd Brookes",
"license": "BSD", "license": "BSD",
"dependencies": { "dependencies": {
"connect": "~2.7.11" "connect": "~2.7.11",
"nature": "0.0.4"
} }
} }

View File

@ -1,24 +1,38 @@
#!/usr/bin/env node #!/usr/bin/env node
var connect = require('connect'); var connect = require('connect'),
Thing = require("nature").Thing;
/** process.argv.splice(0, 2);
usage:
$ ws <port> <connect-logger-profile>
*/
var port = process.argv[2] || 8000, var usage = "usage: ws [--port|-p <port>] [--log-format|-p dev|default|short|tiny]";
loggerProfile = process.argv[3] || "dev"; var options = new Thing()
.define({ name: "port", alias: "p", type: "number", defaultOption: true, default: 8000 })
.define({ name: "log-format", alias: "f", type: "string", default: "dev" })
.define({ name: "help", alias: "h", type: "boolean" })
.set(process.argv);
connect.logger.token('date', function(req, res){ if (!options.valid){
var a = new Date(); console.log(usage);
return (a.getDate() + "/" + a.getUTCMonth() + "/" + a.getFullYear() + ":" + a.toTimeString()) throw new Error(options.validationMessages);
.replace("GMT", "").replace(" (BST)", "");
}); } else if (options.help){
console.log(usage);
connect()
.use(connect.logger(loggerProfile)) } else {
.use(connect.static(process.cwd())) /**
.use(connect.directory(process.cwd())) customised connect.logger :date token, purely to satisfy Logstalgia.
.listen(port); */
connect.logger.token('date', function(req, res){
process.stderr.write("listening on port " + port + "\n"); var a = new Date();
return (a.getDate() + "/" + a.getUTCMonth() + "/" + a.getFullYear() + ":" + a.toTimeString())
.replace("GMT", "").replace(" (BST)", "");
});
connect()
.use(connect.logger(options["log-format"]))
.use(connect.static(process.cwd()))
.use(connect.directory(process.cwd()))
.listen(options.port);
process.stderr.write("listening on port " + options.port + "\n");
}