UNPKG

@openinc/parse-server-opendash

Version:
44 lines (43 loc) 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StructureBuilder = void 0; class StructureBuilder { static build(files, rootPath, defaultFolderConfig) { const root = { name: rootPath || "root", path: "", files: [], subfolders: new Map(), config: { ...defaultFolderConfig }, }; const configFiles = []; for (const file of files) { const pathParts = file.path.split("/"); // folder navigation (all but last segment) let current = root; for (let i = 0; i < pathParts.length - 1; i++) { const folderName = pathParts[i]; const folderPath = pathParts.slice(0, i + 1).join("/"); if (!current.subfolders.has(folderName)) { current.subfolders.set(folderName, { name: folderName, path: folderPath, files: [], subfolders: new Map(), config: { ...defaultFolderConfig }, }); } current = current.subfolders.get(folderName); } // classify file if (file.originalFilename === "config.json") { configFiles.push(file); } else if (file.extension === "md") { current.files.push(file); } } return { root, configFiles }; } } exports.StructureBuilder = StructureBuilder;