Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyShane committed Apr 12, 2015
2 parents d063a0c + ca517d0 commit 6f6532a
Show file tree
Hide file tree
Showing 48 changed files with 1,669 additions and 552 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ sudo: false
git:
depth: 2
language: node_js
os:
- linux
- osx
node_js:
- iojs
- '0.12'
Expand Down
22 changes: 20 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ module.exports.use = function () {
*/
module.exports.reload = noop("reload");

/**
* The `stream` method returns a transform stream and can act once or on many files.
*
* @method stream
* @param {Object} [opts] Configuration for the stream method
* @returns {*}
*/
module.exports.stream = noop("stream");

/**
* Helper method for browser notifications
*
Expand All @@ -74,6 +83,13 @@ module.exports.notify = noop("notify");
*/
module.exports.exit = noop("exit");

/**
* File watcher
*
* @method watch
*/
module.exports.watch = noop("watch");

/**
* Method to pause file change events
*
Expand Down Expand Up @@ -159,7 +175,7 @@ function noop(name) {
if (singleton) {
return singleton[name].apply(singleton, args);
} else {
if (name === "reload" && args[0] && args[0].stream) {
if (name === "stream") {
return utils.noopStream();
}
}
Expand Down Expand Up @@ -248,10 +264,12 @@ function create(name, emitter) {
pause: require("./lib/public/pause")(browserSync),
resume: require("./lib/public/resume")(browserSync),
reload: require("./lib/public/reload")(emitter),
stream: require("./lib/public/stream")(emitter),
cleanup: browserSync.cleanup.bind(browserSync),
use: browserSync.registerPlugin.bind(browserSync),
getOption: browserSync.getOption.bind(browserSync),
emitter: browserSync.events
emitter: browserSync.events,
watch: require("./lib/file-watcher").watch
};

Object.defineProperty(instance, "active", {
Expand Down
17 changes: 5 additions & 12 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,17 @@ module.exports = {
}

if (Immutable.Map.isMap(item)) {
item.forEach(function (value, key) {
loadPlugin(key, value);
});
loadPlugin(item.get("module"), item.get("options"));
}
});

function loadPlugin (name, opts) {
try {
opts = opts ? opts.toJS() : {};
opts = opts ? opts.toJS() : {};
if (_.isString(name)) {
opts.moduleName = name;
bs.registerPlugin(require(name), opts);

} catch (e) {
if (e.code === "MODULE_NOT_FOUND") {
return bs.logger.setOnce("useLevelPrefixes", true).error("Plugin {yellow:`%s`} was not found, did you forget to {cyan:npm install} it?", name);
}
console.error(e);
} else {
bs.registerPlugin(name.toJS(), opts);
}
}

Expand All @@ -97,7 +91,6 @@ module.exports = {
* @param {Function} done
*/
setOptions: function (bs, done) {

done(null, {
options: {
urls: utils.getUrlOptions(bs.options),
Expand Down
22 changes: 12 additions & 10 deletions lib/browser-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,19 +609,29 @@ BrowserSync.prototype.doFileReload = function (data) {

var willReload = utils.willCauseReload(
bs._reloadQueue.map(function (item) { return item.path; }),
bs.options.get("injectFileTypes").toJS());
bs.options.get("injectFileTypes").toJS()
);

bs._reloadTimer = setTimeout(function () {

if (willReload) {
bs.io.sockets.emit("browser:reload");
if (!bs._reloadDebounced) {
bs._reloadDebounced = setTimeout(function () {
bs._reloadDebounced = false;
}, bs.options.get("reloadDebounce"));
bs.io.sockets.emit("browser:reload");
}
} else {
bs._reloadQueue.forEach(function (item) {
bs.io.sockets.emit("file:reload", item);
});
}

clearTimeout(bs._reloadTimer);

bs._reloadTimer = undefined;
bs._reloadQueue = [];

}, bs.options.get("reloadDelay"));
};

Expand Down Expand Up @@ -649,14 +659,6 @@ BrowserSync.prototype.cleanup = function (cb) {
bs.server.close();
}

// Stop any file watching
if (bs.watchers) {
bs.debug("Stopping watchers...");
_.each(bs.watchers, function (item) {
item.watcher.end();
});
}

// Remove all event listeners
if (bs.events) {
bs.debug("Removing event listeners...");
Expand Down
59 changes: 43 additions & 16 deletions lib/cli/cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var url = require("url");
var _ = require("lodash");
var Immutable = require("immutable");
var isList = Immutable.List.isList;
var isMap = Immutable.Map.isMap;
var defaultConfig = require("../default-config");
var immDefs = Immutable.fromJS(defaultConfig);

Expand Down Expand Up @@ -231,29 +232,22 @@ opts.callbacks = {
*/
files: function (value) {

var merged = [];
var namespaces = {core: {}};

if (_.isString(value)) {
merged = merged.concat(opts.utils.explodeFilesArg(value));
}
namespaces.core.globs = [];
namespaces.core.objs = [];

if (value === false) {
return false;
}
var processed = opts.makeFilesArg(value);

if (merged.length) {
return Immutable.List(merged); // default case is array
if (processed.globs.length) {
namespaces.core.globs = processed.globs;
}

if (isList(value)) {
return value;
if (processed.objs.length) {
namespaces.core.objs = processed.objs;
}

return Immutable.fromJS(value).map(function (value) {
if (_.isString(value)) {
return Immutable.List([value]);
}
});
return Immutable.fromJS(namespaces);
},
/**
* @param value
Expand Down Expand Up @@ -284,3 +278,36 @@ opts.merge = function (values, argv) {
});
});
};

/**
* @param value
* @returns {{globs: Array, objs: Array}}
*/
opts.makeFilesArg = function (value) {

var globs = [];
var objs = [];

if (_.isString(value)) {
globs = globs.concat(
opts.utils.explodeFilesArg(value)
);
}

if (isList(value) && value.size) {
value.forEach(function (value) {
if (_.isString(value)) {
globs.push(value);
} else {
if (isMap(value)) {
objs.push(value);
}
}
});
}

return {
globs: globs,
objs: objs
};
};
7 changes: 1 addition & 6 deletions lib/cli/command.reload.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"use strict";

var error = "Could not contact BrowserSync server.";

/**
* $ browser-sync reload <options>
*
Expand All @@ -23,10 +21,7 @@ module.exports = function (opts) {
var url = proto.getUrl({method: "reload", args: flags.files}, flags.url);

require(scheme).get(url, function (res) {
if (res.statusCode !== 200) {
require("logger").logger.error(error);
return opts.cb(new Error(error));
} else {
if (res.statusCode === 200) {
opts.cb(null, res);
}
}).on("error", function (err) {
Expand Down
5 changes: 4 additions & 1 deletion lib/cli/opts.start.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"help": "Output usage information",
"version": "utput the version number",
"version": "Output the version number",
"browser": "Choose which browser should be auto-opened",
"files": "File paths to watch",
"exclude": "File patterns to ignore",
"server": "Run a Local server (uses your cwd as the web root)",
Expand All @@ -17,6 +18,8 @@
"host": "Specify a hostname to use",
"logLevel": "Set the logger output level (silent, info or debug)",
"port": "Specify a port to use",
"reload-delay": "Time in milliseconds to delay the reload event following file changes",
"reload-debounce": "Time in milliseconds to delay the reload event following file changes",
"ui-port": "Specify a port for the UI to use",
"no-notify": "Disable the notify element in browsers",
"no-open": "Don't open a new browser window",
Expand Down
38 changes: 34 additions & 4 deletions lib/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,40 @@ module.exports = {
/**
* 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 [isaacs's minimatch](https://github.com/isaacs/minimatch) for more information on glob patterns.
* a full-page refresh. See [anymatch](https://github.com/es128/anymatch) for more information on glob patterns.
* @property files
* @type Array|String
* @default false
*/
files: false,

/**
* File watching options that get passed along to [Gaze](https://github.com/shama/gaze). Check out the [properties](https://github.com/shama/gaze#properties)
* section of their docs to see which options they support.
* for availbable options
* File watching options that get passed along to [Chokidar](https://github.com/paulmillr/chokidar).
* Check their docs for available options
* @property watchOptions
* @type Object
* @default undefined
* @since 1.3.0
*/
watchOptions: {
/**
*
persistent: true,
ignored: '*.txt',
ignoreInitial: false,
followSymlinks: true,
cwd: '.',
usePolling: true,
alwaysStat: false,
depth: undefined,
interval: 100,
ignorePermissionErrors: false,
atomic: true
*/
},

/**
* Use the built-in static server for basic HTML/JS/CSS websites.
Expand Down Expand Up @@ -244,12 +262,24 @@ module.exports = {
scrollThrottle: 0,

/**
* Time, in milliseconds, to wait before
* instruction browser to reload/inject following a
* file change event
* @property reloadDelay
* @type Number
* @default 0
*/
reloadDelay: 0,

/**
* Restrict the frequency in which browser:reload events
* can be emitted to connected clients
* @property reloadDebounce
* @type Number
* @default 0
*/
reloadDebounce: 0,

/**
* User provided plugins
* @property plugins
Expand Down
Loading

0 comments on commit 6f6532a

Please sign in to comment.