diff --git a/examples/server.watch.js b/examples/server.watch.js new file mode 100644 index 000000000..986710961 --- /dev/null +++ b/examples/server.watch.js @@ -0,0 +1,20 @@ +/** + * + * Install: + * npm install browser-sync + * + * Run: + * node + * + * This example will create a server using https using the default information & use the `app` directory as the root + * + */ + +"use strict"; + +var browserSync = require("browser-sync").create(); + +browserSync.init({ + server: "test/fixtures", + watch: true +}); diff --git a/lib/cli/cli-options.ts b/lib/cli/cli-options.ts index 94b7d910f..fd9ae633e 100644 --- a/lib/cli/cli-options.ts +++ b/lib/cli/cli-options.ts @@ -10,6 +10,7 @@ import { handleProxyOption } from "./transforms/handleProxyOption"; import { handleServerOption } from "./transforms/handleServerOption"; import { appendServerIndexOption } from "./transforms/appendServerIndexOption"; import { appendServerDirectoryOption } from "./transforms/appendServerDirectoryOption"; +import {addCwdToWatchOptions} from "./transforms/addCwdToWatchOptions"; const _ = require("../lodash.custom"); const defaultConfig = require("../default-config"); @@ -23,6 +24,7 @@ export function merge(input) { const merged = immDefs.mergeDeep(input); const transforms = [ addToFilesOption, + addCwdToWatchOptions, addDefaultIgnorePatterns, copyCLIIgnoreToWatchOptions, handleServerOption, diff --git a/lib/cli/transforms/addCwdToWatchOptions.ts b/lib/cli/transforms/addCwdToWatchOptions.ts new file mode 100644 index 000000000..d3c34b132 --- /dev/null +++ b/lib/cli/transforms/addCwdToWatchOptions.ts @@ -0,0 +1,5 @@ +export function addCwdToWatchOptions(incoming) { + return incoming.updateIn(['watchOptions', 'cwd'], (watchCwd) => { + return watchCwd || incoming.get('cwd'); + }) +} \ No newline at end of file diff --git a/lib/cli/transforms/addDefaultIgnorePatterns.ts b/lib/cli/transforms/addDefaultIgnorePatterns.ts index 83c6b4aaf..03330610d 100644 --- a/lib/cli/transforms/addDefaultIgnorePatterns.ts +++ b/lib/cli/transforms/addDefaultIgnorePatterns.ts @@ -1,6 +1,6 @@ import {List} from "immutable"; -const defaultIgorePatterns = [ +const defaultIgnorePatterns = [ /node_modules/, /bower_components/, /\.sass-cache/, @@ -10,21 +10,16 @@ const defaultIgorePatterns = [ ]; export function addDefaultIgnorePatterns(incoming) { - if (!incoming.get("watch")) { - return incoming; - } - return incoming.update("watchOptions", watchOptions => { const userIgnored = List([]) .concat(watchOptions.get("ignored")) .filter(Boolean) .toSet(); - const merged = userIgnored.merge(defaultIgorePatterns); + const merged = userIgnored.merge(defaultIgnorePatterns); return watchOptions.merge({ ignored: merged.toList(), - cwd: incoming.get("cwd") }); }); } diff --git a/lib/file-watcher.js b/lib/file-watcher.js index 1ccbe914d..d0a88234b 100644 --- a/lib/file-watcher.js +++ b/lib/file-watcher.js @@ -79,6 +79,10 @@ function watch(patterns, opts, cb) { watcher.on("all", cb); } + // watcher.on('ready', () => { + // console.log(watcher.getWatched()); + // }); + return watcher; } diff --git a/test/specs/cli/cli.options.ignore.js b/test/specs/cli/cli.options.ignore.js new file mode 100644 index 000000000..8c35d93b9 --- /dev/null +++ b/test/specs/cli/cli.options.ignore.js @@ -0,0 +1,13 @@ +var cli = require("../../../dist/cli/cli-options"); +var merge = cli.merge; +var assert = require("chai").assert; + +describe("CLI: Options: dealing with 'ignore' option", function() { + it("watches in server mode (no files given)", function() { + var cwd = '/Users/shakyshane/app'; + var input = { server: true, files: ['**/*'], ignore: ['**/*.php'], cwd: cwd }; + var config = merge(input).toJS(); + assert.deepEqual(config.files, { core: { globs: ["**/*"], objs: [] } }); + assert.ok(config.watchOptions.ignored.indexOf('**/*.php') > -1); + }); +}); diff --git a/test/specs/cli/cli.options.watchOptions.cwd.js b/test/specs/cli/cli.options.watchOptions.cwd.js new file mode 100644 index 000000000..2660000a8 --- /dev/null +++ b/test/specs/cli/cli.options.watchOptions.cwd.js @@ -0,0 +1,12 @@ +var cli = require("../../../dist/cli/cli-options"); +var merge = cli.merge; +var assert = require("chai").assert; + +describe("ensures the CWD is transferred to the watchOptions.cwd ", function() { + it("add cwd with files option", function() { + var cwd = '/Users/shakyshane/app'; + var input = { server: true, files: "**/*.html", cwd: cwd }; + var config = merge(input).toJS(); + assert.deepEqual(config.watchOptions.cwd, '/Users/shakyshane/app'); + }); +});