'use strict';

var tslib = require('tslib');
var coreBackend = require('@cromwell/core-backend');
var webpack = require('webpack');
var yargs = require('yargs-parser');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var webpack__default = /*#__PURE__*/_interopDefaultLegacy(webpack);
var yargs__default = /*#__PURE__*/_interopDefaultLegacy(yargs);

var webpackConfig = require('../webpack.config');
var chalk = require('react-dev-utils/chalk');
var run = function () { return tslib.__awaiter(void 0, void 0, void 0, function () {
    var args, compiler;
    return tslib.__generator(this, function (_a) {
        args = yargs__default['default'](process.argv.slice(2));
        compiler = webpack__default['default'](webpackConfig);
        compiler.hooks.watchRun.tap('adminPanelStart', function () {
            console.log(chalk.cyan('\r\nBegin compile at ' + new Date() + '\r\n'));
        });
        compiler.hooks.done.tap('adminPanelDone', function () {
            setTimeout(function () {
                console.log(chalk.cyan('\r\nEnd compile at ' + new Date() + '\r\n'));
                if (process.send)
                    process.send(coreBackend.adminPanelMessages.onBuildEndMessage);
            }, 100);
        });
        if (args.watch)
            compiler.watch({}, function (err, stats) {
                console.log(stats === null || stats === void 0 ? void 0 : stats.toString({
                    chunks: false,
                    colors: true
                }));
            });
        else
            compiler.run(function (err, stats) {
                console.log(stats === null || stats === void 0 ? void 0 : stats.toString({
                    chunks: false,
                    colors: true
                }));
            });
        return [2 /*return*/];
    });
}); };
run();
