"use strict";
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = __importStar(require("path"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const os = __importStar(require("os"));
function getPaths(rootPath) {
    const outputPath = path.resolve(rootPath, './dist');
    const tempPath = path.resolve(rootPath, './.temp');
    const srcPath = path.resolve(rootPath, './src');
    /**
     * @desc temp
     */
    if (!fs_extra_1.default.existsSync(tempPath)) {
        fs_extra_1.default.mkdirSync(tempPath);
    }
    const autoRequireMetaTempPath = path.resolve(tempPath, './autoRequireMetaTemp.js');
    const autoRequireTempPath = path.resolve(tempPath, './autoRequireTemp.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');
    return {
        rootPath,
        srcPath,
        tempPath,
        outputPath,
        autoRequireTempPath,
        autoRequireMetaTempPath,
        metaTempPath,
        manifestPath,
        styleSchemaTempPath,
        styleSchemaPath,
        componentsMap: getComponentMap(srcPath),
        pluginsMap: getPluginsMap(srcPath),
        actionsMap: getActionsMap(srcPath),
        containersMap: getContainersMap(srcPath),
    };
}
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).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