'use strict';

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);

const webpackConfig = require('../webpack.config');
const chalk = require('react-dev-utils/chalk');
const run = async () => {
    const args = yargs__default['default'](process.argv.slice(2));
    const compiler = webpack__default['default'](webpackConfig);
    compiler.hooks.watchRun.tap('adminPanelStart', () => {
        console.log(chalk.cyan('\r\nBegin compile at ' + new Date() + '\r\n'));
    });
    compiler.hooks.done.tap('adminPanelDone', () => {
        setTimeout(() => {
            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({}, (err, stats) => {
            console.log(stats === null || stats === void 0 ? void 0 : stats.toString({
                chunks: false,
                colors: true
            }));
        });
    else
        compiler.run((err, stats) => {
            console.log(stats === null || stats === void 0 ? void 0 : stats.toString({
                chunks: false,
                colors: true
            }));
        });
};
run();
