Add live-server type declarations (#45621)

* Add live-server type declarations

* Add shutdown function to live-server types

Co-authored-by: mrjoshc <hello@joshcummingsdesign.com>
This commit is contained in:
Josh Cummings 2020-06-23 08:10:52 -07:00 committed by GitHub
parent 4abecf3200
commit 5142132dc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 0 deletions

40
types/live-server/index.d.ts vendored Normal file
View File

@ -0,0 +1,40 @@
// Type definitions for live-server 1.2
// Project: https://github.com/tapio/live-server#readme
// Definitions by: Josh Cummings <https://github.com/joshcummingsdesign>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* The live-server start params.
*/
export interface LiveServerParams {
/** Set the server port. Defaults to 8080. */
port?: number;
/** Set the address to bind to. Defaults to 0.0.0.0 or process.env.IP. */
host?: string;
/** Set root directory that's being served. Defaults to cwd. */
root?: string;
/** When false, it won't load your browser by default. */
open?: boolean;
/** Comma-separated string for paths to ignore. */
ignore?: string;
/** When set, serve this file (server root relative) for every 404 (useful for single-page applications). */
file?: string;
/** Waits for all changes, before reloading. Defaults to 0 sec. */
wait?: number;
/** Mount a directory to a route. */
mount?: string[][];
/** 0 = errors only, 1 = some, 2 = lots */
logLevel?: 0 | 1 | 2;
/** Takes an array of Connect-compatible middleware that are injected into the server middleware stack. */
middleware?: Array<(req: any, res: any, next: any) => void>;
}
/**
* Start live-server.
*/
export function start(params: LiveServerParams): void;
/**
* Shutdown live-server.
*/
export function shutdown(): void;

View File

@ -0,0 +1,20 @@
import liveServer = require('live-server');
liveServer.start({
port: 8181,
host: '0.0.0.0',
root: '/public',
open: false,
ignore: 'scss,my/templates',
file: 'index.html',
wait: 1000,
mount: [['/components', './node_modules']],
logLevel: 2,
middleware: [
(req: any, res: any, next: any) => {
next();
},
],
});
liveServer.shutdown();

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"live-server-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }