UNPKG

@mdfriday/foundry

Version:

The core engine of MDFriday. Convert Markdown and shortcodes into fully themed static sites – Hugo-style, powered by TypeScript.

169 lines 6.96 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.FilesystemsCollector = exports.RootMapping = void 0; exports.newFilesystemsCollector = newFilesystemsCollector; const overlayfs_factory_1 = require("./overlayfs-factory"); const basefs_1 = require("../entity/basefs"); const path = __importStar(require("path")); const log_1 = require("../../../../pkg/log"); // Create domain-specific logger for fs operations const log = (0, log_1.getDomainLogger)('fs', { component: 'filesystemscollector' }); /** * RootMapping represents a filesystem mount mapping * TypeScript version of Go's RootMapping */ class RootMapping { constructor(from, to, toBase = '') { this.from = from; this.to = to; this.toBase = toBase; } /** * Create a filesystem for this mapping */ fs(sourceProject) { // Use BasePathFs pointing to the target path (like Go version) return (0, basefs_1.newBaseFs)(sourceProject, [this.to]); } } exports.RootMapping = RootMapping; /** * FilesystemsCollector value object * TypeScript version of Go's FilesystemsCollector */ class FilesystemsCollector { constructor(sourceProject) { this.sourceProject = sourceProject; this.overlayMountsPrompt = (0, overlayfs_factory_1.createReadOnlyOverlayFs)([]); this.overlayMountsWorkflow = (0, overlayfs_factory_1.createReadOnlyOverlayFs)([]); this.overlayMountsContent = (0, overlayfs_factory_1.createReadOnlyOverlayFs)([]); this.overlayMountsLayouts = (0, overlayfs_factory_1.createReadOnlyOverlayFs)([]); this.overlayMountsStatics = (0, overlayfs_factory_1.createReadOnlyOverlayFs)([]); this.overlayMountsAssets = (0, overlayfs_factory_1.createReadOnlyOverlayFs)([]); } /** * Collect filesystem mounts from modules */ async collect(mods) { const allModules = mods.all(); for (const md of allModules) { const fromToWorkflow = []; const fromToPrompt = []; const fromToContent = []; const fromToLayouts = []; const fromToStatics = []; const fromToAssets = []; const absPathify = (inputPath) => { if (path.isAbsolute(inputPath)) { return ['', inputPath]; } return [md.dir(), this.absPathify(md.dir(), inputPath)]; }; const mounts = md.mounts(); for (const mount of mounts) { const [base, absFilename] = absPathify(mount.source()); const rm = new RootMapping(mount.target(), absFilename, base); const fs = rm.fs(this.sourceProject); if (this.isPrompts(mount.target())) { fromToPrompt.push(fs); } else if (this.isWorkflows(mount.target())) { fromToWorkflow.push(fs); } else if (this.isContent(mount.target())) { fromToContent.push(fs); } else if (this.isLayouts(mount.target())) { fromToLayouts.push(fs); } else if (this.isStatics(mount.target())) { fromToStatics.push(fs); } else if (this.isAssets(mount.target())) { fromToAssets.push(fs); } } // Append new filesystems to existing overlays if (fromToWorkflow.length > 0) { this.overlayMountsWorkflow = this.overlayMountsWorkflow.append(...fromToWorkflow); } if (fromToPrompt.length > 0) { this.overlayMountsPrompt = this.overlayMountsPrompt.append(...fromToPrompt); } if (fromToContent.length > 0) { this.overlayMountsContent = this.overlayMountsContent.append(...fromToContent); } if (fromToLayouts.length > 0) { this.overlayMountsLayouts = this.overlayMountsLayouts.append(...fromToLayouts); } if (fromToStatics.length > 0) { this.overlayMountsStatics = this.overlayMountsStatics.append(...fromToStatics); } if (fromToAssets.length > 0) { this.overlayMountsAssets = this.overlayMountsAssets.append(...fromToAssets); } } } isPrompts(target) { return target === 'prompts' || target.startsWith('prompts/') || target.startsWith('/prompts/'); } isWorkflows(target) { return target === 'workflows' || target.startsWith('workflows/') || target.startsWith('/workflows/'); } isContent(target) { return target === 'content' || target.startsWith('content/') || target.startsWith('/content/'); } isLayouts(target) { return target === 'layouts' || target.startsWith('layouts/') || target.startsWith('/layouts/'); } isStatics(target) { return target === 'static' || target.startsWith('static/') || target.startsWith('/static/'); } isAssets(target) { return target === 'assets' || target.startsWith('assets/') || target.startsWith('/assets/'); } absPathify(baseDir, relativePath) { return path.resolve(baseDir, relativePath); } } exports.FilesystemsCollector = FilesystemsCollector; /** * Create new FilesystemsCollector */ function newFilesystemsCollector(sourceProject) { return new FilesystemsCollector(sourceProject); } //# sourceMappingURL=filesystemscollector.js.map