diff --git a/packages/app-desktop/InteropServiceHelper.ts b/packages/app-desktop/InteropServiceHelper.ts index 5717b9ec2..7c5441782 100644 --- a/packages/app-desktop/InteropServiceHelper.ts +++ b/packages/app-desktop/InteropServiceHelper.ts @@ -1,7 +1,7 @@ import InteropService from '@joplin/lib/services/interop/InteropService'; import CommandService from '@joplin/lib/services/CommandService'; import shim from '@joplin/lib/shim'; -import { ExportOptions, FileSystemItem } from '@joplin/lib/services/interop/types'; +import { ExportModuleOutputFormat, ExportOptions, FileSystemItem } from '@joplin/lib/services/interop/types'; import { ExportModule } from '@joplin/lib/services/interop/Module'; import { _ } from '@joplin/lib/locale'; @@ -31,7 +31,7 @@ export default class InteropServiceHelper { const tempFile = `${Setting.value('tempDir')}/${md5(Date.now() + Math.random())}.html`; const fullExportOptions: ExportOptions = { path: tempFile, - format: 'html', + format: ExportModuleOutputFormat.Html, target: FileSystemItem.File, sourceNoteIds: [noteId], customCss: '', ...exportOptions }; diff --git a/packages/app-desktop/commands/exportFolders.ts b/packages/app-desktop/commands/exportFolders.ts index 6820ef680..25739e088 100644 --- a/packages/app-desktop/commands/exportFolders.ts +++ b/packages/app-desktop/commands/exportFolders.ts @@ -1,6 +1,6 @@ import { CommandRuntime, CommandDeclaration } from '@joplin/lib/services/CommandService'; import InteropService from '@joplin/lib/services/interop/InteropService'; -import { ExportOptions, FileSystemItem } from '@joplin/lib/services/interop/types'; +import { ExportModuleOutputFormat, ExportOptions, FileSystemItem } from '@joplin/lib/services/interop/types'; import shim from '@joplin/lib/shim'; export const declaration: CommandDeclaration = { @@ -11,7 +11,7 @@ export const runtime = (): CommandRuntime => { return { // "targetPath" should be a file for JEX export (because the format can // contain multiple folders) or a directory otherwise. - execute: async (_context: any, folderIds: string[], format: string, targetPath: string) => { + execute: async (_context: any, folderIds: string[], format: ExportModuleOutputFormat, targetPath: string) => { const exportOptions: ExportOptions = { sourceFolderIds: folderIds, path: targetPath, diff --git a/packages/app-desktop/commands/exportNotes.ts b/packages/app-desktop/commands/exportNotes.ts index cbf355dd2..d9798d51d 100644 --- a/packages/app-desktop/commands/exportNotes.ts +++ b/packages/app-desktop/commands/exportNotes.ts @@ -1,6 +1,6 @@ import { CommandRuntime, CommandDeclaration } from '@joplin/lib/services/CommandService'; import InteropService from '@joplin/lib/services/interop/InteropService'; -import { ExportOptions, FileSystemItem } from '@joplin/lib/services/interop/types'; +import { ExportModuleOutputFormat, ExportOptions, FileSystemItem } from '@joplin/lib/services/interop/types'; export const declaration: CommandDeclaration = { name: 'exportNotes', @@ -8,7 +8,7 @@ export const declaration: CommandDeclaration = { export const runtime = (): CommandRuntime => { return { - execute: async (_context: any, noteIds: string[], format: string, targetDirectoryPath: string) => { + execute: async (_context: any, noteIds: string[], format: ExportModuleOutputFormat, targetDirectoryPath: string) => { const exportOptions: ExportOptions = { path: targetDirectoryPath, format: format, diff --git a/packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/utils/exportAllFolders.ts b/packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/utils/exportAllFolders.ts index 32f9f7f33..16d9e090f 100644 --- a/packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/utils/exportAllFolders.ts +++ b/packages/app-mobile/components/screens/ConfigScreen/NoteExportSection/utils/exportAllFolders.ts @@ -1,6 +1,6 @@ import Folder from '@joplin/lib/models/Folder'; import InteropService from '@joplin/lib/services/interop/InteropService'; -import { ExportOptions, FileSystemItem, OnExportProgressCallback } from '@joplin/lib/services/interop/types'; +import { ExportModuleOutputFormat, ExportOptions, FileSystemItem, OnExportProgressCallback } from '@joplin/lib/services/interop/types'; import shim from '@joplin/lib/shim'; import { CachesDirectoryPath } from 'react-native-fs'; @@ -18,7 +18,7 @@ const exportFolders = async (path: string, onProgress: OnExportProgressCallback) const exportOptions: ExportOptions = { sourceFolderIds, path, - format: 'jex', + format: ExportModuleOutputFormat.Jex, target: FileSystemItem.File, onProgress, }; diff --git a/packages/lib/services/interop/InteropService.test.ts b/packages/lib/services/interop/InteropService.test.ts index 107f9e605..2d273c58a 100644 --- a/packages/lib/services/interop/InteropService.test.ts +++ b/packages/lib/services/interop/InteropService.test.ts @@ -1,5 +1,5 @@ import InteropService from '../../services/interop/InteropService'; -import { CustomExportContext, CustomImportContext, ModuleType } from '../../services/interop/types'; +import { CustomExportContext, CustomImportContext, ExportModuleOutputFormat, ModuleType } from '../../services/interop/types'; import shim from '../../shim'; import { fileContentEqual, setupDatabaseAndSynchronizer, switchClient, checkThrowAsync, exportDir, supportDir } from '../../testing/test-utils'; import Folder from '../../models/Folder'; @@ -52,7 +52,7 @@ function memoryExportModule() { const module: Module = makeExportModule({ description: 'Memory Export Module', - format: 'memory', + format: ExportModuleOutputFormat.Memory, fileExtensions: ['memory'], }, () => { return new InteropService_Exporter_Custom({ @@ -416,7 +416,7 @@ describe('services_InteropService', () => { const outDir = exportDir(); - await service.export({ path: outDir, format: 'md', sourceNoteIds: [note11.id, note21.id] }); + await service.export({ path: outDir, format: ExportModuleOutputFormat.Markdown, sourceNoteIds: [note11.id, note21.id] }); // verify that the md files exist expect(await shim.fsDriver().exists(`${outDir}/folder1`)).toBe(true); @@ -441,7 +441,7 @@ describe('services_InteropService', () => { const outDir = exportDir(); - await service.export({ path: outDir, format: 'md' }); + await service.export({ path: outDir, format: ExportModuleOutputFormat.Markdown }); expect(await shim.fsDriver().exists(`${outDir}/folder1/生活.md`)).toBe(true); expect(await shim.fsDriver().exists(`${outDir}/folder1/生活-1.md`)).toBe(true); @@ -461,7 +461,7 @@ describe('services_InteropService', () => { await service.export({ path: exportDir(), - format: 'md', + format: ExportModuleOutputFormat.Markdown, sourceFolderIds: [folder1.id], }); @@ -478,7 +478,7 @@ describe('services_InteropService', () => { await service.export({ path: exportDir(), - format: 'md', + format: ExportModuleOutputFormat.Markdown, sourceFolderIds: [folder1.id], includeConflicts: false, }); @@ -490,7 +490,7 @@ describe('services_InteropService', () => { await service.export({ path: exportDir(), - format: 'md', + format: ExportModuleOutputFormat.Markdown, sourceFolderIds: [folder1.id], includeConflicts: true, }); @@ -515,7 +515,7 @@ describe('services_InteropService', () => { const result = await service.export({ path: exportDir(), - format: 'md', + format: ExportModuleOutputFormat.Markdown, }); expect(result.warnings.length).toBe(0); @@ -533,7 +533,7 @@ describe('services_InteropService', () => { service.registerModule(module); await service.export({ - format: 'memory', + format: ExportModuleOutputFormat.Memory, }); const exportedNote = (result.items.find(i => i.type === ModelType.Note)).object as NoteEntity; @@ -603,7 +603,7 @@ describe('services_InteropService', () => { const module: Module = makeExportModule({ type: ModuleType.Exporter, description: 'Test Export Module', - format: 'testing', + format: 'testing' as any, fileExtensions: ['test'], }, () => { return new InteropService_Exporter_Custom({ @@ -630,7 +630,7 @@ describe('services_InteropService', () => { const service = InteropService.instance(); service.registerModule(module); await service.export({ - format: 'testing', + format: 'testing' as any, path: filePath, }); diff --git a/packages/lib/services/interop/InteropService.ts b/packages/lib/services/interop/InteropService.ts index bf73e71fc..f4d88d208 100644 --- a/packages/lib/services/interop/InteropService.ts +++ b/packages/lib/services/interop/InteropService.ts @@ -1,4 +1,4 @@ -import { ModuleType, FileSystemItem, ImportModuleOutputFormat, ImportOptions, ExportOptions, ImportExportResult, ExportProgressState } from './types'; +import { ModuleType, FileSystemItem, ImportModuleOutputFormat, ImportOptions, ExportOptions, ImportExportResult, ExportProgressState, ExportModuleOutputFormat } from './types'; import shim from '../../shim'; import { _ } from '../../locale'; import BaseItem from '../../models/BaseItem'; @@ -119,32 +119,32 @@ export default class InteropService { const exportModules = [ makeExportModule({ - format: 'jex', + format: ExportModuleOutputFormat.Jex, fileExtensions: ['jex'], target: FileSystemItem.File, description: _('Joplin Export File'), }, () => new InteropService_Exporter_Jex()), makeExportModule({ - format: 'raw', + format: ExportModuleOutputFormat.Raw, target: FileSystemItem.Directory, description: _('Joplin Export Directory'), }, () => new InteropService_Exporter_Raw()), makeExportModule({ - format: 'md', + format: ExportModuleOutputFormat.Markdown, target: FileSystemItem.Directory, description: _('Markdown'), }, () => new InteropService_Exporter_Md()), makeExportModule({ - format: 'md_frontmatter', + format: ExportModuleOutputFormat.MarkdownFrontMatter, target: FileSystemItem.Directory, description: _('Markdown + Front Matter'), }, () => new InteropService_Exporter_Md_frontmatter()), makeExportModule({ - format: 'html', + format: ExportModuleOutputFormat.Html, fileExtensions: ['html', 'htm'], target: FileSystemItem.File, isNoteArchive: false, @@ -153,7 +153,7 @@ export default class InteropService { }, dynamicRequireModuleFactory('./InteropService_Exporter_Html')), makeExportModule({ - format: 'html', + format: ExportModuleOutputFormat.Html, target: FileSystemItem.Directory, description: _('HTML Directory'), supportsMobile: false, @@ -301,7 +301,7 @@ export default class InteropService { public async export(options: ExportOptions): Promise { options = { - format: 'jex', + format: ExportModuleOutputFormat.Jex, ...options, }; diff --git a/packages/lib/services/interop/InteropService_Exporter_Html.test.ts b/packages/lib/services/interop/InteropService_Exporter_Html.test.ts index 0a80706ad..2f62a9989 100644 --- a/packages/lib/services/interop/InteropService_Exporter_Html.test.ts +++ b/packages/lib/services/interop/InteropService_Exporter_Html.test.ts @@ -6,7 +6,7 @@ import Note from '../../models/Note'; import * as fs from 'fs-extra'; import { tempFilePath } from '../../testing/test-utils'; import { ContentScriptType } from '../../services/plugins/api/types'; -import { FileSystemItem } from './types'; +import { ExportModuleOutputFormat, FileSystemItem } from './types'; import { readFile } from 'fs/promises'; async function recreateExportDir() { @@ -31,7 +31,7 @@ describe('interop/InteropService_Exporter_Html', () => { await service.export({ path: filePath, - format: 'html', + format: ExportModuleOutputFormat.Html, packIntoSingleFile: false, }); @@ -49,7 +49,7 @@ describe('interop/InteropService_Exporter_Html', () => { const dir = exportDir(); await service.export({ path: dir, - format: 'html', + format: ExportModuleOutputFormat.Html, target: FileSystemItem.Directory, }); @@ -106,7 +106,7 @@ describe('interop/InteropService_Exporter_Html', () => { await service.export({ path: filePath, - format: 'html', + format: ExportModuleOutputFormat.Html, packIntoSingleFile: false, plugins, }); @@ -130,7 +130,7 @@ describe('interop/InteropService_Exporter_Html', () => { await service.export({ path: filePath, - format: 'html', + format: ExportModuleOutputFormat.Html, packIntoSingleFile: true, target: FileSystemItem.File, }); diff --git a/packages/lib/services/interop/InteropService_Exporter_Md.test.ts b/packages/lib/services/interop/InteropService_Exporter_Md.test.ts index fc572c1d0..10773c57a 100644 --- a/packages/lib/services/interop/InteropService_Exporter_Md.test.ts +++ b/packages/lib/services/interop/InteropService_Exporter_Md.test.ts @@ -11,6 +11,7 @@ import { NoteEntity, ResourceEntity } from '../database/types.js'; import InteropService from './InteropService.js'; import { fileExtension } from '../../path-utils.js'; import { readdir } from 'fs/promises'; +import { ExportModuleOutputFormat } from './types.js'; describe('interop/InteropService_Exporter_Md', () => { @@ -440,7 +441,7 @@ describe('interop/InteropService_Exporter_Md', () => { await service.export({ path: exportDir(), - format: 'md', + format: ExportModuleOutputFormat.Markdown, }); const resourceFilename = (await fs.readdir(`${exportDir()}/_resources`))[0]; @@ -459,7 +460,7 @@ describe('interop/InteropService_Exporter_Md', () => { await service.export({ path: exportDir(), - format: 'md', + format: ExportModuleOutputFormat.Markdown, }); const note_body = await shim.fsDriver().readFile(`${exportDir()}/testing/mynote.md`); @@ -478,7 +479,7 @@ describe('interop/InteropService_Exporter_Md', () => { await service.export({ path: exportDir(), - format: 'md', + format: ExportModuleOutputFormat.Markdown, }); const files = await readdir(`${exportDir()}/_resources`); diff --git a/packages/lib/services/interop/InteropService_Exporter_Md_frontmatter.test.ts b/packages/lib/services/interop/InteropService_Exporter_Md_frontmatter.test.ts index 016a666b5..1bbc5c1a9 100644 --- a/packages/lib/services/interop/InteropService_Exporter_Md_frontmatter.test.ts +++ b/packages/lib/services/interop/InteropService_Exporter_Md_frontmatter.test.ts @@ -6,6 +6,7 @@ import Tag from '../../models/Tag'; import time from '../../time'; import { fieldOrder } from './InteropService_Exporter_Md_frontmatter'; import * as fs from 'fs-extra'; +import { ExportModuleOutputFormat } from './types'; async function recreateExportDir() { const dir = exportDir(); @@ -19,7 +20,7 @@ describe('interop/InteropService_Exporter_Md_frontmatter', () => { await service.export({ path: exportDir(), - format: 'md_frontmatter', + format: ExportModuleOutputFormat.MarkdownFrontMatter, }); return await fs.readFile(path, 'utf8'); diff --git a/packages/lib/services/interop/Module.test.ts b/packages/lib/services/interop/Module.test.ts index b8787fe99..90b570e8d 100644 --- a/packages/lib/services/interop/Module.test.ts +++ b/packages/lib/services/interop/Module.test.ts @@ -38,7 +38,7 @@ describe('Module', () => { it('should return correct default fullLabel for an ExportModule', () => { const testExportModule = makeExportModule({ - format: 'format_test_______TEST', + format: 'format_test_______TEST' as any, description: 'Testing...', }, () => new InteropService_Exporter_Base()); diff --git a/packages/lib/services/interop/Module.ts b/packages/lib/services/interop/Module.ts index 239cccd68..066711567 100644 --- a/packages/lib/services/interop/Module.ts +++ b/packages/lib/services/interop/Module.ts @@ -2,11 +2,10 @@ import { _ } from '../../locale'; import shim from '../../shim'; import InteropService_Exporter_Base from './InteropService_Exporter_Base'; import InteropService_Importer_Base from './InteropService_Importer_Base'; -import { ExportOptions, FileSystemItem, ImportModuleOutputFormat, ImportOptions, ModuleType } from './types'; +import { ExportModuleOutputFormat, ExportOptions, FileSystemItem, ImportModuleOutputFormat, ImportOptions, ModuleType } from './types'; // Metadata shared between importers and exporters. interface BaseMetadata { - format: string; fileExtensions: string[]; description: string; isDefault: boolean; @@ -26,6 +25,7 @@ interface BaseMetadata { interface ImportMetadata extends BaseMetadata { type: ModuleType.Importer; + format: string; sources: FileSystemItem[]; outputFormat: ImportModuleOutputFormat; @@ -37,6 +37,7 @@ export interface ImportModule extends ImportMetadata { interface ExportMetadata extends BaseMetadata { type: ModuleType.Exporter; + format: ExportModuleOutputFormat; target: FileSystemItem; } @@ -46,7 +47,6 @@ export interface ExportModule extends ExportMetadata { } const defaultBaseMetadata = { - format: '', fileExtensions: [] as string[], description: '', isNoteArchive: true, @@ -69,6 +69,7 @@ export const makeImportModule = ( ): ImportModule => { const importerDefaults: ImportMetadata = { ...defaultBaseMetadata, + format: '', type: ModuleType.Importer, sources: [], outputFormat: ImportModuleOutputFormat.Markdown, @@ -99,6 +100,7 @@ export const makeExportModule = ( ): ExportModule => { const exporterDefaults: ExportMetadata = { ...defaultBaseMetadata, + format: '' as any, type: ModuleType.Exporter, target: FileSystemItem.File, diff --git a/packages/lib/services/interop/types.ts b/packages/lib/services/interop/types.ts index 2d9a3ab4a..7df1a74c4 100644 --- a/packages/lib/services/interop/types.ts +++ b/packages/lib/services/interop/types.ts @@ -26,6 +26,17 @@ export enum ImportModuleOutputFormat { Html = 'html', } +export enum ExportModuleOutputFormat { + Enex = 'enex', + Html = 'html', + Jex = 'jex', + Markdown = 'md', + MarkdownFrontMatter = 'md_frontmatter', + Memory = 'memory', + Pdf = 'pdf', + Raw = 'raw', +} + export interface ImportOptions { path?: string; format?: string; @@ -44,7 +55,7 @@ export enum ExportProgressState { export type OnExportProgressCallback = (status: ExportProgressState, progress: number)=> void; export interface ExportOptions { - format?: string; + format?: ExportModuleOutputFormat; path?: string; sourceFolderIds?: string[]; sourceNoteIds?: string[]; diff --git a/packages/lib/services/plugins/api/JoplinInterop.ts b/packages/lib/services/plugins/api/JoplinInterop.ts index 464a96ed2..82977f4df 100644 --- a/packages/lib/services/plugins/api/JoplinInterop.ts +++ b/packages/lib/services/plugins/api/JoplinInterop.ts @@ -23,7 +23,7 @@ export default class JoplinInterop { public async registerExportModule(module: ExportModule) { const internalModule = makeExportModule({ - ...module, + ...module as any, type: ModuleType.Exporter, fileExtensions: module.fileExtensions ? module.fileExtensions : [], }, () => new InteropService_Exporter_Custom(module));