Adding browser-sync definitions

Browser Sync is also really helpful if you want to setup a TypeScript
only development environment.
This commit is contained in:
Phips Peter
2015-01-28 14:36:15 -08:00
parent 338059f48e
commit e6ef60d24a
2 changed files with 163 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
/// <reference path="./browser-sync.d.ts"/>
import browserSync = require("browser-sync");
browserSync({
server: {
baseDir: "./"
}
});
browserSync({
proxy: "yourlocal.dev"
});
var config = {
server: {
baseDir: "./"
}
};
// config only
browserSync(config);
// config + callback
browserSync(config, function (err, bs) {
if (!err) {
console.log("BrowserSync is ready!");
}
});
// browser reload
browserSync.reload();
// single file
browserSync.reload( "styles.css" );
// multiple files
browserSync.reload( ["styles.css", "ie.css"] );
// streams support
browserSync.reload( { stream: true } );
browserSync.notify("Compiling, please wait!");
browserSync.notify("HTML <span color='green'>is supported</span> too!");
// Since 1.3.0, specify a timeout
browserSync.notify("This message will only last a second", 1000);
browserSync(config, function (err, bs) {
browserSync.exit();
});
console.log(browserSync.active); // false
browserSync(config, function (err, bs) {
console.log(browserSync.active); // true
});
var evt = browserSync.emitter;
evt.on("init", function () {
console.log("BrowserSync is running!");
});
browserSync(config);
+98
View File
@@ -0,0 +1,98 @@
// Type definitions for browser-sync
// Project: http://www.browsersync.io/
// Definitions by: Asana <https://asana.com>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module "browser-sync" {
import http = require("http");
function BrowserSync(config?: BrowserSync.Options, callback?: (err: Error, bs: Object) => any): void;
module BrowserSync {
export function reload(): void;
export function reload(file: string): void;
export function reload(files: string[]): void;
export function reload(options: {stream: boolean}): NodeJS.ReadWriteStream;
export function notify(message: string, timeout?: number): void;
export function exit(): void;
export var active: boolean;
export var emitter: NodeJS.EventEmitter;
interface Options {
files?: string | string[];
watchOptions?: GazeOptions;
server?: ServerOptions;
proxy?: string | boolean;
port?: number;
https?: boolean;
ghostMode?: GhostOptions | boolean;
logLevel?: string;
logPrefix?: string;
logConnections?: boolean;
logFileChanges?: boolean;
logSnippet?: boolean;
snippetOptions?: SnippetOptions;
tunnel?: string | boolean;
online?: boolean;
open?: string | boolean;
browser?: string | string[];
xip?: boolean;
notify?: boolean;
scrollProportionally?: boolean;
scrollThrottle?: number;
reloadDelay?: number;
injectChanges?: boolean;
startPath?: string;
minify?: boolean;
host?: string;
codeSync?: boolean;
timestamps?: boolean;
scriptPath?: (path: string) => string;
socket?: SocketOptions;
}
interface GazeOptions {
interval?: number;
debounceDelay?: number;
mode?: string;
cwd?: string;
}
interface ServerOptions {
baseDir?: string;
directory?: boolean;
index?: string;
routes?: {[path: string]: string};
middleware?: MiddlewareHandler[];
}
interface MiddlewareHandler {
(req: http.ServerRequest, res: http.ServerResponse, next: Function): any;
}
interface GhostOptions {
clicks?: boolean;
scroll?: boolean;
forms?: boolean;
}
interface SnippetOptions {
ignorePaths?: string;
rule?: {match?: RegExp; fn?: (snippet: string, match: string) => any};
}
interface SocketOptions {
path?: string;
clientPath?: string;
namespace?: string;
}
}
export = BrowserSync;
}