# add dist

This commit is contained in:
Mario Romano
2016-04-21 11:56:31 +01:00
parent 5914688467
commit 07807e7bc3
13499 changed files with 1808930 additions and 5 deletions

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.

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

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');
}

View File

@@ -0,0 +1,116 @@
{
"_args": [
[
"browser-sync-client@^2.3.3",
"/Users/mromano/dev/dev-platform-webcomponents/ng2-components/ng2-alfresco-documentslist/node_modules/browser-sync"
]
],
"_from": "browser-sync-client@>=2.3.3 <3.0.0",
"_id": "browser-sync-client@2.4.2",
"_inCache": true,
"_installable": true,
"_location": "/browser-sync-client",
"_nodeVersion": "4.2.2",
"_npmOperationalInternal": {
"host": "packages-16-east.internal.npmjs.com",
"tmp": "tmp/browser-sync-client-2.4.2.tgz_1460319012213_0.6915903650224209"
},
"_npmUser": {
"email": "shakyshane@gmail.com",
"name": "shakyshane"
},
"_npmVersion": "2.14.7",
"_phantomChildren": {},
"_requested": {
"name": "browser-sync-client",
"raw": "browser-sync-client@^2.3.3",
"rawSpec": "^2.3.3",
"scope": null,
"spec": ">=2.3.3 <3.0.0",
"type": "range"
},
"_requiredBy": [
"/browser-sync"
],
"_resolved": "https://registry.npmjs.org/browser-sync-client/-/browser-sync-client-2.4.2.tgz",
"_shasum": "0c510d4183c0b5dbc4044363facc3a4273f7ba28",
"_shrinkwrap": null,
"_spec": "browser-sync-client@^2.3.3",
"_where": "/Users/mromano/dev/dev-platform-webcomponents/ng2-components/ng2-alfresco-documentslist/node_modules/browser-sync",
"author": {
"email": "shane.osbourne8@gmail.com",
"name": "Shane Osbourne"
},
"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",
"express": "^4.12.3",
"gulp": "^3.8.11",
"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",
"sinon": "~1.8.2",
"supertest": "^0.10.0",
"through2": "^0.4.1",
"vinyl-source-stream": "^1.1.0"
},
"directories": {},
"dist": {
"shasum": "0c510d4183c0b5dbc4044363facc3a4273f7ba28",
"tarball": "https://registry.npmjs.org/browser-sync-client/-/browser-sync-client-2.4.2.tgz"
},
"engines": {
"node": ">= 0.8.0"
},
"files": [
"dist",
"index.js"
],
"gitHead": "b53c6446d53773243100614217d85462a769d166",
"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": [
{
"email": "shane.osbourne8@gmail.com",
"name": "shakyshane"
}
],
"name": "browser-sync-client",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git://github.com/shakyshane/browser-sync-client.git"
},
"scripts": {
"karma": "karma start test/karma.conf.ci.js",
"mocha": "mocha test/middleware",
"test": "gulp && npm run mocha && npm run karma"
},
"version": "2.4.2"
}