Add Docstrings
This commit is contained in:
17 files changed
+5380
-177
No files matched your search
@@ -1,11 +1,29 @@
|
||||
/**
|
||||
* Dependency checking utilities for Obsidian Typst PDF Export plugin
|
||||
* Dependency checking utilities for Obsidian Typst PDF Export plugin.
|
||||
*
|
||||
* This module provides comprehensive dependency checking for the three external
|
||||
* tools required by the plugin:
|
||||
* - Pandoc: Converts Markdown to Typst markup
|
||||
* - Typst: Compiles Typst markup to PDF
|
||||
* - ImageMagick: Handles PDF-to-image conversion for embedded PDFs (optional)
|
||||
*
|
||||
* The module offers both async and sync checking methods, automatic startup
|
||||
* validation, and user-facing status display functionality.
|
||||
*/
|
||||
|
||||
import { DEPENDENCY_CONSTANTS } from './constants';
|
||||
import { ExportErrorHandler } from './ExportErrorHandler';
|
||||
import { ExecutableChecker, DependencyInfo } from './ExecutableChecker';
|
||||
|
||||
/**
|
||||
* Complete result of a dependency check operation.
|
||||
*
|
||||
* @property pandoc - Detailed information about Pandoc installation
|
||||
* @property typst - Detailed information about Typst installation
|
||||
* @property imagemagick - Detailed information about ImageMagick installation
|
||||
* @property allAvailable - True if all dependencies are available
|
||||
* @property missingDependencies - Array of names of missing dependencies
|
||||
*/
|
||||
export interface DependencyCheckResult {
|
||||
pandoc: DependencyInfo;
|
||||
typst: DependencyInfo;
|
||||
@@ -14,6 +32,46 @@ export interface DependencyCheckResult {
|
||||
missingDependencies: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Utilities for checking external dependency availability and versions.
|
||||
*
|
||||
* This class provides static methods for validating that Pandoc, Typst, and
|
||||
* ImageMagick are properly installed and accessible. It supports both async
|
||||
* and sync operations, configurable executable paths, and user notifications.
|
||||
*
|
||||
* Key features:
|
||||
* - Comprehensive async checking with version detection
|
||||
* - Fast sync checking for startup validation
|
||||
* - User-facing status display with formatted output
|
||||
* - Silent background checking with error notifications
|
||||
* - Support for custom executable paths and search directories
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Comprehensive check with version information
|
||||
* const result = await DependencyChecker.checkAllDependencies(
|
||||
* settings.pandocPath,
|
||||
* settings.typstPath,
|
||||
* settings.imagemagickPath,
|
||||
* settings.additionalPaths
|
||||
* );
|
||||
*
|
||||
* if (!result.allAvailable) {
|
||||
* console.error('Missing:', result.missingDependencies);
|
||||
* } else {
|
||||
* console.log(`Pandoc ${result.pandoc.version} found`);
|
||||
* }
|
||||
*
|
||||
* // Quick startup check
|
||||
* const missing = DependencyChecker.checkDependenciesSync(
|
||||
* settings.pandocPath,
|
||||
* settings.typstPath
|
||||
* );
|
||||
* if (missing.length > 0) {
|
||||
* console.error('Missing dependencies:', missing);
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
export class DependencyChecker {
|
||||
|
||||
|
||||
@@ -23,7 +81,51 @@ export class DependencyChecker {
|
||||
|
||||
|
||||
/**
|
||||
* Comprehensive dependency check (async) - returns detailed information
|
||||
* Performs comprehensive dependency checking with version detection (async).
|
||||
*
|
||||
* This method checks all three required external tools (Pandoc, Typst, and
|
||||
* ImageMagick) in parallel for maximum efficiency. It resolves executable
|
||||
* paths, verifies availability, and extracts version information using regex
|
||||
* patterns.
|
||||
*
|
||||
* The method supports custom executable paths from user settings and falls
|
||||
* back to searching system PATH if paths are not specified. Additional search
|
||||
* directories can be provided to help locate tools in non-standard locations.
|
||||
*
|
||||
* @param pandocPath - Optional custom path to Pandoc executable
|
||||
* @param typstPath - Optional custom path to Typst executable
|
||||
* @param imagemagickPath - Optional custom path to ImageMagick convert executable
|
||||
* @param additionalPaths - Additional directories to search for executables
|
||||
* @returns Detailed dependency check result including version information
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Check with default paths (searches system PATH)
|
||||
* const result = await DependencyChecker.checkAllDependencies();
|
||||
* if (result.allAvailable) {
|
||||
* console.log('All dependencies found!');
|
||||
* console.log(`Pandoc: ${result.pandoc.version}`);
|
||||
* console.log(`Typst: ${result.typst.version}`);
|
||||
* }
|
||||
*
|
||||
* // Check with custom paths and additional search directories
|
||||
* const result = await DependencyChecker.checkAllDependencies(
|
||||
* '/usr/local/bin/pandoc',
|
||||
* '/opt/typst/bin/typst',
|
||||
* '/usr/bin/convert',
|
||||
* ['/opt/local/bin', '/usr/local/opt/bin']
|
||||
* );
|
||||
*
|
||||
* // Handle missing dependencies
|
||||
* if (!result.allAvailable) {
|
||||
* console.error('Missing:', result.missingDependencies.join(', '));
|
||||
* result.missingDependencies.forEach(name => {
|
||||
* const dep = name === 'Pandoc' ? result.pandoc :
|
||||
* name === 'Typst' ? result.typst : result.imagemagick;
|
||||
* console.error(`${name} not found at: ${dep.executablePath}`);
|
||||
* });
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
public static async checkAllDependencies(
|
||||
pandocPath?: string,
|
||||
@@ -58,7 +160,52 @@ export class DependencyChecker {
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick dependency check (synchronous) - returns list of missing dependencies
|
||||
* Performs fast synchronous dependency checking without version detection.
|
||||
*
|
||||
* This is a simplified version of checkAllDependencies that only checks if
|
||||
* executables can be run successfully (exit code 0), without extracting version
|
||||
* information. It's designed for scenarios where async operations are not
|
||||
* possible (e.g., plugin initialization) or when only availability matters.
|
||||
*
|
||||
* The method checks all three tools sequentially and returns a list of missing
|
||||
* dependency names. Empty array indicates all dependencies are available.
|
||||
*
|
||||
* @param pandocPath - Optional custom path to Pandoc executable
|
||||
* @param typstPath - Optional custom path to Typst executable
|
||||
* @param imagemagickPath - Optional custom path to ImageMagick convert executable
|
||||
* @param additionalPaths - Additional directories to search for executables
|
||||
* @returns Array of missing dependency names (empty if all available)
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Quick startup check in plugin onload()
|
||||
* const missing = DependencyChecker.checkDependenciesSync(
|
||||
* this.settings.pandocPath,
|
||||
* this.settings.typstPath,
|
||||
* this.settings.imagemagickPath
|
||||
* );
|
||||
*
|
||||
* if (missing.length > 0) {
|
||||
* new Notice(`Missing dependencies: ${missing.join(', ')}`);
|
||||
* return;
|
||||
* }
|
||||
*
|
||||
* // Check with additional search paths
|
||||
* const missing = DependencyChecker.checkDependenciesSync(
|
||||
* undefined, // Use default Pandoc
|
||||
* undefined, // Use default Typst
|
||||
* undefined, // Use default ImageMagick
|
||||
* ['/opt/local/bin', '~/.local/bin']
|
||||
* );
|
||||
*
|
||||
* // React based on specific missing tools
|
||||
* if (missing.includes('Pandoc')) {
|
||||
* console.error('Pandoc is required for Markdown conversion');
|
||||
* }
|
||||
* if (missing.includes('Typst')) {
|
||||
* console.error('Typst is required for PDF generation');
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
public static checkDependenciesSync(
|
||||
pandocPath?: string,
|
||||
@@ -87,7 +234,47 @@ export class DependencyChecker {
|
||||
}
|
||||
|
||||
/**
|
||||
* Show dependency status modal
|
||||
* Displays dependency status in a user-facing notice with version information.
|
||||
*
|
||||
* This method performs a comprehensive dependency check and displays the results
|
||||
* in an Obsidian notice modal. The notice includes:
|
||||
* - Status of each dependency (version or "Not found")
|
||||
* - Overall availability message
|
||||
* - Installation instructions if dependencies are missing
|
||||
*
|
||||
* The notice is displayed for 12 seconds to give users time to read the detailed
|
||||
* information. This method is typically called from the plugin's settings or via
|
||||
* a command palette action.
|
||||
*
|
||||
* @param pandocPath - Optional custom path to Pandoc executable
|
||||
* @param typstPath - Optional custom path to Typst executable
|
||||
* @param imagemagickPath - Optional custom path to ImageMagick convert executable
|
||||
* @param additionalPaths - Additional directories to search for executables
|
||||
* @returns Promise that resolves when the status has been displayed
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Display status from settings panel
|
||||
* await DependencyChecker.showDependencyStatus(
|
||||
* this.plugin.settings.pandocPath,
|
||||
* this.plugin.settings.typstPath,
|
||||
* this.plugin.settings.imagemagickPath
|
||||
* );
|
||||
*
|
||||
* // Display status via command palette
|
||||
* this.addCommand({
|
||||
* id: 'check-dependencies',
|
||||
* name: 'Check Dependencies',
|
||||
* callback: async () => {
|
||||
* await DependencyChecker.showDependencyStatus(
|
||||
* this.settings.pandocPath,
|
||||
* this.settings.typstPath,
|
||||
* this.settings.imagemagickPath,
|
||||
* this.settings.additionalPaths
|
||||
* );
|
||||
* }
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
public static async showDependencyStatus(
|
||||
pandocPath?: string,
|
||||
@@ -117,7 +304,49 @@ ${dependencyResult.allAvailable
|
||||
}
|
||||
|
||||
/**
|
||||
* Check dependencies silently on startup and show notice if missing
|
||||
* Performs silent dependency checking on plugin startup with error notifications.
|
||||
*
|
||||
* This method is designed for plugin initialization and performs a fast synchronous
|
||||
* check of all dependencies. It only displays a notice if dependencies are missing,
|
||||
* keeping the user experience clean when everything is working correctly.
|
||||
*
|
||||
* If dependencies are missing, a notice is shown for 8 seconds directing the user
|
||||
* to run the full "Check Dependencies" command for detailed information. If an
|
||||
* error occurs during checking, it's handled gracefully via ExportErrorHandler.
|
||||
*
|
||||
* This method should be called early in the plugin lifecycle (typically in onload)
|
||||
* to ensure users are aware of missing dependencies before attempting exports.
|
||||
*
|
||||
* @param pandocPath - Optional custom path to Pandoc executable
|
||||
* @param typstPath - Optional custom path to Typst executable
|
||||
* @param imagemagickPath - Optional custom path to ImageMagick convert executable
|
||||
* @param additionalPaths - Additional directories to search for executables
|
||||
* @returns Promise that resolves when the check is complete
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // Call during plugin initialization
|
||||
* export default class MyPlugin extends Plugin {
|
||||
* async onload() {
|
||||
* await this.loadSettings();
|
||||
*
|
||||
* // Silent startup check - only shows notice if problems exist
|
||||
* await DependencyChecker.checkDependenciesAsync(
|
||||
* this.settings.pandocPath,
|
||||
* this.settings.typstPath,
|
||||
* this.settings.imagemagickPath,
|
||||
* this.settings.additionalPaths
|
||||
* );
|
||||
*
|
||||
* // Continue with plugin initialization
|
||||
* this.registerCommands();
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // User will see a notice only if dependencies are missing:
|
||||
* // "Typst PDF Export: Missing dependencies: Pandoc, Typst.
|
||||
* // Run 'Check Dependencies' command for details."
|
||||
* ```
|
||||
*/
|
||||
public static async checkDependenciesAsync(
|
||||
pandocPath?: string,
|
||||
|
||||
Reference in new issue
Block a user