"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_extra_1 = __importDefault(require("fs-extra"));
const path = __importStar(require("path"));
const util_1 = require("../../util");
function writeTempFile(paths) {
    fs_extra_1.default.writeFileSync(paths.metaTempPath, getMetaDeclare(paths));
}
exports.writeTempFile = writeTempFile;
function getMetaDeclare(paths) {
    const { componentsMap, pluginsMap, actionsMap } = paths;
    const components = Object.entries(componentsMap)
        .map(([name, entry]) => `{ path: '${name}', info: require('${util_1.handlePathEscape(path.resolve(entry, './config.js'))}').default.info }`)
        .join(',\n');
    const plugins = Object.entries(pluginsMap)
        .map(([name, entry]) => `{ path: '${name}', info: require('${util_1.handlePathEscape(path.resolve(entry, './config.js'))}').default.info }`)
        .join(',\n');
    const actions = Object.entries(actionsMap)
        .map(([name, entry]) => `{ path: '${name}', info: require('${util_1.handlePathEscape(path.resolve(entry, './config.js'))}').default.info }`)
        .join(',\n');
    return `module.exports = { "components": [${components}],\
   "plugins": [${plugins}], "actions": [${actions}] }`;
}
function generateMeta(paths) {
    const { manifestPath, tempPath, outputPath } = paths;
    const manifest = JSON.parse(fs_extra_1.default.readFileSync(manifestPath, { encoding: 'utf8' }));
    const metaTempPath = path.resolve(tempPath, 'meta.js');
    const metaTemp = `require = () => {};\n${fs_extra_1.default.readFileSync(metaTempPath, {
        encoding: 'utf8',
    })}`;
    fs_extra_1.default.writeFileSync(metaTempPath, metaTemp, { encoding: 'utf8' });
    manifest.styleSchema = 'styleSchema.js';
    const meta = Object.assign({ manifest }, require(metaTempPath));
    fs_extra_1.default.writeFileSync(path.join(outputPath, './meta.json'), JSON.stringify(meta, undefined, 2));
    fs_extra_1.default.unlinkSync(manifestPath);
}
exports.generateMeta = generateMeta;
//# sourceMappingURL=generateMeta.js.map