"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.postprocessDeployExtraJson = exports.postprocessProjectConfig = void 0;
const fs_extra_1 = __importDefault(require("fs-extra"));
const lodash_1 = require("lodash");
const path_1 = __importDefault(require("path"));
function postprocessProjectConfig(projectJsonPath, data) {
    let projectJson = fs_extra_1.default.readJsonSync(projectJsonPath);
    fs_extra_1.default.writeJsonSync(projectJsonPath, (0, lodash_1.merge)(projectJson, data), { spaces: 2 });
}
exports.postprocessProjectConfig = postprocessProjectConfig;
function postprocessDeployExtraJson(projectPath, deployOptions) {
    let { targetMpAppId, mpAppId } = deployOptions;
    if (targetMpAppId !== mpAppId) {
        let projectJson = fs_extra_1.default.readJsonSync(path_1.default.resolve(projectPath, 'project.config.json'));
        const miniprogramRoot = (projectJson === null || projectJson === void 0 ? void 0 : projectJson.miniprogramRoot) || './';
        fs_extra_1.default.writeFileSync(path_1.default.resolve(projectPath, miniprogramRoot, 'ext.json'), JSON.stringify({
            extEnable: true,
            extAppid: targetMpAppId,
            directCommit: true,
        }, null, 2));
    }
}
exports.postprocessDeployExtraJson = postprocessDeployExtraJson;
