"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 os = __importStar(require("os"));
const path = __importStar(require("path"));
function getPaths(rootPath) {
    const outputPath = path.resolve(rootPath, './dist');
    const tempPath = path.resolve(rootPath, './.temp');
    const srcPath = path.resolve(rootPath, './src');
    const staticPath = path.resolve(__dirname, '../../static');
    const editorPath = path.resolve(staticPath, './editor');
    /**
     * @desc temp
     */
    if (!fs_extra_1.default.existsSync(tempPath)) {
        fs_extra_1.default.mkdirSync(tempPath);
    }
    const autoRequireMetaTempPath = path.resolve(tempPath, './autoRequireMetaTemp.js');
    const autoRequireMetaH5TempPath = path.resolve(tempPath, './autoRequireMetaTemp.h5.js');
    const autoRequireMetaPCTempPath = path.resolve(tempPath, './autoRequireMetaTemp.pc.js');
    const autoRequireTempPath = path.resolve(tempPath, './autoRequireTemp.js');
    const autoRequireTempH5Path = path.resolve(tempPath, './autoRequireTemp.h5.js');
    const autoRequireTempPCPath = path.resolve(tempPath, './autoRequireTemp.pc.js');
    const metaTempPath = path.resolve(tempPath, './metaTemp.js');
    const manifestPath = path.resolve(outputPath, './manifest.json');
    const styleSchemaTempPath = path.resolve(tempPath, './styleSchemaTemp.js');
    const styleSchemaPath = path.resolve(tempPath, './styleSchema.js');
    const webpackConfigPath = path.resolve(rootPath, './webpack');
    const { libName } = require(path.resolve(rootPath, 'package.json'));
    return {
        libName,
        rootPath,
        srcPath,
        staticPath,
        editorPath,
        tempPath,
        outputPath,
        autoRequireTempPath,
        autoRequireTempH5Path,
        autoRequireTempPCPath,
        autoRequireMetaTempPath,
        autoRequireMetaTempH5Path: autoRequireMetaH5TempPath,
        autoRequireMetaTempPCPath: autoRequireMetaPCTempPath,
        metaTempPath,
        manifestPath,
        styleSchemaTempPath,
        styleSchemaPath,
        webpackConfigPath,
        modulesPath: path.resolve(rootPath, './node_modules'),
        componentsMap: getComponentMap(srcPath),
        pluginsMap: getPluginsMap(srcPath),
        actionsMap: getActionsMap(srcPath),
        containersMap: getContainersMap(srcPath),
        webpackConfigMap: {
            pageDev: path.resolve(webpackConfigPath, './dev.js'),
            pageProd: path.resolve(webpackConfigPath, './prod.js'),
            libDev: path.resolve(webpackConfigPath, './dev.lib.js'),
            libProd: path.resolve(webpackConfigPath, './prod.lib.js'),
        },
    };
}
exports.getPaths = getPaths;
function getComponentMap(srcPath) {
    const componentsPath = path.join(srcPath, 'components');
    if (!fs_extra_1.default.existsSync(componentsPath)) {
        fs_extra_1.default.mkdirSync(componentsPath);
    }
    return fs_extra_1.default.readdirSync(componentsPath).reduce((componentsMap, name) => {
        const folder = path.join(componentsPath, name.toString());
        if (fs_extra_1.default.lstatSync(folder).isDirectory()) {
            componentsMap[name] = folder;
        }
        return componentsMap;
    }, {});
}
function getPluginsMap(srcPath) {
    const pluginsPath = path.join(srcPath, 'plugins');
    if (!fs_extra_1.default.existsSync(pluginsPath)) {
        fs_extra_1.default.mkdirSync(pluginsPath);
    }
    return fs_extra_1.default.readdirSync(pluginsPath).reduce((pluginsMap, name) => {
        const folder = path.join(pluginsPath, name.toString());
        if (fs_extra_1.default.lstatSync(folder).isDirectory()) {
            pluginsMap[name] = folder;
        }
        return pluginsMap;
    }, {});
}
function getActionsMap(srcPath) {
    const actionsPath = path.join(srcPath, 'actions');
    if (!fs_extra_1.default.existsSync(actionsPath)) {
        fs_extra_1.default.mkdirSync(actionsPath);
    }
    return fs_extra_1.default.readdirSync(actionsPath).reduce((actionsMap, name) => {
        const folder = path.join(actionsPath, name.toString());
        if (fs_extra_1.default.lstatSync(folder).isDirectory()) {
            actionsMap[name] = folder;
        }
        return actionsMap;
    }, {});
}
function getContainersMap(srcPath) {
    const containersPath = path.join(srcPath, 'containers');
    if (!fs_extra_1.default.existsSync(containersPath)) {
        fs_extra_1.default.mkdirSync(containersPath);
    }
    return fs_extra_1.default
        .readdirSync(containersPath)
        .filter(v => v !== '.DS_Store')
        .reduce((actionsMap, name) => {
        const ejs = path.join(containersPath, name.toString());
        if (fs_extra_1.default.existsSync(ejs)) {
            actionsMap[name] = ejs;
        }
        return actionsMap;
    }, {});
}
function handlePathEscape(path) {
    if (os.platform() !== 'win32') {
        return path;
    }
    return path.replace(/\\/g, '\\\\');
}
exports.handlePathEscape = handlePathEscape;
//# sourceMappingURL=path.js.map