"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");

var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");

_Object$defineProperty(exports, "__esModule", {
  value: true
});

exports.default = void 0;

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));

var _plugin = _interopRequireDefault(require("@start/plugin"));

var _liveServer = _interopRequireDefault(require("live-server"));

var _default = ({
  port,
  root
}) => (0, _plugin.default)('SERVE APP', ({
  reporter
}) =>
/*#__PURE__*/
(0, _asyncToGenerator2.default)(function* () {
  _liveServer.default.start({
    port: port,
    // Set the server port. Defaults to 8080.
    root: root,
    // Set root directory that's being served. Defaults to cwd.
    open: false,
    host: 'localhost',
    // Set the address to bind to. Defaults to 0.0.0.0 or process.env.IP.
    file: 'index.html',
    // When set, serve this file (server root relative) for every 404 (useful for single-page applications)
    mount: [],
    logLevel: 2 // 0 = errors only, 1 = some, 2 = lots

  });

  const exitHandler = () => {
    reporter.emit('message', 'Shutting down server');

    _liveServer.default.shutdown();
  }; //do something when app is closing


  process.on('exit', exitHandler); //catches ctrl+c event

  process.on('SIGINT', exitHandler); //catches uncaught exceptions

  process.on('uncaughtException', exitHandler);
}));

exports.default = _default;
module.exports = exports.default;