"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.startCompile = void 0;
const cross_spawn_1 = __importDefault(require("cross-spawn"));
const runningCompilations = {};
function startCompile(options, cb) {
    const key = options.configPath;
    const runningProcess = runningCompilations[key];
    if (runningProcess) {
        console.log(`Compiling ${options.configPath} already running`);
        return;
    }
    console.log('Running webpack by ' + options.configPath);
    console.log('Running webpack mode ', options.webpackMode);
    // if (options.webpackMode === WebpackModeType.PRODUCTION) {
    try {
        console.log('【编译中】正在进行生产环境编译，请稍等...');
        let startTime = Date.now();
        runningCompilations[key] = true;
        cross_spawn_1.default.sync('npm', ['run', 'build-web'], {
            cwd: options.appBuildDir,
            env: process.env,
            stdio: 'inherit',
        });
        cb === null || cb === void 0 ? void 0 : cb(null, {
            outDir: options.appBuildDir,
            timeElapsed: Date.now() - startTime,
        });
    }
    catch (e) {
        cb === null || cb === void 0 ? void 0 : cb([e]);
        console.error('【失败】编译失败，请查看上面的日志修改后重试');
    }
    runningCompilations[key] = false;
    // }
}
exports.startCompile = startCompile;
