feat: implement dependency checker and external tool management (task 3)
Add comprehensive dependency checking system for external tools: - Create DependencyChecker class with cross-platform executable detection - Implement version validation for Pandoc (3.0.0+) and Typst (0.11.0+) - Add timeout handling and robust error management for external processes - Integrate dependency checking with plugin lifecycle and settings interface - Create DependencyStatusModal with detailed status display and installation guides - Add platform-specific installation instructions (Windows/Mac/Linux) - Include user-friendly error messages and troubleshooting guidance - Add dependency status section to settings with "Check Dependencies" button - Style dependency modal with Obsidian theme-aware CSS - Update TypeScript config to exclude reference files from compilation The dependency checker provides non-blocking startup validation, export workflow integration, and comprehensive user guidance for missing or outdated external tools. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
4 files changed
+903
-8
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { App, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
|
||||
import { App, Notice, Plugin, PluginSettingTab, Setting, Modal, MarkdownRenderer } from 'obsidian';
|
||||
import { DependencyChecker } from './src/DependencyChecker';
|
||||
|
||||
/**
|
||||
* Obsidian Typst PDF Export Plugin
|
||||
@@ -161,13 +162,20 @@ const DEFAULT_SETTINGS: obsidianTypstPDFExportSettings = {
|
||||
|
||||
export default class obsidianTypstPDFExport extends Plugin {
|
||||
settings: obsidianTypstPDFExportSettings;
|
||||
dependencyChecker: DependencyChecker;
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
|
||||
// Initialize dependency checker
|
||||
this.dependencyChecker = new DependencyChecker();
|
||||
|
||||
// Check dependencies on startup (non-blocking)
|
||||
this.checkDependenciesAsync();
|
||||
|
||||
// Add ribbon icon for quick export access
|
||||
this.addRibbonIcon('file-text', 'Export to PDF with Typst', () => {
|
||||
new Notice('Typst PDF Export: Coming soon!');
|
||||
this.handleExportWithDependencyCheck();
|
||||
});
|
||||
|
||||
// Add basic export command
|
||||
@@ -175,7 +183,16 @@ export default class obsidianTypstPDFExport extends Plugin {
|
||||
id: 'export-current-note',
|
||||
name: 'Export current note to Typst PDF',
|
||||
callback: () => {
|
||||
new Notice('Typst PDF Export functionality will be implemented in future versions.');
|
||||
this.handleExportWithDependencyCheck();
|
||||
}
|
||||
});
|
||||
|
||||
// Add dependency check command
|
||||
this.addCommand({
|
||||
id: 'check-dependencies',
|
||||
name: 'Check Pandoc and Typst dependencies',
|
||||
callback: () => {
|
||||
this.showDependencyStatus();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -187,6 +204,115 @@ export default class obsidianTypstPDFExport extends Plugin {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check dependencies asynchronously without blocking plugin startup
|
||||
*/
|
||||
private async checkDependenciesAsync(): Promise<void> {
|
||||
try {
|
||||
const result = await this.dependencyChecker.checkAllDependencies(
|
||||
{ customPath: this.settings.pandocPath },
|
||||
{ customPath: this.settings.typstPath }
|
||||
);
|
||||
|
||||
if (!result.allAvailable) {
|
||||
// Show notice only if some dependencies are missing
|
||||
const missingTools = [];
|
||||
if (!result.pandoc.isAvailable) missingTools.push('Pandoc');
|
||||
if (!result.typst.isAvailable) missingTools.push('Typst');
|
||||
|
||||
new Notice(`Typst PDF Export: ${missingTools.join(' and ')} not found. Use "Check dependencies" command for setup instructions.`, 8000);
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Dependency check failed on startup:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle export with dependency checking
|
||||
*/
|
||||
private async handleExportWithDependencyCheck(): Promise<void> {
|
||||
const result = await this.dependencyChecker.checkAllDependencies(
|
||||
{ customPath: this.settings.pandocPath },
|
||||
{ customPath: this.settings.typstPath }
|
||||
);
|
||||
|
||||
if (!result.allAvailable) {
|
||||
this.showDependencyErrorDialog(result);
|
||||
return;
|
||||
}
|
||||
|
||||
// Dependencies are available, proceed with export
|
||||
new Notice('Typst PDF Export: Dependencies verified! Export functionality will be implemented in future versions.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show detailed dependency status
|
||||
*/
|
||||
private async showDependencyStatus(): Promise<void> {
|
||||
try {
|
||||
const result = await this.dependencyChecker.checkAllDependencies(
|
||||
{ customPath: this.settings.pandocPath },
|
||||
{ customPath: this.settings.typstPath }
|
||||
);
|
||||
|
||||
let message = '## Dependency Status\n\n';
|
||||
|
||||
// Pandoc status
|
||||
message += '### Pandoc\n';
|
||||
if (result.pandoc.isAvailable) {
|
||||
message += `✅ **Available** (v${result.pandoc.version})\n`;
|
||||
message += `Path: ${result.pandoc.executablePath}\n\n`;
|
||||
} else {
|
||||
message += '❌ **Not Available**\n';
|
||||
message += `Error: ${result.pandoc.error}\n\n`;
|
||||
message += this.dependencyChecker.formatInstallationGuide(
|
||||
this.dependencyChecker.getInstallationGuide('pandoc')
|
||||
);
|
||||
message += '\n\n';
|
||||
}
|
||||
|
||||
// Typst status
|
||||
message += '### Typst\n';
|
||||
if (result.typst.isAvailable) {
|
||||
message += `✅ **Available** (v${result.typst.version})\n`;
|
||||
message += `Path: ${result.typst.executablePath}\n\n`;
|
||||
} else {
|
||||
message += '❌ **Not Available**\n';
|
||||
message += `Error: ${result.typst.error}\n\n`;
|
||||
message += this.dependencyChecker.formatInstallationGuide(
|
||||
this.dependencyChecker.getInstallationGuide('typst')
|
||||
);
|
||||
}
|
||||
|
||||
// Create and show modal with dependency status
|
||||
const modal = new DependencyStatusModal(this.app, this);
|
||||
modal.open();
|
||||
|
||||
} catch (error) {
|
||||
new Notice(`Error checking dependencies: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show dependency error dialog with installation instructions
|
||||
*/
|
||||
private showDependencyErrorDialog(result: { pandoc: any; typst: any; allAvailable: boolean }): void {
|
||||
let message = '## Missing Dependencies\n\nThe following dependencies are required:\n\n';
|
||||
|
||||
if (!result.pandoc.isAvailable) {
|
||||
message += `**Pandoc**: ${result.pandoc.error}\n\n`;
|
||||
}
|
||||
|
||||
if (!result.typst.isAvailable) {
|
||||
message += `**Typst**: ${result.typst.error}\n\n`;
|
||||
}
|
||||
|
||||
message += 'Use the "Check Pandoc and Typst dependencies" command for detailed installation instructions.';
|
||||
|
||||
const modal = new DependencyStatusModal(this.app, this);
|
||||
modal.open();
|
||||
}
|
||||
|
||||
async loadSettings() {
|
||||
try {
|
||||
const loadedData = await this.loadData();
|
||||
@@ -384,6 +510,158 @@ export default class obsidianTypstPDFExport extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Modal for displaying dependency status and installation instructions
|
||||
*/
|
||||
class DependencyStatusModal extends Modal {
|
||||
plugin: obsidianTypstPDFExport;
|
||||
|
||||
constructor(app: App, plugin: obsidianTypstPDFExport) {
|
||||
super(app);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
async onOpen() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
|
||||
contentEl.createEl('h2', { text: 'External Dependencies Status' });
|
||||
|
||||
// Show loading indicator
|
||||
const loadingEl = contentEl.createDiv();
|
||||
loadingEl.setText('Checking dependencies...');
|
||||
|
||||
try {
|
||||
// Check dependencies
|
||||
const results = await this.plugin.dependencyChecker.checkAllDependencies(
|
||||
{ customPath: this.plugin.settings.pandocPath },
|
||||
{ customPath: this.plugin.settings.typstPath }
|
||||
);
|
||||
|
||||
// Clear loading indicator
|
||||
loadingEl.remove();
|
||||
|
||||
// Show overall status
|
||||
const overallStatus = contentEl.createDiv({ cls: 'dependency-overall-status' });
|
||||
if (results.allAvailable) {
|
||||
overallStatus.createEl('div', {
|
||||
text: '✅ All dependencies are available and ready to use',
|
||||
cls: 'dependency-success'
|
||||
});
|
||||
} else {
|
||||
overallStatus.createEl('div', {
|
||||
text: '❌ Some dependencies need attention',
|
||||
cls: 'dependency-error'
|
||||
});
|
||||
}
|
||||
|
||||
// Pandoc status
|
||||
this.createDependencySection(contentEl, 'Pandoc', results.pandoc);
|
||||
|
||||
// Typst status
|
||||
this.createDependencySection(contentEl, 'Typst', results.typst);
|
||||
|
||||
// Add refresh button
|
||||
const buttonContainer = contentEl.createDiv({ cls: 'dependency-button-container' });
|
||||
const refreshButton = buttonContainer.createEl('button', { text: 'Refresh Status' });
|
||||
refreshButton.onclick = () => {
|
||||
this.close();
|
||||
new DependencyStatusModal(this.app, this.plugin).open();
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
loadingEl.remove();
|
||||
const errorEl = contentEl.createDiv({ cls: 'dependency-error' });
|
||||
errorEl.setText(`Error checking dependencies: ${error instanceof Error ? error.message : String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
private createDependencySection(containerEl: HTMLElement, toolName: string, result: any) {
|
||||
const section = containerEl.createDiv({ cls: 'dependency-section' });
|
||||
|
||||
// Tool header
|
||||
const header = section.createEl('h3', { text: toolName });
|
||||
|
||||
// Status indicator
|
||||
const statusEl = section.createDiv({ cls: 'dependency-status' });
|
||||
if (result.isAvailable) {
|
||||
statusEl.createEl('span', {
|
||||
text: `✅ ${toolName} v${result.version} - Ready`,
|
||||
cls: 'dependency-success'
|
||||
});
|
||||
if (result.executablePath) {
|
||||
statusEl.createEl('div', {
|
||||
text: `Path: ${result.executablePath}`,
|
||||
cls: 'dependency-path'
|
||||
});
|
||||
}
|
||||
if (result.warning) {
|
||||
statusEl.createEl('div', {
|
||||
text: `⚠️ ${result.warning}`,
|
||||
cls: 'dependency-warning'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
statusEl.createEl('span', {
|
||||
text: `❌ ${toolName} - Not Available`,
|
||||
cls: 'dependency-error'
|
||||
});
|
||||
if (result.error) {
|
||||
statusEl.createEl('div', {
|
||||
text: `Error: ${result.error}`,
|
||||
cls: 'dependency-error-detail'
|
||||
});
|
||||
}
|
||||
|
||||
// Show installation guide
|
||||
this.createInstallationGuide(section, toolName.toLowerCase() as 'pandoc' | 'typst');
|
||||
}
|
||||
}
|
||||
|
||||
private createInstallationGuide(containerEl: HTMLElement, toolName: 'pandoc' | 'typst') {
|
||||
const guide = this.plugin.dependencyChecker.getInstallationGuide(toolName);
|
||||
const platform = this.plugin.dependencyChecker.getCurrentPlatform();
|
||||
const platformInstructions = guide.instructions[platform];
|
||||
|
||||
const guideEl = containerEl.createDiv({ cls: 'dependency-install-guide' });
|
||||
guideEl.createEl('h4', { text: 'Installation Instructions' });
|
||||
|
||||
guideEl.createEl('p', { text: platformInstructions.description });
|
||||
|
||||
if (platformInstructions.commands && platformInstructions.commands.length > 0) {
|
||||
const commandsEl = guideEl.createDiv();
|
||||
commandsEl.createEl('strong', { text: 'Installation commands:' });
|
||||
const commandsList = commandsEl.createEl('ul');
|
||||
platformInstructions.commands.forEach(cmd => {
|
||||
const listItem = commandsList.createEl('li');
|
||||
listItem.createEl('code', { text: cmd });
|
||||
});
|
||||
}
|
||||
|
||||
const linksEl = guideEl.createDiv();
|
||||
linksEl.createEl('strong', { text: 'Useful links:' });
|
||||
const linksList = linksEl.createEl('ul');
|
||||
platformInstructions.links.forEach(link => {
|
||||
const listItem = linksList.createEl('li');
|
||||
const linkEl = listItem.createEl('a', { text: link, href: link });
|
||||
linkEl.setAttr('target', '_blank');
|
||||
});
|
||||
|
||||
if (guide.troubleshooting.length > 0) {
|
||||
const troubleshootingEl = guideEl.createDiv();
|
||||
troubleshootingEl.createEl('strong', { text: 'Troubleshooting:' });
|
||||
const troubleshootingList = troubleshootingEl.createEl('ul');
|
||||
guide.troubleshooting.forEach(tip => {
|
||||
troubleshootingList.createEl('li', { text: tip });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
}
|
||||
|
||||
class TypstPDFExportSettingTab extends PluginSettingTab {
|
||||
plugin: obsidianTypstPDFExport;
|
||||
@@ -400,6 +678,22 @@ class TypstPDFExportSettingTab extends PluginSettingTab {
|
||||
|
||||
containerEl.createEl('h2', {text: 'Typst PDF Export Settings'});
|
||||
|
||||
// Dependency Status Section
|
||||
new Setting(containerEl)
|
||||
.setHeading();
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Dependency Status')
|
||||
.setDesc('Check the status of external dependencies')
|
||||
.addButton(button => button
|
||||
.setButtonText('Check Dependencies')
|
||||
.setCta()
|
||||
.onClick(async () => {
|
||||
// Open dependency status modal
|
||||
const modal = new DependencyStatusModal(this.app, this.plugin);
|
||||
modal.open();
|
||||
}));
|
||||
|
||||
// External Tools Section
|
||||
new Setting(containerEl)
|
||||
.setHeading();
|
||||
|
||||
@@ -0,0 +1,493 @@
|
||||
import { spawn, ChildProcess } from 'child_process';
|
||||
import { access } from 'fs/promises';
|
||||
import { join, resolve, dirname } from 'path';
|
||||
import { Platform } from 'obsidian';
|
||||
|
||||
/**
|
||||
* Result of a dependency check operation
|
||||
*/
|
||||
interface DependencyCheckResult {
|
||||
/** Whether the dependency was found and is valid */
|
||||
isAvailable: boolean;
|
||||
/** Path to the executable (if found) */
|
||||
executablePath?: string;
|
||||
/** Detected version (if available) */
|
||||
version?: string;
|
||||
/** Error message if dependency is not available */
|
||||
error?: string;
|
||||
/** Warning message for issues that don't prevent usage */
|
||||
warning?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Installation guidance for specific platforms and tools
|
||||
*/
|
||||
interface InstallationGuide {
|
||||
/** Tool name */
|
||||
tool: 'pandoc' | 'typst';
|
||||
/** Installation instructions by platform */
|
||||
instructions: {
|
||||
windows: {
|
||||
description: string;
|
||||
links: string[];
|
||||
commands?: string[];
|
||||
};
|
||||
mac: {
|
||||
description: string;
|
||||
links: string[];
|
||||
commands?: string[];
|
||||
};
|
||||
linux: {
|
||||
description: string;
|
||||
links: string[];
|
||||
commands?: string[];
|
||||
};
|
||||
};
|
||||
/** Troubleshooting tips */
|
||||
troubleshooting: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration for dependency checking
|
||||
*/
|
||||
interface DependencyConfig {
|
||||
/** Custom path to executable (empty string means use PATH) */
|
||||
customPath: string;
|
||||
/** Minimum required version */
|
||||
minVersion: string;
|
||||
/** Timeout for version checks in milliseconds */
|
||||
timeout: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for external tool dependencies (Pandoc and Typst) with cross-platform support
|
||||
*/
|
||||
export class DependencyChecker {
|
||||
private static readonly DEFAULT_TIMEOUT = 5000; // 5 seconds
|
||||
private static readonly PANDOC_MIN_VERSION = '3.0.0';
|
||||
private static readonly TYPST_MIN_VERSION = '0.11.0';
|
||||
|
||||
/**
|
||||
* Check if Pandoc is available and meets version requirements
|
||||
*/
|
||||
async checkPandoc(config: Partial<DependencyConfig> = {}): Promise<DependencyCheckResult> {
|
||||
const fullConfig: DependencyConfig = {
|
||||
customPath: config.customPath || '',
|
||||
minVersion: config.minVersion || DependencyChecker.PANDOC_MIN_VERSION,
|
||||
timeout: config.timeout || DependencyChecker.DEFAULT_TIMEOUT
|
||||
};
|
||||
|
||||
return this.checkDependency('pandoc', fullConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Typst is available and meets version requirements
|
||||
*/
|
||||
async checkTypst(config: Partial<DependencyConfig> = {}): Promise<DependencyCheckResult> {
|
||||
const fullConfig: DependencyConfig = {
|
||||
customPath: config.customPath || '',
|
||||
minVersion: config.minVersion || DependencyChecker.TYPST_MIN_VERSION,
|
||||
timeout: config.timeout || DependencyChecker.DEFAULT_TIMEOUT
|
||||
};
|
||||
|
||||
return this.checkDependency('typst', fullConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check both Pandoc and Typst dependencies
|
||||
*/
|
||||
async checkAllDependencies(pandocConfig: Partial<DependencyConfig> = {}, typstConfig: Partial<DependencyConfig> = {}): Promise<{
|
||||
pandoc: DependencyCheckResult;
|
||||
typst: DependencyCheckResult;
|
||||
allAvailable: boolean;
|
||||
}> {
|
||||
const [pandoc, typst] = await Promise.all([
|
||||
this.checkPandoc(pandocConfig),
|
||||
this.checkTypst(typstConfig)
|
||||
]);
|
||||
|
||||
return {
|
||||
pandoc,
|
||||
typst,
|
||||
allAvailable: pandoc.isAvailable && typst.isAvailable
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Core dependency checking logic
|
||||
*/
|
||||
private async checkDependency(toolName: 'pandoc' | 'typst', config: DependencyConfig): Promise<DependencyCheckResult> {
|
||||
try {
|
||||
// Step 1: Find the executable
|
||||
const executablePath = await this.findExecutable(toolName, config.customPath);
|
||||
if (!executablePath) {
|
||||
return {
|
||||
isAvailable: false,
|
||||
error: `${toolName} executable not found. ${this.getInstallationMessage(toolName)}`
|
||||
};
|
||||
}
|
||||
|
||||
// Step 2: Check version
|
||||
const versionResult = await this.checkVersion(executablePath, config.minVersion, config.timeout);
|
||||
if (!versionResult.isValid) {
|
||||
return {
|
||||
isAvailable: false,
|
||||
executablePath,
|
||||
version: versionResult.version,
|
||||
error: versionResult.error || `${toolName} version ${versionResult.version} does not meet minimum requirement ${config.minVersion}`
|
||||
};
|
||||
}
|
||||
|
||||
// Step 3: Success
|
||||
return {
|
||||
isAvailable: true,
|
||||
executablePath,
|
||||
version: versionResult.version,
|
||||
warning: versionResult.warning
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
return {
|
||||
isAvailable: false,
|
||||
error: `Error checking ${toolName}: ${error instanceof Error ? error.message : String(error)}`
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find executable path using custom path or system PATH
|
||||
*/
|
||||
private async findExecutable(toolName: string, customPath: string): Promise<string | null> {
|
||||
// If custom path is provided, validate it
|
||||
if (customPath) {
|
||||
const resolvedPath = resolve(customPath);
|
||||
if (await this.isExecutableFile(resolvedPath)) {
|
||||
return resolvedPath;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Search in system PATH
|
||||
return this.findInPath(toolName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for executable in system PATH
|
||||
*/
|
||||
private async findInPath(toolName: string): Promise<string | null> {
|
||||
const pathEnv = process.env.PATH || '';
|
||||
const pathSeparator = Platform.isWin ? ';' : ':';
|
||||
const paths = pathEnv.split(pathSeparator);
|
||||
|
||||
// Add common executable extensions on Windows
|
||||
const extensions = Platform.isWin ? ['.exe', '.cmd', '.bat'] : [''];
|
||||
|
||||
for (const dir of paths) {
|
||||
if (!dir.trim()) continue;
|
||||
|
||||
for (const ext of extensions) {
|
||||
const fullPath = join(dir, toolName + ext);
|
||||
if (await this.isExecutableFile(fullPath)) {
|
||||
return fullPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a file exists and is executable
|
||||
*/
|
||||
private async isExecutableFile(filePath: string): Promise<boolean> {
|
||||
try {
|
||||
await access(filePath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check version of an executable and validate against minimum requirement
|
||||
*/
|
||||
private async checkVersion(executablePath: string, minVersion: string, timeout: number): Promise<{
|
||||
isValid: boolean;
|
||||
version?: string;
|
||||
error?: string;
|
||||
warning?: string;
|
||||
}> {
|
||||
try {
|
||||
const version = await this.getVersion(executablePath, timeout);
|
||||
if (!version) {
|
||||
return {
|
||||
isValid: false,
|
||||
error: 'Could not determine version'
|
||||
};
|
||||
}
|
||||
|
||||
const isValid = this.compareVersions(version, minVersion) >= 0;
|
||||
return {
|
||||
isValid,
|
||||
version,
|
||||
error: isValid ? undefined : `Version ${version} is below required ${minVersion}`,
|
||||
warning: isValid ? undefined : this.getUpgradeMessage(executablePath, version, minVersion)
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
return {
|
||||
isValid: false,
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get version string from executable
|
||||
*/
|
||||
private async getVersion(executablePath: string, timeout: number): Promise<string | null> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const process = spawn(executablePath, ['--version'], {
|
||||
stdio: ['ignore', 'pipe', 'pipe']
|
||||
});
|
||||
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
|
||||
const timeoutHandle = setTimeout(() => {
|
||||
process.kill();
|
||||
reject(new Error(`Version check timed out after ${timeout}ms`));
|
||||
}, timeout);
|
||||
|
||||
process.stdout?.on('data', (data) => {
|
||||
stdout += data.toString();
|
||||
});
|
||||
|
||||
process.stderr?.on('data', (data) => {
|
||||
stderr += data.toString();
|
||||
});
|
||||
|
||||
process.on('close', (code) => {
|
||||
clearTimeout(timeoutHandle);
|
||||
|
||||
if (code !== 0) {
|
||||
reject(new Error(`Process exited with code ${code}: ${stderr}`));
|
||||
return;
|
||||
}
|
||||
|
||||
const version = this.extractVersion(stdout);
|
||||
resolve(version);
|
||||
});
|
||||
|
||||
process.on('error', (error) => {
|
||||
clearTimeout(timeoutHandle);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract version number from version command output
|
||||
*/
|
||||
private extractVersion(output: string): string | null {
|
||||
// Common patterns for version output
|
||||
const patterns = [
|
||||
/version\s+(\d+\.\d+\.\d+)/i,
|
||||
/v?(\d+\.\d+\.\d+)/,
|
||||
/(\d+\.\d+\.\d+)/
|
||||
];
|
||||
|
||||
for (const pattern of patterns) {
|
||||
const match = output.match(pattern);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two semantic version strings
|
||||
* Returns: -1 if a < b, 0 if a == b, 1 if a > b
|
||||
*/
|
||||
private compareVersions(a: string, b: string): number {
|
||||
const parseVersion = (version: string) => {
|
||||
return version.split('.').map(num => parseInt(num, 10));
|
||||
};
|
||||
|
||||
const aParts = parseVersion(a);
|
||||
const bParts = parseVersion(b);
|
||||
const maxLength = Math.max(aParts.length, bParts.length);
|
||||
|
||||
for (let i = 0; i < maxLength; i++) {
|
||||
const aPart = aParts[i] || 0;
|
||||
const bPart = bParts[i] || 0;
|
||||
|
||||
if (aPart < bPart) return -1;
|
||||
if (aPart > bPart) return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get installation instructions for a tool
|
||||
*/
|
||||
getInstallationGuide(toolName: 'pandoc' | 'typst'): InstallationGuide {
|
||||
if (toolName === 'pandoc') {
|
||||
return {
|
||||
tool: 'pandoc',
|
||||
instructions: {
|
||||
windows: {
|
||||
description: 'Install Pandoc using the Windows installer or package manager',
|
||||
links: [
|
||||
'https://pandoc.org/installing.html',
|
||||
'https://github.com/jgm/pandoc/releases'
|
||||
],
|
||||
commands: [
|
||||
'winget install --id JohnMacFarlane.Pandoc',
|
||||
'choco install pandoc'
|
||||
]
|
||||
},
|
||||
mac: {
|
||||
description: 'Install Pandoc using Homebrew or the macOS installer',
|
||||
links: [
|
||||
'https://pandoc.org/installing.html',
|
||||
'https://github.com/jgm/pandoc/releases'
|
||||
],
|
||||
commands: [
|
||||
'brew install pandoc',
|
||||
'sudo port install pandoc'
|
||||
]
|
||||
},
|
||||
linux: {
|
||||
description: 'Install Pandoc using your distribution\'s package manager',
|
||||
links: [
|
||||
'https://pandoc.org/installing.html',
|
||||
'https://github.com/jgm/pandoc/releases'
|
||||
],
|
||||
commands: [
|
||||
'sudo apt install pandoc # Ubuntu/Debian',
|
||||
'sudo dnf install pandoc # Fedora',
|
||||
'sudo pacman -S pandoc # Arch Linux'
|
||||
]
|
||||
}
|
||||
},
|
||||
troubleshooting: [
|
||||
'Ensure Pandoc is in your system PATH',
|
||||
'Restart Obsidian after installation',
|
||||
'For manual installations, specify the full path in plugin settings',
|
||||
'Check that you have the latest version from the official website'
|
||||
]
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
tool: 'typst',
|
||||
instructions: {
|
||||
windows: {
|
||||
description: 'Install Typst using the Windows installer or package manager',
|
||||
links: [
|
||||
'https://github.com/typst/typst#installation',
|
||||
'https://github.com/typst/typst/releases'
|
||||
],
|
||||
commands: [
|
||||
'winget install --id Typst.Typst',
|
||||
'cargo install --locked typst-cli'
|
||||
]
|
||||
},
|
||||
mac: {
|
||||
description: 'Install Typst using Homebrew or Rust',
|
||||
links: [
|
||||
'https://github.com/typst/typst#installation',
|
||||
'https://github.com/typst/typst/releases'
|
||||
],
|
||||
commands: [
|
||||
'brew install typst',
|
||||
'cargo install --locked typst-cli'
|
||||
]
|
||||
},
|
||||
linux: {
|
||||
description: 'Install Typst using your package manager or Rust',
|
||||
links: [
|
||||
'https://github.com/typst/typst#installation',
|
||||
'https://github.com/typst/typst/releases'
|
||||
],
|
||||
commands: [
|
||||
'cargo install --locked typst-cli',
|
||||
'Download from releases page for your distribution'
|
||||
]
|
||||
}
|
||||
},
|
||||
troubleshooting: [
|
||||
'Ensure Typst is in your system PATH',
|
||||
'Restart Obsidian after installation',
|
||||
'For manual installations, specify the full path in plugin settings',
|
||||
'Install Rust first if using cargo install method',
|
||||
'Check that you have version 0.11.0 or higher'
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a brief installation message for error display
|
||||
*/
|
||||
private getInstallationMessage(toolName: 'pandoc' | 'typst'): string {
|
||||
if (toolName === 'pandoc') {
|
||||
return 'Install from https://pandoc.org/installing.html or specify custom path in settings.';
|
||||
} else {
|
||||
return 'Install from https://github.com/typst/typst#installation or specify custom path in settings.';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get upgrade message for outdated versions
|
||||
*/
|
||||
private getUpgradeMessage(executablePath: string, currentVersion: string, requiredVersion: string): string {
|
||||
return `Found ${executablePath} v${currentVersion}, but v${requiredVersion}+ is required. Please upgrade.`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current platform information
|
||||
*/
|
||||
getCurrentPlatform(): 'windows' | 'mac' | 'linux' {
|
||||
if (Platform.isWin) return 'windows';
|
||||
if (Platform.isMacOS) return 'mac';
|
||||
return 'linux';
|
||||
}
|
||||
|
||||
/**
|
||||
* Format installation guide as user-friendly text
|
||||
*/
|
||||
formatInstallationGuide(guide: InstallationGuide): string {
|
||||
const platform = this.getCurrentPlatform();
|
||||
const platformInstructions = guide.instructions[platform];
|
||||
|
||||
let text = `## Installing ${guide.tool.charAt(0).toUpperCase() + guide.tool.slice(1)}\n\n`;
|
||||
text += `${platformInstructions.description}\n\n`;
|
||||
|
||||
if (platformInstructions.commands && platformInstructions.commands.length > 0) {
|
||||
text += '**Installation commands:**\n';
|
||||
platformInstructions.commands.forEach(cmd => {
|
||||
text += `\`${cmd}\`\n`;
|
||||
});
|
||||
text += '\n';
|
||||
}
|
||||
|
||||
text += '**Useful links:**\n';
|
||||
platformInstructions.links.forEach(link => {
|
||||
text += `- ${link}\n`;
|
||||
});
|
||||
text += '\n';
|
||||
|
||||
if (guide.troubleshooting.length > 0) {
|
||||
text += '**Troubleshooting:**\n';
|
||||
guide.troubleshooting.forEach(tip => {
|
||||
text += `- ${tip}\n`;
|
||||
});
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
||||
+108
-4
@@ -1,8 +1,112 @@
|
||||
/*
|
||||
* Typst PDF Export Plugin Styles
|
||||
*/
|
||||
|
||||
This CSS file will be included with your plugin, and
|
||||
available in the app when your plugin is enabled.
|
||||
/* Dependency status modal styles */
|
||||
.dependency-overall-status {
|
||||
margin-bottom: 1rem;
|
||||
padding: 0.75rem;
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
If your plugin does not need CSS, delete this file.
|
||||
.dependency-success {
|
||||
color: var(--text-success);
|
||||
}
|
||||
|
||||
*/
|
||||
.dependency-error {
|
||||
color: var(--text-error);
|
||||
}
|
||||
|
||||
.dependency-warning {
|
||||
color: var(--text-warning);
|
||||
}
|
||||
|
||||
.dependency-section {
|
||||
margin-bottom: 2rem;
|
||||
padding: 1rem;
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.dependency-section h3 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0.5rem;
|
||||
color: var(--text-normal);
|
||||
}
|
||||
|
||||
.dependency-status {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.dependency-path {
|
||||
margin-top: 0.25rem;
|
||||
font-size: 0.9em;
|
||||
color: var(--text-muted);
|
||||
font-family: var(--font-monospace);
|
||||
}
|
||||
|
||||
.dependency-error-detail {
|
||||
margin-top: 0.25rem;
|
||||
font-size: 0.9em;
|
||||
color: var(--text-error);
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.dependency-install-guide {
|
||||
margin-top: 1rem;
|
||||
padding: 1rem;
|
||||
background-color: var(--background-secondary);
|
||||
border-radius: 4px;
|
||||
border-left: 3px solid var(--interactive-accent);
|
||||
}
|
||||
|
||||
.dependency-install-guide h4 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0.75rem;
|
||||
color: var(--text-normal);
|
||||
}
|
||||
|
||||
.dependency-install-guide p {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.dependency-install-guide ul {
|
||||
margin-left: 1rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.dependency-install-guide code {
|
||||
background-color: var(--background-primary-alt);
|
||||
padding: 0.125rem 0.25rem;
|
||||
border-radius: 3px;
|
||||
font-family: var(--font-monospace);
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.dependency-install-guide a {
|
||||
color: var(--text-accent);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.dependency-install-guide a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.dependency-button-container {
|
||||
margin-top: 1.5rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.dependency-button-container button {
|
||||
padding: 0.5rem 1rem;
|
||||
background-color: var(--interactive-accent);
|
||||
color: var(--text-on-accent);
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.dependency-button-container button:hover {
|
||||
background-color: var(--interactive-accent-hover);
|
||||
}
|
||||
+5
-1
@@ -19,6 +19,10 @@
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts"
|
||||
"main.ts",
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"reference/**/*"
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user