refactor: migrate PandocCommandBuilder.ts to use PathUtils
- Replace fs.existsSync with PathUtils.fileExists() - Replace path.resolve with PathUtils.joinPath() for vault paths - Remove fs require, add PathUtils import - Keep path module for external tool relative path operations (path.relative) - Follow plan guidance for minimal path usage with external tools
This commit is contained in:
1 file changed
+5
-4
@@ -9,6 +9,7 @@ import { TypstVariableMapper } from './TypstVariableMapper';
|
|||||||
import { ResourcePathResolver } from './ResourcePathResolver';
|
import { ResourcePathResolver } from './ResourcePathResolver';
|
||||||
import { PathResolver } from '../../plugin/PathResolver';
|
import { PathResolver } from '../../plugin/PathResolver';
|
||||||
import type { obsidianTypstPDFExport } from '../../../main';
|
import type { obsidianTypstPDFExport } from '../../../main';
|
||||||
|
import { PathUtils } from '../../core/PathUtils';
|
||||||
|
|
||||||
export class PandocCommandBuilder {
|
export class PandocCommandBuilder {
|
||||||
private plugin: obsidianTypstPDFExport;
|
private plugin: obsidianTypstPDFExport;
|
||||||
@@ -95,19 +96,19 @@ export class PandocCommandBuilder {
|
|||||||
private async addTemplateConfiguration(args: string[], pandocOptions: PandocOptions): Promise<void> {
|
private async addTemplateConfiguration(args: string[], pandocOptions: PandocOptions): Promise<void> {
|
||||||
// Use universal wrapper with --template and pass actual template as template_path variable
|
// Use universal wrapper with --template and pass actual template as template_path variable
|
||||||
if (pandocOptions.template) {
|
if (pandocOptions.template) {
|
||||||
const fs = require('fs');
|
const pathUtils = new PathUtils(this.plugin.app);
|
||||||
const absolutePluginDir = pandocOptions.pluginDir || '';
|
const absolutePluginDir = pandocOptions.pluginDir || '';
|
||||||
const wrapperPath = path.resolve(absolutePluginDir, 'templates', 'universal-wrapper.pandoc.typ');
|
const wrapperPath = pathUtils.joinPath(absolutePluginDir, 'templates', 'universal-wrapper.pandoc.typ');
|
||||||
|
|
||||||
// Verify wrapper exists
|
// Verify wrapper exists
|
||||||
if (!fs.existsSync(wrapperPath)) {
|
if (!(await pathUtils.fileExists(wrapperPath))) {
|
||||||
throw new Error(`Universal wrapper template not found at: ${wrapperPath}`);
|
throw new Error(`Universal wrapper template not found at: ${wrapperPath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
args.push('--template', wrapperPath);
|
args.push('--template', wrapperPath);
|
||||||
|
|
||||||
// Add plugin templates directory as a resource path so Typst can find template files
|
// Add plugin templates directory as a resource path so Typst can find template files
|
||||||
const templatesDir = path.resolve(absolutePluginDir, 'templates');
|
const templatesDir = pathUtils.joinPath(absolutePluginDir, 'templates');
|
||||||
// Quote the path to handle spaces and special characters
|
// Quote the path to handle spaces and special characters
|
||||||
args.push('--resource-path', `"${templatesDir}"`);
|
args.push('--resource-path', `"${templatesDir}"`);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user