This commit is contained in:
chrosey
2017-09-13 07:52:34 +02:00
parent a1f16c37f4
commit 2340b0226b
24621 changed files with 2912161 additions and 149 deletions
+19
View File
@@ -0,0 +1,19 @@
# browser-sync-client [![Build Status](https://travis-ci.org/BrowserSync/browser-sync-client.svg)](https://travis-ci.org/BrowserSync/browser-sync-client)
Client-side script for BrowserSync
## Contributors
```
177 Shane Osbourne
2 Sergey Slipchenko
1 Hugo Dias
1 Shinnosuke Watanabe
1 Tim Schaub
1 Shane Daniel
1 Matthieu Vachon
```
## License
Copyright (c) 2014 Shane Osbourne
Licensed under the MIT license.
View File
+1951
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+144
View File
@@ -0,0 +1,144 @@
"use strict";
var etag = require("etag");
var fresh = require("fresh");
var fs = require("fs");
var path = require("path");
var zlib = require("zlib");
var minifiedScript = path.join(__dirname, "/dist/index.min.js");
var unminifiedScript = path.join(__dirname, "/dist/index.js");
/**
* Does the current request support compressed encoding?
* @param {Object} req
* @returns {boolean}
*/
function supportsGzip (req) {
var accept = req.headers['accept-encoding'];
return accept && accept.indexOf('gzip') > -1;
}
/**
* Set headers on the response
* @param {Object} res
* @param {String} body
*/
function setHeaders(res, body) {
res.setHeader("Cache-Control", "public, max-age=0");
res.setHeader("Content-Type", "text/javascript");
res.setHeader("ETag", etag(body));
}
/**
* @param {Object} options
* @param {String} connector
* @returns {String}
*/
function getScriptBody(options, connector) {
var script = minifiedScript;
if (options && !options.minify) {
script = unminifiedScript;
}
return connector + fs.readFileSync(script);
}
/**
* @param {Object} req
* @returns {String}
*/
function isConditionalGet(req) {
return req.headers["if-none-match"] || req.headers["if-modified-since"];
}
/**
* Return a not-modified response
* @param {Object} res
*/
function notModified(res) {
res.removeHeader("Content-Type");
res.statusCode = 304;
res.end();
}
/**
* Public method for returning either a middleware fn
* or the content as a string
* @param {Object} options
* @param {String} connector - content to be prepended
* @param {String} type - either `file` or `middleware`
* @returns {*}
*/
function init(options, connector, type) {
var gzipCached;
/**
* Combine string to create the final version
* @type {String}
*/
var requestBody = getScriptBody(options, connector);
/**
* If the user asked for a file, simply return the string.
*/
if (type && type === "file") {
return requestBody;
}
/**
* Otherwise return a function to be used a middleware
*/
return function (req, res) {
/**
* default to using the uncompressed string
* @type {String}
*/
var output = requestBody;
/**
* Set the appropriate headers for caching
*/
setHeaders(res, output);
if (isConditionalGet(req) && fresh(req.headers, res._headers)) {
return notModified(res);
}
/**
* If gzip is supported, compress the string once
* and save for future requests
*/
if (supportsGzip(req)) {
res.setHeader("Content-Encoding", "gzip");
if (!gzipCached) {
var buf = new Buffer(output, "utf-8");
zlib.gzip(buf, function (_, result) {
gzipCached = result;
res.end(result);
});
} else {
res.end(gzipCached);
}
} else {
res.end(output);
}
};
}
module.exports.middleware = init;
module.exports.plugin = init;
module.exports.minified = function () {
return fs.readFileSync(minifiedScript, 'utf8');
};
module.exports.unminified = function () {
return fs.readFileSync(unminifiedScript, 'utf8');
}
+126
View File
@@ -0,0 +1,126 @@
{
"_args": [
[
{
"raw": "browser-sync-client@2.5.1",
"scope": null,
"escapedName": "browser-sync-client",
"name": "browser-sync-client",
"rawSpec": "2.5.1",
"spec": "2.5.1",
"type": "version"
},
"c:\\xampp\\htdocs\\laravel\\node_modules\\browser-sync"
]
],
"_from": "browser-sync-client@2.5.1",
"_id": "browser-sync-client@2.5.1",
"_inCache": true,
"_location": "/browser-sync-client",
"_nodeVersion": "6.10.1",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/browser-sync-client-2.5.1.tgz_1495357338080_0.24074852792546153"
},
"_npmUser": {
"name": "shakyshane",
"email": "shakyshane@gmail.com"
},
"_npmVersion": "3.10.10",
"_phantomChildren": {},
"_requested": {
"raw": "browser-sync-client@2.5.1",
"scope": null,
"escapedName": "browser-sync-client",
"name": "browser-sync-client",
"rawSpec": "2.5.1",
"spec": "2.5.1",
"type": "version"
},
"_requiredBy": [
"/browser-sync"
],
"_resolved": "https://registry.npmjs.org/browser-sync-client/-/browser-sync-client-2.5.1.tgz",
"_shasum": "ec1ad69a49c2e2d4b645b18b1c06c29b3d9af8eb",
"_shrinkwrap": null,
"_spec": "browser-sync-client@2.5.1",
"_where": "c:\\xampp\\htdocs\\laravel\\node_modules\\browser-sync",
"author": {
"name": "Shane Osbourne",
"email": "shane.osbourne8@gmail.com"
},
"bugs": {
"url": "https://github.com/shakyshane/browser-sync-client/issues"
},
"dependencies": {
"etag": "^1.7.0",
"fresh": "^0.3.0"
},
"description": "Client-side scripts for BrowserSync",
"devDependencies": {
"browser-sync": "^2.9.11",
"browserify": "^11.2.0",
"chai": "~1.9.0",
"crossbow": "latest",
"express": "^4.12.3",
"gulp-contribs": "0.0.2",
"gulp-jshint": "~1.4.0",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^0.2.1",
"karma": "^0.13.15",
"karma-chrome-launcher": "^0.1.3",
"karma-coverage": "^0.2.1",
"karma-firefox-launcher": "^0.1.4",
"karma-html2js-preprocessor": "^0.1.0",
"karma-mocha": "~0.1.1",
"karma-sinon": "~1.0.0",
"mocha": "^1.18.2",
"nodemon": "^1.11.0",
"sinon": "~1.8.2",
"supertest": "^0.10.0",
"through2": "^0.4.1",
"vinyl-fs": "^2.4.4",
"vinyl-source-stream": "^1.1.0"
},
"directories": {},
"dist": {
"shasum": "ec1ad69a49c2e2d4b645b18b1c06c29b3d9af8eb",
"tarball": "https://registry.npmjs.org/browser-sync-client/-/browser-sync-client-2.5.1.tgz"
},
"engines": {
"node": ">=4.0.0"
},
"files": [
"dist",
"index.js"
],
"gitHead": "702fa68743c6d8123ab2fa1e75dd133eca090be9",
"homepage": "https://github.com/shakyshane/browser-sync-client",
"keywords": [],
"licenses": [
{
"type": "MIT",
"url": "https://github.com/shakyshane/browser-sync-client/blob/master/LICENSE-MIT"
}
],
"main": "index.js",
"maintainers": [
{
"name": "shakyshane",
"email": "shane.osbourne8@gmail.com"
}
],
"name": "browser-sync-client",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git://github.com/shakyshane/browser-sync-client.git"
},
"scripts": {
"prepublish": "cb run default",
"start": "cb dev",
"test": "cb test"
},
"version": "2.5.1"
}