(getConfig: () => Config)
| 3 | import type { PreviewResult } from '../content/preview.ts'; |
| 4 | |
| 5 | export function previewCommand(getConfig: () => Config): Command { |
| 6 | return new Command('preview') |
| 7 | .description('Show what content the watcher will track (read-only)') |
| 8 | .action(async () => { |
| 9 | const { previewContent, formatPreviewBlock } = await import('../content/preview.ts'); |
| 10 | const config = getConfig(); |
| 11 | const cwd = process.cwd(); |
| 12 | const contentDir = resolveContentDir(config, cwd); |
| 13 | |
| 14 | let result: PreviewResult; |
| 15 | try { |
| 16 | result = previewContent({ |
| 17 | projectDir: cwd, |
| 18 | contentDir, |
| 19 | }); |
| 20 | } catch (e) { |
| 21 | console.error(`Content preview failed: ${e instanceof Error ? e.message : String(e)}`); |
| 22 | process.exitCode = 1; |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | process.stdout.write(`${formatPreviewBlock(result, cwd)}\n`); |
| 27 | |
| 28 | if (result.totalCount === 0 && result.warnings.length > 0) { |
| 29 | process.exitCode = 1; |
| 30 | } |
| 31 | }); |
| 32 | } |
no test coverage detected