"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.runWebpackCore = void 0;
const common_1 = require("../types/common");
const webpack_1 = require("../service/webpack");
const generate_1 = require("./generate");
async function runWebpackCore({ mainAppData, subAppDataList, appBuildDir, publicPath, mode = common_1.WebpackModeType.NONE, appKey, buildTypeList = [common_1.BuildType.WEB], mpConfig, assets = [], devTool = 'vite', generateMpType = common_1.GenerateMpType.APP, cdnEndpoints, }) {
    console.time('runWebpackCore');
    console.time('webpackGenerate');
    const allAppDataList = subAppDataList.concat(mainAppData);
    const webWebpackConfigPath = await (0, webpack_1.generateWebpackWebBuildParamsFile)({
        appId: mainAppData.id || appKey,
        allAppDataList,
        appBuildDir,
        publicPath,
        mode,
        buildTypeList,
        assets,
    });
    console.timeEnd('webpackGenerate');
    // compile
    console.time('generateMpJsonConfigFile');
    await (0, webpack_1.generateMpJsonConfigFile)(allAppDataList, mpConfig, appBuildDir, {
        appKey,
        generateMpType,
    });
    console.timeEnd('generateMpJsonConfigFile');
    await (0, generate_1.generateHTML)({
        appId: mainAppData.id || appKey,
        appBuildDir,
        jsApis: assets,
        mode,
        devTool,
        isBuildApp: buildTypeList.includes(common_1.BuildType.APP),
        buildTypeList,
        cdnEndpoints,
    });
    if ((0, common_1.buildAsWebByBuildType)(buildTypeList)) {
        if (mode !== common_1.WebpackModeType.PRODUCTION) {
            await (0, webpack_1.generateWebpackWebDevServerFile)({
                appBuildDir,
                buildTypeList,
            });
        }
    }
    console.timeEnd('runWebpackCore');
    return webWebpackConfigPath;
}
exports.runWebpackCore = runWebpackCore;
