"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 _pluginLibWebpackServe = _interopRequireDefault(require("@start/plugin-lib-webpack-serve"));

var _pluginEnv = _interopRequireDefault(require("@start/plugin-env"));

var _connectHistoryApiFallback = _interopRequireDefault(require("connect-history-api-fallback"));

var _pluginSequence = _interopRequireDefault(require("@start/plugin-sequence"));

var _webpack = require("../configs/webpack/webpack.plugins");

var _buildInfo = _interopRequireDefault(require("./plugins/buildInfo"));

var _createConfig = _interopRequireDefault(require("./plugins/createConfig"));

var _mergeTheme = _interopRequireDefault(require("./plugins/mergeTheme"));

/**
 * Run production build on local machine
 * @param force
 */
var _default = ({
  port,
  force,
  locals,
  theme = null
}) => {
  const webpackConfig = require('../configs/webpack/webpack.config.production');

  const {
    ROOT_PATH
  } = require('../configs/webpack/webpack.config');

  if (locals) {
    const regex = new RegExp(locals.join('|'));
    webpackConfig.plugins.push(new _webpack.ContextReplacementPlugin(/moment[/\\]locale$/, regex));
  }

  const convert = require('koa-connect');

  return (0, _pluginSequence.default)((0, _buildInfo.default)(['node'], {
    force
  }), (0, _pluginEnv.default)({
    THEME: theme
  }), (0, _mergeTheme.default)(theme), (0, _createConfig.default)(), (0, _pluginLibWebpackServe.default)({
    config: webpackConfig,
    hmr: false,
    reload: false,
    open: true,
    hotClient: false,
    port: port || 9000,
    content: ROOT_PATH,
    add: app => app.use(convert((0, _connectHistoryApiFallback.default)())),
    devMiddleware: {
      stats: {
        colors: true,
        hash: false,
        version: false,
        timings: false,
        assets: false,
        chunks: false,
        modules: false,
        reasons: false,
        children: false,
        source: false,
        errors: true,
        errorDetails: true,
        warnings: true,
        publicPath: false
      }
    }
  }));
};

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