UNPKG

@docfy/ember-vite

Version:

Vite plugin for Docfy Ember integration with @embroider/vite

66 lines (65 loc) 2.12 kB
import path from 'path'; import fastGlob from 'fast-glob'; import debugFactory from 'debug'; const debug = debugFactory('@docfy/ember-vite:utils'); /** * Check if a file should be processed by the plugin */ export function shouldProcessFile(filePath, docfyConfig, root) { if (!docfyConfig?.sources) return false; return docfyConfig.sources.some(source => { const sourceRoot = path.resolve(source.root || root); const resolvedFilePath = path.resolve(filePath); // Check if file is within source root if (!resolvedFilePath.startsWith(sourceRoot)) { return false; } // Simple pattern matching for .md files return filePath.endsWith('.md'); }); } /** * Get all Docfy source files using glob patterns */ export async function getDocfySourceFiles(docfyConfig, root) { if (!docfyConfig?.sources) return []; const allFiles = []; for (const source of docfyConfig.sources) { const sourceRoot = path.resolve(source.root || root); const pattern = source.pattern || '**/*.md'; const ignore = source.ignore || []; try { const files = await fastGlob(pattern, { cwd: sourceRoot, absolute: true, ignore: ['node_modules/**', ...ignore], }); allFiles.push(...files); debug('Found source files for pattern', { pattern, sourceRoot, fileCount: files.length, }); } catch (error) { debug('Error globbing files', { pattern, sourceRoot, error }); } } return allFiles; } /** * virtual docfy-output module template */ export function virtualDocfyOutputTemplate(docfyResult) { if (!docfyResult) { // Return empty structure when no result is available yet return `export default ${JSON.stringify({ nested: { name: '/', pages: [], children: [] }, })};`; } return `export default ${JSON.stringify({ nested: docfyResult.nestedPageMetadata, })};`; }