diff --git a/browser-sync/browser-sync-tests.ts b/browser-sync/browser-sync-tests.ts
index 210a8cf1b..822c941d9 100644
--- a/browser-sync/browser-sync-tests.ts
+++ b/browser-sync/browser-sync-tests.ts
@@ -78,6 +78,8 @@ evt.on("init", function () {
browserSync(config);
+var has = browserSync.has("My server");
+
var bs = browserSync.create();
bs.init({
@@ -85,7 +87,7 @@ bs.init({
});
bs.reload();
-
+
function browserSyncInit(): browserSync.BrowserSyncInstance {
var browser = browserSync.create();
browser.init();
@@ -95,3 +97,26 @@ function browserSyncInit(): browserSync.BrowserSyncInstance {
}
var browser = browserSyncInit();
browser.exit();
+
+// Stream method.
+
+// -- No options.
+browser.stream();
+
+// -- "once" option.
+browser.stream({once: true});
+
+// -- "match" option (string).
+browser.stream({match: "**/*.js"});
+
+// -- "match" option (RegExp).
+browser.stream({match: /\.js$/});
+
+// -- "match" option (function).
+browser.stream({match: (testString) => true});
+
+// -- "match" option (array).
+browser.stream({match: ["**/*.js", /\.js$/, (testString) => true]});
+
+// -- Both options.
+browser.stream({once: true, match: ["**/*.js", /\.js$/, (testString) => true]});
diff --git a/browser-sync/browser-sync.d.ts b/browser-sync/browser-sync.d.ts
index 9d4cbcce3..6640090bc 100644
--- a/browser-sync/browser-sync.d.ts
+++ b/browser-sync/browser-sync.d.ts
@@ -5,25 +5,27 @@
///
///
+///
declare module "browser-sync" {
import chokidar = require("chokidar");
import fs = require("fs");
import http = require("http");
+ import mm = require("micromatch");
namespace browserSync {
interface Options {
/**
- * Browsersync includes a user-interface that is accessed via a separate port. The UI allows to controls
+ * Browsersync includes a user-interface that is accessed via a separate port. The UI allows to controls
* all devices, push sync updates and much more.
- *
+ *
* port - Default: 3001
* weinre.port - Default: 8080
* Note: requires at least version 2.0.0
*/
ui?: UIOptions;
/**
- * Browsersync can watch your files as you work. Changes you make will either be injected into the page (CSS
+ * Browsersync can watch your files as you work. Changes you make will either be injected into the page (CSS
* & images) or will cause all browsers to do a full-page refresh. See anymatch for more information on glob
* patterns.
* Default: false
@@ -55,14 +57,14 @@ declare module "browser-sync" {
*/
port?: number;
/**
- * Add additional directories from which static files should be served.
+ * Add additional directories from which static files should be served.
* Should only be used in proxy or snippet mode.
* Default: []
* Note: requires at least version 2.8.0
*/
serveStatic?: string[];
/**
- * Enable https for localhost development.
+ * Enable https for localhost development.
* Note - this is not needed for proxy option as it will be inferred from your target url.
* Note: requires at least version 1.3.0
*/
@@ -102,7 +104,7 @@ declare module "browser-sync" {
*/
logSnippet?: boolean;
/**
- * You can control how the snippet is injected onto each page via a custom regex + function.
+ * You can control how the snippet is injected onto each page via a custom regex + function.
* You can also provide patterns for certain urls that should be ignored from the snippet injection.
* Note: requires at least version 2.0.0
*/
@@ -119,13 +121,13 @@ declare module "browser-sync" {
*/
tunnel?: string | boolean;
/**
- * Some features of Browsersync (such as xip & tunnel) require an internet connection, but if you're
+ * Some features of Browsersync (such as xip & tunnel) require an internet connection, but if you're
* working offline, you can reduce start-up time by setting this option to false
*/
online?: boolean;
/**
* Default: true
- * Decide which URL to open automatically when Browsersync starts. Defaults to "local" if none set.
+ * Decide which URL to open automatically when Browsersync starts. Defaults to "local" if none set.
* Can be true, local, external, ui, ui-external, tunnel or false
*/
open?: string | boolean;
@@ -135,7 +137,7 @@ declare module "browser-sync" {
*/
browser?: string | string[];
/**
- * Requires an internet connection - useful for services such as Typekit as it allows you to configure
+ * Requires an internet connection - useful for services such as Typekit as it allows you to configure
* domains such as *.xip.io in your kit settings
* Default: false
*/
@@ -154,14 +156,14 @@ declare module "browser-sync" {
* scrollProportionally: false // Sync viewports to TOP position
* Default: true
*/
- scrollProportionally?: boolean
+ scrollProportionally?: boolean;
/**
* How often to send scroll events
* Default: 0
*/
scrollThrottle?: number;
/**
- * Decide which technique should be used to restore scroll position following a reload.
+ * Decide which technique should be used to restore scroll position following a reload.
* Can be window.name or cookie
* Default: 'window.name'
*/
@@ -175,13 +177,13 @@ declare module "browser-sync" {
/**
* Default: []
* Note: requires at least version 2.9.0
- * Sync the scroll position of any element on the page - where any scrolled element will cause
- * all others to match scroll position. This is helpful when a breakpoint alters which element
+ * Sync the scroll position of any element on the page - where any scrolled element will cause
+ * all others to match scroll position. This is helpful when a breakpoint alters which element
* is actually scrolling
*/
scrollElementMapping?: string[];
/**
- * Time, in milliseconds, to wait before instructing the browser to reload/inject following a file
+ * Time, in milliseconds, to wait before instructing the browser to reload/inject following a file
* change event
* Default: 0
*/
@@ -227,7 +229,7 @@ declare module "browser-sync" {
*/
timestamps?: boolean;
/**
- * Alter the script path for complete control over where the Browsersync Javascript is served
+ * Alter the script path for complete control over where the Browsersync Javascript is served
* from. Whatever you return from this function will be used as the script path.
* Note: requires at least version 1.5.0
*/
@@ -250,7 +252,7 @@ declare module "browser-sync" {
[path: string]: T;
}
- interface UIOptions {
+ interface UIOptions {
/** set the default port */
port?: number;
/** set the default weinre port */
@@ -266,9 +268,9 @@ declare module "browser-sync" {
directory?: boolean;
/** set index filename */
index?: string;
- /**
- * key-value object hash, where the key is the url to match,
- * and the value is the folder to serve (relative to your working directory)
+ /**
+ * key-value object hash, where the key is the url to match,
+ * and the value is the folder to serve (relative to your working directory)
*/
routes?: Hash;
/** configure custom middleware */
@@ -312,9 +314,14 @@ declare module "browser-sync" {
fn: (match: string) => string;
}
+ interface StreamOptions {
+ once?: boolean;
+ match?: mm.Pattern | mm.Pattern[];
+ }
+
interface BrowserSyncStatic extends BrowserSyncInstance {
/**
- * Start the Browsersync service. This will launch a server, proxy or start the snippet mode
+ * Start the Browsersync service. This will launch a server, proxy or start the snippet mode
* depending on your use-case.
*/
(config?: Options, callback?: (err: Error, bs: Object) => any): BrowserSyncInstance;
@@ -328,36 +335,41 @@ declare module "browser-sync" {
* @param name the identifier used for retrieval
*/
get(name: string): BrowserSyncInstance;
+ /**
+ * Check if an instance has been created.
+ * @param name the name of the instance
+ */
+ has(name: string): boolean;
}
interface BrowserSyncInstance {
/** the name of this instance of browser-sync */
name: string;
/**
- * Start the Browsersync service. This will launch a server, proxy or start the snippet mode
+ * Start the Browsersync service. This will launch a server, proxy or start the snippet mode
* depending on your use-case.
*/
init(config?: Options, callback?: (err: Error, bs: Object) => any): BrowserSyncInstance;
/**
* Reload the browser
- * The reload method will inform all browsers about changed files and will either cause the browser
+ * The reload method will inform all browsers about changed files and will either cause the browser
* to refresh, or inject the files where possible.
*/
reload(): void;
/**
* Reload a single file
- * The reload method will inform all browsers about changed files and will either cause the browser
+ * The reload method will inform all browsers about changed files and will either cause the browser
* to refresh, or inject the files where possible.
*/
reload(file: string): void;
/**
* Reload multiple files
- * The reload method will inform all browsers about changed files and will either cause the browser
+ * The reload method will inform all browsers about changed files and will either cause the browser
* to refresh, or inject the files where possible.
*/
reload(files: string[]): void;
/**
- * The reload method will inform all browsers about changed files and will either cause the browser
+ * The reload method will inform all browsers about changed files and will either cause the browser
* to refresh, or inject the files where possible.
*/
reload(options: { stream: boolean }): NodeJS.ReadWriteStream;
@@ -365,7 +377,7 @@ declare module "browser-sync" {
* The stream method returns a transform stream and can act once or on many files.
* @param opts Configuration for the stream method
*/
- stream(opts?: { once: boolean }): NodeJS.ReadWriteStream;
+ stream(opts?: StreamOptions): NodeJS.ReadWriteStream;
/**
* Helper method for browser notifications
* @param message Can be a simple message such as 'Connected' or HTML
@@ -390,7 +402,7 @@ declare module "browser-sync" {
*/
resume(): void;
/**
- * The internal Event Emitter used by the running Browsersync instance (if there is one). You can use
+ * The internal Event Emitter used by the running Browsersync instance (if there is one). You can use
* this to emit your own events, such as changed files, logging etc.
*/
emitter: NodeJS.EventEmitter;