Merge pull request #17858 from andrewiggins/add-gulp-connect

Add gulp-connect typings
This commit is contained in:
Ryan Cavanaugh
2017-07-13 14:16:08 -07:00
committed by GitHub
4 changed files with 219 additions and 0 deletions

View File

@@ -0,0 +1,120 @@
// Copying examples from Readme which currently depend on gulp v3
import * as gulp from 'gulp/v3';
import * as connect from 'gulp-connect';
// Simple example
gulp.task('connect', () => {
connect.server();
});
gulp.task('default', ['connect']);
// LiveReload
gulp.task('connect', () => {
connect.server({
root: 'app',
livereload: true
});
});
gulp.task('html', () => {
gulp.src('./app/*.html')
.pipe(connect.reload());
});
gulp.task('watch', () => {
gulp.watch(['./app/*.html'], ['html']);
});
gulp.task('default', ['connect', 'watch']);
// Start and stop server
gulp.task('jenkins-tests', () => {
connect.server({
port: 8888
});
// run some headless tests with phantomjs
// when process exits:
connect.serverClose();
});
// Multiple server
gulp.task('connectDev', () => {
connect.server({
name: 'Dev App',
root: ['app', 'tmp'],
port: 8000,
livereload: true
});
});
gulp.task('connectDist', () => {
connect.server({
name: 'Dist App',
root: 'dist',
port: 8001,
livereload: true
});
});
gulp.task('html', () => {
gulp.src('./app/*.html')
.pipe(connect.reload());
});
gulp.task('stylus', () => {
gulp.src('./app/stylus/*.styl')
// .pipe(stylus()) // just here for demonstration purposes
.pipe(gulp.dest('./app/css'))
.pipe(connect.reload());
});
gulp.task('watch', () => {
gulp.watch(['./app/*.html'], ['html']);
gulp.watch(['./app/stylus/*.styl'], ['stylus']);
});
gulp.task('default', ['connectDist', 'connectDev', 'watch']);
// Barebones middleware example from Readme
gulp.task('connect', () => {
connect.server({
root: "app",
middleware(connect, opt) {
return [];
}
});
});
// The following tests are custom tests to validate the more complicated APIs
// Validate gulp-connect typings allow express apps to be passed in as middleware
import * as express from "express";
gulp.task('connect', () => {
let middleware = [
express()
];
return connect.server({
root: [__dirname],
port: 8081,
livereload: true,
middleware: (connect, opt) => middleware
});
});
// Validate using paths to restrict handler functions works
gulp.task('connect', () => {
let middleware: connect.ConnectRouteHandler[] = [
["/path", express()],
["/path2", express()],
];
return connect.server({
root: [__dirname],
port: 8081,
livereload: true,
middleware: (connect, opt) => middleware
});
});

76
types/gulp-connect/index.d.ts vendored Normal file
View File

@@ -0,0 +1,76 @@
// Type definitions for gulp-connect 5.0
// Project: https://github.com/avevlad/gulp-connect#readme
// Definitions by: Andre Wiggins <https://github.com/andrewiggins>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import * as http from "http";
import * as https from "https";
import * as connectModule from "connect";
export interface LiveReloadOptions {
/** Port to run live reload server on. Defauls to 35729. */
port: number;
/** Hostname to bind live reload server to */
hostname?: string;
}
/** a list of [string, HandlerFunction] where the string is the path (i.e. route) that the handler function should be invoked for */
export type ConnectRouteHandler = [ string, connectModule.HandleFunction ];
/**
* Factory function that returns a list of middleware handlers to pass to a connect server's use function.
* The list contain normal Connect middleware handler functions or ConnectRoutHandlers
*/
export type MiddlewareFactory = (connect: typeof connectModule, options: ConnectAppOptions) => Array<connectModule.HandleFunction | ConnectRouteHandler>;
export interface ConnectAppOptions {
/** The name of this server. Used in logs. Defaults to "Server". */
name?: string;
/** The root path. Defaults to directory with gulpfile */
root?: string | string[];
/** The connect webserver port. Defaults to 8080 */
port?: number;
/** Host to bind server to. Defaults to localhost. */
host?: string;
/** Don't log any messages. Defaults to false. */
slient?: boolean;
/**
* Options to pass to http.createServer (or false to disable https).
* Defaults to false. When https is just set to true, then internally
* some defaults will be used.
*/
https?: boolean | https.ServerOptions;
/** Enable/disable livereload or set live reload options. Defaults to false. */
livereload?: boolean | LiveReloadOptions;
/** A function to run custom initialization on the underlying http or https server */
serverInit?(server: http.Server | https.Server): void;
/** File to serve if url results in a 404. Defaults to undefined */
fallback?: string;
/** Middleware factory function which should return a list of connect handler functions . Defaults to () => []; */
middleware?: MiddlewareFactory;
/** Whether or not to log debug messages. Defaults to false. */
debug?: boolean;
/** Value to pass into the serve-static's index option. See serve-static documentation for details. Defaults to true. */
index?: boolean | string | string[];
}
/** Create a gulp-connect server with the given options */
export function server(options?: ConnectAppOptions): ConnectAppOptions;
/** Reload all gulp-connect servers that have livereload enabled */
export function reload(): any;
/** Close all gulp-connect servers */
export function serverClose(): void;

View File

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

View File

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