browser-sync
Advanced tools
Comparing version 0.1.10 to 0.2.0
var portScanner = require('portscanner'); | ||
var chokidar = require('chokidar'); | ||
var gaze = require('gaze'); | ||
var _ = require("lodash"); | ||
@@ -20,7 +20,13 @@ var fs = require("fs"); | ||
var io; | ||
browserSync.prototype = { | ||
options: { | ||
injectFileTypes: ['css', 'png', 'jpg', 'svg', 'gif'] | ||
}, | ||
/** | ||
* Files patterns | ||
* @param files | ||
* @param options | ||
*/ | ||
init: function (files, options) { | ||
@@ -364,16 +370,20 @@ | ||
var _this = this; | ||
var _this = this, log = this.log; | ||
var watcher = chokidar.watch(files, {persistent: true}); | ||
gaze(files, function(err, watcher) { | ||
watcher.on('change', function (filepath, info) { | ||
if (!info.size) { | ||
return; | ||
var key = Object.keys(this.watched())[0]; | ||
if (key) { | ||
log(messages.fileWatching(watcher._patterns), options, true); | ||
} else { | ||
log(messages.fileWatching(false), options, true); | ||
} | ||
callback(filepath, io, options, _this); | ||
}); | ||
this.log(messages.fileWatching(Array.isArray(files) ? files.length : 1), options, true); | ||
// On file changed | ||
this.on('changed', function(filepath) { | ||
callback(filepath, io, options, _this); | ||
}); | ||
}); | ||
}, | ||
@@ -380,0 +390,0 @@ getFileExtension: function (path) { |
@@ -5,4 +5,3 @@ #! /usr/bin/env node | ||
var argv = require('optimist').argv; | ||
var si = require("./browser-sync"); | ||
var glob = require("glob"); | ||
var bs = require("./browser-sync"); | ||
var fs = require("fs"); | ||
@@ -27,3 +26,3 @@ var _ = require("lodash"); | ||
var browserSync = new si(); | ||
var browserSync = new bs(); | ||
@@ -49,2 +48,8 @@ var setup = { | ||
}, | ||
/** | ||
* @param defaultConfig | ||
* @param argv | ||
* @returns {*} | ||
* @private | ||
*/ | ||
_mergeConfigs: function (defaultConfig, argv) { | ||
@@ -61,2 +66,8 @@ | ||
}, | ||
/** | ||
* @param defaultConfig | ||
* @param argv | ||
* @returns {*} | ||
* @private | ||
*/ | ||
_setDefaultServerConfig: function (defaultConfig, argv) { | ||
@@ -80,2 +91,8 @@ | ||
}, | ||
/** | ||
* Retrieve the config file | ||
* @param path | ||
* @returns {*} | ||
* @private | ||
*/ | ||
_getConfigFile: function (path) { | ||
@@ -92,3 +109,3 @@ if (fs.existsSync(path)) { | ||
* @param {object} config | ||
* @returns {argv.files|*|.watch.negate.files|exports.files|.echo.files|.watch.files} | ||
* @returns {argv.files} | ||
*/ | ||
@@ -98,39 +115,29 @@ getFilesArg: function (argv, config) { | ||
}, | ||
getFiles: function (files, cb) { | ||
/** | ||
* Resolve the file patterns | ||
* @param filesArg | ||
* @returns {*} | ||
*/ | ||
getFiles: function (filesArg) { | ||
var isString; | ||
var returnFiles = []; | ||
if (typeof filesArg === "string") { | ||
if (typeof files === "string") { | ||
isString = true; | ||
if(files.indexOf(",") !== -1) { | ||
files = files.split(","); | ||
isString = false; | ||
if(filesArg.indexOf(",") !== -1) { | ||
return filesArg.split(","); | ||
} else { | ||
return (filesArg.length > 0) ? filesArg : false; | ||
} | ||
} | ||
if (Array.isArray(filesArg)) { | ||
return filesArg | ||
} | ||
if (Array.isArray(files)) { // if an array given | ||
files.forEach(function (file, i) { | ||
glob(file, function (er, foundFiles) { | ||
returnFiles.push(foundFiles); | ||
if (i === files.length - 1) { | ||
cb(_.flatten(returnFiles)); | ||
} | ||
}); | ||
}); | ||
} else { | ||
if (isString) { | ||
glob(files, function (er, foundFiles) { | ||
cb(foundFiles); | ||
}); | ||
} else { | ||
cb([]); | ||
} | ||
} | ||
return false; | ||
}, | ||
/** | ||
* Kickoff browser-sync | ||
* @param files | ||
* @param config | ||
*/ | ||
kickoff: function (files, config) { | ||
@@ -141,12 +148,14 @@ browserSync.init(files || [], config); | ||
/** | ||
* Was it run from the command line? | ||
*/ | ||
if (require.main === module) { | ||
var config = setup.getConfig(defaultConfig, argv); | ||
var filesArg = setup.getFilesArg(argv, config); | ||
var config = setup.getConfig(defaultConfig, argv), | ||
filesArg = setup.getFilesArg(argv, config), | ||
files = setup.getFiles(filesArg); | ||
setup.getFiles(filesArg, function (files) { | ||
setup.kickoff(files, config); | ||
}); | ||
setup.kickoff(files, config); | ||
} | ||
module.exports.setup = setup; |
@@ -5,59 +5,68 @@ var clc = require("cli-color"); | ||
module.exports = { | ||
connection: function (browser) { | ||
return clc.cyan("Browser Connected! (" + browser.name + ", version: " + browser.version + ")"); | ||
}, | ||
init: function (hostIp, socketIoPort, scriptPort) { | ||
return clc.yellow('\n\nAll Set Up! Now copy & paste this snippet just before the closing </body> tag in your website.\n\n') + | ||
connection: function (browser) { | ||
return clc.cyan("Browser Connected! (" + browser.name + ", version: " + browser.version + ")"); | ||
}, | ||
init: function (hostIp, socketIoPort, scriptPort) { | ||
return clc.yellow('\n\nAll Set Up! Now copy & paste this snippet just before the closing </body> tag in your website.\n\n') + | ||
this.scriptTags(hostIp, socketIoPort, scriptPort, false); | ||
}, | ||
initServer: function (hostIp, scriptPort, baseDir) { | ||
}, | ||
initServer: function (hostIp, scriptPort, baseDir) { | ||
return clc.green("\nOK, Server running at ") + clc.magenta("http://" + hostIp + ":" + scriptPort +"\n\n") + | ||
clc.green("Serving files from: ") + clc.magenta(baseDir) + "\n\n" + | ||
clc.green("Go load a browser & check back here. If you set up everthing correctly, you'll see a " + | ||
"'Browser Connected' message.\n"); | ||
}, | ||
scriptTags : function (hostIp, socketIoPort, scriptPort, colors) { | ||
var tags = "<script src='http://" + hostIp + ":" + socketIoPort + this.socketIoScript + "'></script>\n" + | ||
"<script src='http://" + hostIp + ":" + scriptPort + this.clientScript + "'></script>\n\n"; | ||
return clc.green("\nOK, Server running at ") + clc.magenta("http://" + hostIp + ":" + scriptPort + "\n\n") + | ||
clc.green("Serving files from: ") + clc.magenta(baseDir) + "\n\n" + | ||
clc.green("Go load a browser & check back here. If you set up everthing correctly, you'll see a " + | ||
"'Browser Connected' message.\n"); | ||
}, | ||
scriptTags: function (hostIp, socketIoPort, scriptPort, colors) { | ||
var tags = "<script src='http://" + hostIp + ":" + socketIoPort + this.socketIoScript + "'></script>\n" + | ||
"<script src='http://" + hostIp + ":" + scriptPort + this.clientScript + "'></script>\n\n"; | ||
if (colors) { | ||
return clc.magenta(tags); | ||
} | ||
if (colors) { | ||
return clc.magenta(tags); | ||
} | ||
return tags; | ||
return tags; | ||
}, | ||
invalidBaseDir: function () { | ||
return clc.cyan("Invalid Base Directory path for server. ( baseDir: )\n\n") + | ||
clc.green("TIP: Don't use a forward slash at the beginning, and if you " + | ||
"want to serve files from the root folder, just set the baseDir option to './' "); | ||
}, | ||
fileWatching: function (patterns) { | ||
var string; | ||
if (Array.isArray(patterns) && patterns.length) { | ||
string = clc.cyan("Watching the following:\n"); | ||
patterns.forEach(function (item) { | ||
string += item.replace(" ", "") + "\n"; | ||
}); | ||
} else { | ||
string = "Not watching anything..."; | ||
} | ||
return string; | ||
}, | ||
fileChanged: function (path) { | ||
return clc.magenta("File Changed: " + clc.green(path)); | ||
}, | ||
browser: { | ||
reload: function () { | ||
return clc.yellow("Reloading all connected browsers..."); | ||
}, | ||
invalidBaseDir: function () { | ||
return clc.cyan("Invalid Base Directory path for server. ( baseDir: )\n\n") + | ||
clc.green("TIP: Don't use a forward slash at the beginning, and if you " + | ||
"want to serve files from the root folder, just set the baseDir option to './' "); | ||
}, | ||
fileWatching: function (numFiles) { | ||
if (numFiles === 1) { | ||
return "Watching 1 file"; | ||
} | ||
if (numFiles > 1) { | ||
return "Watching "+ numFiles + " files"; | ||
} | ||
return "Not watching any files..."; | ||
}, | ||
fileChanged: function (path) { | ||
return clc.magenta("File Changed: " + clc.green(path)); | ||
}, | ||
browser: { | ||
reload: function () { | ||
return clc.yellow("Reloading all connected browsers..."); | ||
}, | ||
inject: function () { | ||
return clc.yellow("Injecting file into all connected browsers..."); | ||
} | ||
}, | ||
location: function (url) { | ||
return clc.yellow("Link clicked! Redirecting all browser to " + clc.green(url)); | ||
}, | ||
socketConnector: function (host, port) { | ||
return "var ___socket___ = io.connect('" + host + ":" + port + "');"; | ||
}, | ||
clientScript: "/browser-sync-client.min.js", | ||
socketIoScript: "/socket.io/socket.io.js" | ||
inject: function () { | ||
return clc.yellow("Injecting file into all connected browsers..."); | ||
} | ||
}, | ||
location: function (url) { | ||
return clc.yellow("Link clicked! Redirecting all browser to " + clc.green(url)); | ||
}, | ||
socketConnector: function (host, port) { | ||
return "var ___socket___ = io.connect('" + host + ":" + port + "');"; | ||
}, | ||
clientScript: "/browser-sync-client.min.js", | ||
socketIoScript: "/socket.io/socket.io.js" | ||
}; |
{ | ||
"name": "browser-sync", | ||
"description": "Live CSS Reload & Browser Syncing", | ||
"version": "0.1.10", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/shakyshane/browser-sync", | ||
@@ -31,14 +31,14 @@ "author": { | ||
"portscanner": "~0.1.3", | ||
"path": "*", | ||
"url": "*", | ||
"open": "*", | ||
"chokidar": "~0.6.2", | ||
"path": "~0.4.9", | ||
"url": "~0.7.9", | ||
"open": "~0.0.4", | ||
"lodash": "~1.3.1", | ||
"cli-color": "~0.2.2", | ||
"socket.io": "~0.9.16", | ||
"connect": "~2.8.4", | ||
"connect": "~2.11.0", | ||
"ua-parser-js": "~0.6.2", | ||
"optimist": "0.6.0", | ||
"glob": "~3.2.6", | ||
"dev-ip": "~0.1.5" | ||
"glob": "~3.2.7", | ||
"dev-ip": "~0.1.5", | ||
"gaze": "~0.4.3" | ||
}, | ||
@@ -45,0 +45,0 @@ "devDependencies": { |
@@ -6,11 +6,2 @@ 'use strict'; | ||
var file1 = "test/fixtures/index.html"; | ||
var file2 = "test/fixtures/forms.html"; | ||
var file3 = "test/fixtures/scrolling.html"; | ||
var css = "test/fixtures/assets/style.css"; | ||
var scss = "test/fixtures/scss/main.scss"; | ||
var timeoutMsg = "Took too long to access DISK for files"; | ||
describe("Browser-sync: transform the files option into useable watchers", function () { | ||
@@ -22,21 +13,18 @@ | ||
describe("accepting a comma separated lists of files", function () { | ||
describe("accepting a comma separated lists of patterns (files)", function () { | ||
var files; | ||
var cb; | ||
beforeEach(function(){ | ||
cb = jasmine.createSpy(); | ||
beforeEach(function () { | ||
var arg = "test/fixtures/assets/style.css,test/fixtures/scss/main.scss"; | ||
files = setup.getFiles(arg); | ||
}); | ||
it("should return an array of files", function () { | ||
files = setup.getFiles("test/fixtures/assets/style.css,test/fixtures/scss/main.scss", cb); | ||
waits(100); | ||
runs(function () { | ||
expect(cb).toHaveBeenCalledWith([css, scss]); | ||
}); | ||
it("should return an array of patterns", function () { | ||
expect(files.length).toBe(2); | ||
}); | ||
it("should return an array of patterns (2)", function () { | ||
expect(files[0]).toBe("test/fixtures/assets/style.css"); | ||
}); | ||
it("should return an array of patterns (3)", function () { | ||
expect(files[1]).toBe("test/fixtures/scss/main.scss"); | ||
}); | ||
}); | ||
@@ -46,139 +34,63 @@ describe("accepting a comma separated lists of globs", function () { | ||
var files; | ||
var cb; | ||
beforeEach(function(){ | ||
cb = jasmine.createSpy(); | ||
var arg = "test/fixtures/assets/*.css,test/fixtures/scss/*.scss"; | ||
files = setup.getFiles(arg); | ||
}); | ||
it("should return an array of files", function () { | ||
files = setup.getFiles("test/fixtures/assets/*.css,test/fixtures/scss/*.scss", cb); | ||
waitsFor(function () { | ||
return cb.callCount > 0; | ||
}, timeoutMsg, 10000); | ||
runs(function () { | ||
expect(cb).toHaveBeenCalledWith([css, scss]); | ||
}); | ||
it("should return an array of file globs", function () { | ||
expect(files.length).toBe(2); | ||
}); | ||
it("should return an array of file globs (2)", function () { | ||
expect(files[0]).toBe("test/fixtures/assets/*.css"); | ||
}); | ||
it("should return an array of file globs (3)", function () { | ||
expect(files[1]).toBe("test/fixtures/scss/*.scss"); | ||
}); | ||
}); | ||
describe("When getting single files with a string", function () { | ||
describe("accepting a single pattern", function () { | ||
var files; | ||
var cb; | ||
var files, arg | ||
beforeEach(function(){ | ||
cb = jasmine.createSpy(); | ||
arg = "test/fixtures/assets/*.css"; | ||
files = setup.getFiles(arg); | ||
}); | ||
it("should return an array of files even if only 1 file", function () { | ||
files = setup.getFiles(file1, cb); | ||
waitsFor(function () { | ||
return cb.callCount > 0; | ||
}, timeoutMsg, 10000); | ||
runs(function () { | ||
expect(cb).toHaveBeenCalledWith([file1]); | ||
}); | ||
it("should return the pattern", function () { | ||
expect(files).toBe(arg); | ||
}); | ||
}); | ||
describe("accepting an array of patterns", function () { | ||
it("should return an array of files if an array given", function () { | ||
files = setup.getFiles([file1, file2], cb); | ||
waitsFor(function () { | ||
return cb.callCount > 0; | ||
}, timeoutMsg, 10000); | ||
runs(function () { | ||
expect(cb).toHaveBeenCalledWith([file1, file2]); | ||
}); | ||
var files, arg | ||
beforeEach(function(){ | ||
arg = ["**/*.css", "*.html"]; | ||
files = setup.getFiles(arg); | ||
}); | ||
it("should return the pattern", function () { | ||
expect(files).toBe(arg); | ||
}); | ||
}); | ||
describe("accepting an array of patterns (2)", function () { | ||
describe("when getting multiple files given as strings", function () { | ||
describe("When the files DO exist", function () { | ||
var files = [file1, file2]; | ||
var cb; | ||
beforeEach(function(){ | ||
cb = jasmine.createSpy("callback1"); | ||
}); | ||
it("should return an array of the files", function () { | ||
files = setup.getFiles(files, cb); | ||
waitsFor(function () { | ||
return cb.callCount > 0; | ||
}, timeoutMsg, 10000); | ||
runs(function () { | ||
expect(cb).toHaveBeenCalledWith([file1, file2]); | ||
}); | ||
}); | ||
var files, arg | ||
beforeEach(function(){ | ||
arg = ["**/*.css"]; | ||
files = setup.getFiles(arg); | ||
}); | ||
describe("When the files DO NOT exist", function () { | ||
// | ||
var files = ["test/fixtures/index.html", "test/fixtures/kittie.html"]; | ||
var cb; | ||
beforeEach(function(){ | ||
cb = jasmine.createSpy("callback1"); | ||
}); | ||
it("should return an array of the files", function () { | ||
files = setup.getFiles(files, cb); | ||
waitsFor(function () { | ||
return cb.callCount > 0; | ||
}, "Took too long", 10000); | ||
runs(function () { | ||
expect(cb).toHaveBeenCalledWith(["test/fixtures/index.html"]); | ||
}); | ||
}); | ||
it("should return the pattern", function () { | ||
expect(files).toBe(arg); | ||
}); | ||
}); | ||
describe("returning false if empty string given", function () { | ||
describe("Getting files from a glob", function () { | ||
var cb; | ||
var files; | ||
var files, arg; | ||
beforeEach(function(){ | ||
cb = jasmine.createSpy(); | ||
arg = ""; | ||
files = setup.getFiles(arg); | ||
}); | ||
it("should return files from a single glob string", function () { | ||
files = setup.getFiles("test/fixtures/*.html", cb); | ||
waitsFor(function () { | ||
return cb.callCount > 0; | ||
}, "Took too long to get files", 10000); | ||
runs(function () { | ||
expect(cb).toHaveBeenCalledWith([file2, file1, file3]); | ||
}); | ||
it("should return false", function () { | ||
expect(files).toBe(false); | ||
}); | ||
it("should return files from an array of globs", function () { | ||
files = setup.getFiles([ | ||
"test/fixtures/*.html", | ||
"test/fixtures/assets/*.css", | ||
"test/fixtures/scss/*.scss"], cb); | ||
waitsFor(function () { | ||
return cb.callCount > 0; | ||
}, "Took too long to get files!", 10000); | ||
runs(function () { | ||
expect(cb).toHaveBeenCalledWith([file2, file1, file3, css, scss]); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -27,20 +27,2 @@ var fs = require("fs"); | ||
it("should log a single file being watched", function () { | ||
methods.watchFiles(testFile1, io, methods.changeFile, {}); | ||
expect(methods.log).toHaveBeenCalledWith("Watching 1 file", {}, true); | ||
}); | ||
it("should log multiple files being watched", function () { | ||
methods.watchFiles([testFile1, testFile2], io, methods.changeFile, {}); | ||
expect(methods.log).toHaveBeenCalledWith("Watching 2 files", {}, true); | ||
}); | ||
it("should log when no files are watched", function () { | ||
methods.watchFiles([], io, methods.changeFile, {}); | ||
expect(methods.log).toHaveBeenCalledWith("Not watching any files...", {}, true); | ||
}); | ||
it("should call changeFile when a watched file is changed", function () { | ||
@@ -47,0 +29,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 3 instances in 1 package
0
108379
2441
+ Addedgaze@~0.4.3
+ Addedbytes@0.2.1(transitive)
+ Addedconnect@2.11.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddebug@0.8.1(transitive)
+ Addedgaze@0.4.3(transitive)
+ Addedglob@3.1.21(transitive)
+ Addedglobule@0.1.0(transitive)
+ Addedgraceful-fs@1.2.3(transitive)
+ Addedinherits@1.0.2(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedlodash@1.0.2(transitive)
+ Addedmethods@0.1.0(transitive)
+ Addedminimatch@0.2.14(transitive)
+ Addedmultiparty@2.2.0(transitive)
+ Addednegotiator@0.3.0(transitive)
+ Addedopen@0.0.5(transitive)
+ Addedpath@0.4.10(transitive)
+ Addedpunycode@1.0.0(transitive)
+ Addedquerystring@0.1.0(transitive)
+ Addedraw-body@1.1.2(transitive)
+ Addedreadable-stream@1.1.14(transitive)
+ Addedstream-counter@0.2.0(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addeduid2@0.0.3(transitive)
+ Addedurl@0.7.9(transitive)
- Removedchokidar@~0.6.2
- Removedbundle-name@4.1.0(transitive)
- Removedbytes@0.2.0(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedchokidar@0.6.3(transitive)
- Removedconnect@2.8.8(transitive)
- Removeddebug@4.3.7(transitive)
- Removeddefault-browser@5.2.1(transitive)
- Removeddefault-browser-id@5.0.0(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-lazy-prop@3.0.0(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedformidable@1.0.14(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinherits@2.0.3(transitive)
- Removedis-docker@3.0.0(transitive)
- Removedis-inside-container@1.0.0(transitive)
- Removedis-wsl@3.1.0(transitive)
- Removedmethods@0.0.1(transitive)
- Removedms@2.1.3(transitive)
- Removedobject-inspect@1.13.2(transitive)
- Removedopen@10.1.0(transitive)
- Removedpath@0.12.7(transitive)
- Removedprocess@0.11.10(transitive)
- Removedpunycode@1.4.1(transitive)
- Removedqs@6.13.0(transitive)
- Removedrun-applescript@7.0.0(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedside-channel@1.0.6(transitive)
- Removeduid2@0.0.2(transitive)
- Removedurl@0.11.4(transitive)
- Removedutil@0.10.4(transitive)
Updatedconnect@~2.11.0
Updatedglob@~3.2.7
Updatedopen@~0.0.4
Updatedpath@~0.4.9
Updatedurl@~0.7.9