UNPKG

legal-markdown-js

Version:

Node.js implementation of LegalMarkdown for processing legal documents with markdown and YAML - Complete feature parity with Ruby version

189 lines 6.12 kB
/** * CLI Service for Legal Markdown Processing * * This module provides a service class that handles the business logic for * the CLI tool, including file processing, output generation, error handling, * and user feedback. It coordinates between the core processing functions * and the command-line interface. * * Features: * - File and content processing orchestration * - Multi-format output generation (HTML, PDF, DOCX, Markdown) * - Error handling and user feedback * - Verbose logging and debugging support * - Path resolution and file system operations * - Flexible output options (file, stdout) * * @example * ```typescript * import { CliService } from './cli/service.js'; * * const service = new CliService({ * verbose: true, * pdf: true, * highlight: true * }); * * await service.processFile('input.md', 'output.md'); * ``` * * @module */ import { LegalMarkdownOptions } from '../types/index.js'; import { type PdfConnectorPreference } from '../extensions/generators/pdf-connectors/index.js'; /** * Extended options interface for CLI operations * * @interface CliOptions * @extends LegalMarkdownOptions */ export interface CliOptions extends LegalMarkdownOptions { /** Input file path */ input?: string; /** Output file path */ output?: string; /** Enable verbose logging */ verbose?: boolean; /** Suppress success output messages */ silent?: boolean; /** Generate PDF output */ pdf?: boolean; /** Generate HTML output */ html?: boolean; /** Generate DOCX output */ docx?: boolean; /** Enable field highlighting */ highlight?: boolean; /** Path to custom CSS file */ css?: string; /** Document title */ title?: string; /** Archive source file after successful processing */ archiveSource?: string | boolean; /** Write output to stdout instead of a file */ stdout?: boolean; /** Page format for PDF */ format?: 'A4' | 'Letter' | 'Legal'; /** Landscape orientation */ landscape?: boolean; pdfConnector?: PdfConnectorPreference; } /** * Service class for CLI operations and document processing * * Handles file processing, output generation, and error management * for the Legal Markdown CLI tool. * * @class CliService * @example * ```typescript * const service = new CliService({ * verbose: true, * pdf: true, * highlight: true * }); * ``` */ export declare class CliService { private options; /** * Creates a new CLI service instance * * @param {CliOptions} [options={}] - Configuration options */ constructor(options?: CliOptions); /** * Resolves output file path using environment variables for relative paths * * @param {string} outputPath - The output path to resolve * @returns {string} The resolved absolute output path * @private */ private resolveOutputPath; /** * Determines the output directory for generated files * * @param {string | undefined} outputPath - The output path (if provided) * @returns {string} The directory to use for output files * @private */ private getOutputDirectory; /** * Processes a file from input path to output path * * @param {string} inputPath - Path to the input file * @param {string} [outputPath] - Path for output file (optional for stdout) * @returns {Promise<void>} * @throws {FileNotFoundError} When input file doesn't exist * @throws {LegalMarkdownError} When processing fails */ processFile(inputPath: string, outputPath?: string): Promise<void>; /** * Processes content directly without file I/O * * @param {string} content - The content to process * @returns {Promise<string>} The processed content * @throws {LegalMarkdownError} When processing fails */ processContent(content: string): Promise<string>; /** * Logs messages with appropriate styling and prefixes * * @private * @param {string} message - The message to log * @param {'info' | 'success' | 'warn' | 'error'} [level='info'] - The log level * @returns {void} */ private log; /** * Generates formatted output (HTML/PDF/DOCX) using 3-phase pipeline * * This method uses the new 3-phase pipeline architecture: * - Phase 1: Build context (parse YAML, resolve force-commands) * - Phase 2: Process content ONCE (run remark pipeline, cache AST) * - Phase 3: Generate ALL formats from cached result (no re-processing) * * @private * @param {string} content - The content to format * @param {string} inputPath - Original input path for naming * @param {string} [outputPath] - Output path override * @returns {Promise<void>} */ private generateFormattedOutputWithOptions; /** * Show generated files with proper grouping and formatting * * @private * @param {string[]} files - Array of generated file paths * @param {boolean} hasHighlight - Whether highlight versions were generated */ private showGeneratedFiles; /** * Handle archiving of source file after successful processing * * @private * @param {string} inputPath - Path to the source file to archive * @param {string} originalContent - Original file content * @param {string} processedContent - Processed file content * @returns {Promise<void>} */ private handleArchiving; /** * Handles and formats errors for user display * * @private * @param {unknown} error - The error to handle * @returns {void} */ private handleError; /** * Process force commands from content and apply them to options * * @private * @param {string} content - The content to analyze for force commands * @param {Partial<CliOptions>} baseOptions - Base options to extend * @returns {Partial<CliOptions>} Updated options with force commands applied */ private processForceCommands; } //# sourceMappingURL=service.d.ts.map