Skip to content

Commit dbb1267

Browse files
committed
watcher: adding cwd + ignore defaults to all
1 parent f72a6ad commit dbb1267

File tree

7 files changed

+58
-7
lines changed

7 files changed

+58
-7
lines changed

examples/server.watch.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
*
3+
* Install:
4+
* npm install browser-sync
5+
*
6+
* Run:
7+
* node <yourfile.js>
8+
*
9+
* This example will create a server using https using the default information & use the `app` directory as the root
10+
*
11+
*/
12+
13+
"use strict";
14+
15+
var browserSync = require("browser-sync").create();
16+
17+
browserSync.init({
18+
server: "test/fixtures",
19+
watch: true
20+
});

lib/cli/cli-options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { handleProxyOption } from "./transforms/handleProxyOption";
1010
import { handleServerOption } from "./transforms/handleServerOption";
1111
import { appendServerIndexOption } from "./transforms/appendServerIndexOption";
1212
import { appendServerDirectoryOption } from "./transforms/appendServerDirectoryOption";
13+
import {addCwdToWatchOptions} from "./transforms/addCwdToWatchOptions";
1314

1415
const _ = require("../lodash.custom");
1516
const defaultConfig = require("../default-config");
@@ -23,6 +24,7 @@ export function merge(input) {
2324
const merged = immDefs.mergeDeep(input);
2425
const transforms = [
2526
addToFilesOption,
27+
addCwdToWatchOptions,
2628
addDefaultIgnorePatterns,
2729
copyCLIIgnoreToWatchOptions,
2830
handleServerOption,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function addCwdToWatchOptions(incoming) {
2+
return incoming.updateIn(['watchOptions', 'cwd'], (watchCwd) => {
3+
return watchCwd || incoming.get('cwd');
4+
})
5+
}
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {List} from "immutable";
22

3-
const defaultIgorePatterns = [
3+
const defaultIgnorePatterns = [
44
/node_modules/,
55
/bower_components/,
66
/\.sass-cache/,
@@ -10,21 +10,16 @@ const defaultIgorePatterns = [
1010
];
1111

1212
export function addDefaultIgnorePatterns(incoming) {
13-
if (!incoming.get("watch")) {
14-
return incoming;
15-
}
16-
1713
return incoming.update("watchOptions", watchOptions => {
1814
const userIgnored = List([])
1915
.concat(watchOptions.get("ignored"))
2016
.filter(Boolean)
2117
.toSet();
2218

23-
const merged = userIgnored.merge(defaultIgorePatterns);
19+
const merged = userIgnored.merge(defaultIgnorePatterns);
2420

2521
return watchOptions.merge({
2622
ignored: merged.toList(),
27-
cwd: incoming.get("cwd")
2823
});
2924
});
3025
}

lib/file-watcher.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ function watch(patterns, opts, cb) {
7979
watcher.on("all", cb);
8080
}
8181

82+
// watcher.on('ready', () => {
83+
// console.log(watcher.getWatched());
84+
// });
85+
8286
return watcher;
8387
}
8488

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var cli = require("../../../dist/cli/cli-options");
2+
var merge = cli.merge;
3+
var assert = require("chai").assert;
4+
5+
describe("CLI: Options: dealing with 'ignore' option", function() {
6+
it("watches in server mode (no files given)", function() {
7+
var cwd = '/Users/shakyshane/app';
8+
var input = { server: true, files: ['**/*'], ignore: ['**/*.php'], cwd: cwd };
9+
var config = merge(input).toJS();
10+
assert.deepEqual(config.files, { core: { globs: ["**/*"], objs: [] } });
11+
assert.ok(config.watchOptions.ignored.indexOf('**/*.php') > -1);
12+
});
13+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var cli = require("../../../dist/cli/cli-options");
2+
var merge = cli.merge;
3+
var assert = require("chai").assert;
4+
5+
describe("ensures the CWD is transferred to the watchOptions.cwd ", function() {
6+
it("add cwd with files option", function() {
7+
var cwd = '/Users/shakyshane/app';
8+
var input = { server: true, files: "**/*.html", cwd: cwd };
9+
var config = merge(input).toJS();
10+
assert.deepEqual(config.watchOptions.cwd, '/Users/shakyshane/app');
11+
});
12+
});

0 commit comments

Comments
 (0)