index.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. var UI = require("./lib/UI");
  3. var config = require("./lib/config");
  4. var Events = require("events").EventEmitter;
  5. /**
  6. * Hooks are for attaching functionality to BrowserSync
  7. */
  8. module.exports.hooks = {
  9. /**
  10. * Client JS is added to each connected client
  11. */
  12. "client:js": fileContent(config.defaults.clientJs)
  13. };
  14. /**
  15. * BrowserSync Plugin interface
  16. * @param {Object} opts
  17. * @param {BrowserSync} bs
  18. * @param {Function} cb
  19. * @returns {UI}
  20. */
  21. module.exports["plugin"] = function (opts, bs, cb) {
  22. var ui = new UI(opts, bs, new Events());
  23. bs.setOption("session", new Date().getTime());
  24. ui.cb = cb || function () { /*noop*/ };
  25. ui.init();
  26. return ui;
  27. };
  28. module.exports["plugin:name"] = config.defaults.pluginName;
  29. /**
  30. * @param filepath
  31. * @returns {*}
  32. */
  33. function getPath (filepath) {
  34. return require("path").join(__dirname, filepath);
  35. }
  36. /**
  37. * @param filepath
  38. * @returns {*}
  39. */
  40. function fileContent (filepath) {
  41. return require("fs").readFileSync(getPath(filepath));
  42. }