Add CLI
This commit is contained in:
parent
ddc7c41910
commit
fcbe06feb3
5 changed files with 50 additions and 5 deletions
|
@ -2,12 +2,12 @@
|
||||||
"name": "tstatic",
|
"name": "tstatic",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Container to host simple static applications using a node server, so files can be deployed using rsync",
|
"description": "Container to host simple static applications using a node server, so files can be deployed using rsync",
|
||||||
"main": "node ./dist/server.js",
|
"main": "node ./dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"tstatic": "node ./dist/server.js"
|
"tstatic": "node ./dist/index.js"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ./dist/server.js site/",
|
"start": "node ./dist/index.js",
|
||||||
"postinstall": "typings install",
|
"postinstall": "typings install",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"test": "npm run build && nsp check"
|
"test": "npm run build && nsp check"
|
||||||
|
@ -28,6 +28,7 @@
|
||||||
"basic-auth": "=1.1.0",
|
"basic-auth": "=1.1.0",
|
||||||
"compression": "=1.6.2",
|
"compression": "=1.6.2",
|
||||||
"connect-static-file": "=1.1.2",
|
"connect-static-file": "=1.1.2",
|
||||||
|
"docopt": "=0.6.2",
|
||||||
"express": "=4.14.1",
|
"express": "=4.14.1",
|
||||||
"express-basic-auth": "=0.3.2",
|
"express-basic-auth": "=0.3.2",
|
||||||
"express-ip-access-control": "=1.0.5",
|
"express-ip-access-control": "=1.0.5",
|
||||||
|
|
15
src/cli.txt
Normal file
15
src/cli.txt
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
tstatic.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
tstatic <dir> [options]
|
||||||
|
tstatic -h | --help
|
||||||
|
tstatic --version
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-h --help Show this screen.
|
||||||
|
--version Show version.
|
||||||
|
-b <auth> --basic-auth=<auth> Enable basic-auth.
|
||||||
|
-i <ips> --ips=<ips> Allowed IP addresses.
|
||||||
|
-l --list-dir List Directory.
|
||||||
|
-o --opbeat Enable Opbeat.
|
||||||
|
|
28
src/index.ts
Normal file
28
src/index.ts
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import { docopt } from 'docopt';
|
||||||
|
import { readFileSync } from 'fs';
|
||||||
|
import { join } from 'path';
|
||||||
|
import { Options } from './types';
|
||||||
|
import createServer from './server';
|
||||||
|
|
||||||
|
const ARG_DATA = readFileSync(join(__dirname, '..', 'src', 'cli.txt')).toString();
|
||||||
|
|
||||||
|
function getArgs() : Options {
|
||||||
|
const rawArgs = docopt(ARG_DATA, {
|
||||||
|
version: require('../package.json').version,
|
||||||
|
help: true
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
allowed_ips: rawArgs['--ips'] ? rawArgs['--ips'].split(',') : [],
|
||||||
|
basicAuth: rawArgs['--basic-auth'] || '',
|
||||||
|
dirList: rawArgs['--list-dir'],
|
||||||
|
serveDir: rawArgs['<dir>'],
|
||||||
|
opbeat: rawArgs['--opbeat']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const app = createServer(getArgs());
|
||||||
|
|
||||||
|
const server = app.listen(5000, function () {
|
||||||
|
console.log("Server started on port " + server.address().port);
|
||||||
|
});
|
|
@ -1,4 +1,4 @@
|
||||||
import express from 'express';
|
import express, { Application } from 'express';
|
||||||
|
|
||||||
import AccessControl from 'express-ip-access-control';
|
import AccessControl from 'express-ip-access-control';
|
||||||
import compression from 'compression';
|
import compression from 'compression';
|
||||||
|
@ -12,7 +12,7 @@ import handle404 from './middleware/404';
|
||||||
|
|
||||||
import { Options } from './types';
|
import { Options } from './types';
|
||||||
|
|
||||||
export default function createServer(opts : Options) {
|
export default function createServer(opts : Options) : Application {
|
||||||
const app = express();
|
const app = express();
|
||||||
const opbeatHandle = opbeat.start({
|
const opbeatHandle = opbeat.start({
|
||||||
active: opts.opbeat
|
active: opts.opbeat
|
||||||
|
|
1
src/types/fakes.d.ts
vendored
1
src/types/fakes.d.ts
vendored
|
@ -6,3 +6,4 @@ declare module 'express-basic-auth';
|
||||||
declare module 'winston'; // doesnt like console transport
|
declare module 'winston'; // doesnt like console transport
|
||||||
declare module 'express-winston';
|
declare module 'express-winston';
|
||||||
declare module 'opbeat';
|
declare module 'opbeat';
|
||||||
|
declare module 'docopt';
|
||||||
|
|
Reference in a new issue