init.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var _ = require("../lodash.custom");
  4. var cli_options_1 = require("../cli/cli-options");
  5. /**
  6. * @param {BrowserSync} browserSync
  7. * @param {String} [name] - instance name
  8. * @param {Object} pjson
  9. * @returns {Function}
  10. */
  11. module.exports = function (browserSync, name, pjson) {
  12. return function () {
  13. /**
  14. * Handle new + old signatures for init.
  15. */
  16. var args = require("../args")(_.toArray(arguments));
  17. /**
  18. * If the current instance is already running, just return an error
  19. */
  20. if (browserSync.active) {
  21. return args.cb(new Error("Instance: " + name + " is already running!"));
  22. }
  23. // Env specific items
  24. args.config.version = pjson.version;
  25. args.config.cwd = args.config.cwd || process.cwd();
  26. var _a = cli_options_1.merge(args.config), opts = _a[0], errors = _a[1];
  27. if (errors.length) {
  28. return args.cb(new Error(cli_options_1.printErrors(errors)));
  29. }
  30. return browserSync.init(opts, args.cb);
  31. };
  32. };
  33. //# sourceMappingURL=init.js.map