You've already forked joplin
							
							
				mirror of
				https://github.com/laurent22/joplin.git
				synced 2025-10-31 00:07:48 +02:00 
			
		
		
		
	Plugins: Added command to export folders and notes
This commit is contained in:
		| @@ -325,6 +325,12 @@ packages/app-desktop/bridge.js.map | ||||
| packages/app-desktop/commands/copyDevCommand.d.ts | ||||
| packages/app-desktop/commands/copyDevCommand.js | ||||
| packages/app-desktop/commands/copyDevCommand.js.map | ||||
| packages/app-desktop/commands/exportFolders.d.ts | ||||
| packages/app-desktop/commands/exportFolders.js | ||||
| packages/app-desktop/commands/exportFolders.js.map | ||||
| packages/app-desktop/commands/exportNotes.d.ts | ||||
| packages/app-desktop/commands/exportNotes.js | ||||
| packages/app-desktop/commands/exportNotes.js.map | ||||
| packages/app-desktop/commands/focusElement.d.ts | ||||
| packages/app-desktop/commands/focusElement.js | ||||
| packages/app-desktop/commands/focusElement.js.map | ||||
|   | ||||
							
								
								
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -317,6 +317,12 @@ packages/app-desktop/bridge.js.map | ||||
| packages/app-desktop/commands/copyDevCommand.d.ts | ||||
| packages/app-desktop/commands/copyDevCommand.js | ||||
| packages/app-desktop/commands/copyDevCommand.js.map | ||||
| packages/app-desktop/commands/exportFolders.d.ts | ||||
| packages/app-desktop/commands/exportFolders.js | ||||
| packages/app-desktop/commands/exportFolders.js.map | ||||
| packages/app-desktop/commands/exportNotes.d.ts | ||||
| packages/app-desktop/commands/exportNotes.js | ||||
| packages/app-desktop/commands/exportNotes.js.map | ||||
| packages/app-desktop/commands/focusElement.d.ts | ||||
| packages/app-desktop/commands/focusElement.js | ||||
| packages/app-desktop/commands/focusElement.js.map | ||||
|   | ||||
| @@ -310,6 +310,7 @@ | ||||
| 			"packages/app-mobile/lib/joplin-renderer/MdToHtml/rules/sanitize_html.js": true, | ||||
| 			"packages/app-mobile/lib/rnInjectedJs/": true, | ||||
| 			"packages/app-mobile/lib/sql-extensions/spellfix.so": true, | ||||
| 			"packages/generator-joplin/generators/app/templates/api/": true, | ||||
| 			"packages/app-mobile/node_modules/": true, | ||||
| 			"phpunit.xml": true, | ||||
| 			"Server/db*.sqlite/": true, | ||||
|   | ||||
| @@ -161,7 +161,7 @@ export default class InteropServiceHelper { | ||||
| 		const exportOptions: ExportOptions = {}; | ||||
| 		exportOptions.path = path; | ||||
| 		exportOptions.format = module.format; | ||||
| 		exportOptions.modulePath = module.path; | ||||
| 		// exportOptions.modulePath = module.path; | ||||
| 		exportOptions.target = module.target; | ||||
| 		exportOptions.includeConflicts = !!options.includeConflicts; | ||||
| 		if (options.sourceFolderIds) exportOptions.sourceFolderIds = options.sourceFolderIds; | ||||
|   | ||||
| @@ -42,15 +42,17 @@ const CssUtils = require('@joplin/lib/CssUtils'); | ||||
| // const populateDatabase = require('@joplin/lib/services/debug/populateDatabase').default; | ||||
|  | ||||
| const commands = [ | ||||
| 	require('./gui/NoteListControls/commands/focusSearch'), | ||||
| 	require('./gui/MainScreen/commands/editAlarm'), | ||||
| 	require('./gui/MainScreen/commands/exportPdf'), | ||||
| 	require('./gui/MainScreen/commands/hideModalMessage'), | ||||
| 	require('./gui/MainScreen/commands/moveToFolder'), | ||||
| 	require('./gui/MainScreen/commands/newNote'), | ||||
| 	require('./gui/MainScreen/commands/newFolder'), | ||||
| 	require('./gui/MainScreen/commands/newNote'), | ||||
| 	require('./gui/MainScreen/commands/newSubFolder'), | ||||
| 	require('./gui/MainScreen/commands/newTodo'), | ||||
| 	require('./gui/MainScreen/commands/openFolder'), | ||||
| 	require('./gui/MainScreen/commands/openNote'), | ||||
| 	require('./gui/MainScreen/commands/openTag'), | ||||
| 	require('./gui/MainScreen/commands/print'), | ||||
| 	require('./gui/MainScreen/commands/renameFolder'), | ||||
| 	require('./gui/MainScreen/commands/renameTag'), | ||||
| @@ -62,34 +64,34 @@ const commands = [ | ||||
| 	require('./gui/MainScreen/commands/showNoteProperties'), | ||||
| 	require('./gui/MainScreen/commands/showShareNoteDialog'), | ||||
| 	require('./gui/MainScreen/commands/showSpellCheckerMenu'), | ||||
| 	require('./gui/MainScreen/commands/toggleEditors'), | ||||
| 	require('./gui/MainScreen/commands/toggleLayoutMoveMode'), | ||||
| 	require('./gui/MainScreen/commands/toggleNoteList'), | ||||
| 	require('./gui/MainScreen/commands/toggleSideBar'), | ||||
| 	require('./gui/MainScreen/commands/toggleVisiblePanes'), | ||||
| 	require('./gui/MainScreen/commands/toggleEditors'), | ||||
| 	require('./gui/MainScreen/commands/openNote'), | ||||
| 	require('./gui/MainScreen/commands/openFolder'), | ||||
| 	require('./gui/MainScreen/commands/openTag'), | ||||
| 	require('./gui/MainScreen/commands/toggleLayoutMoveMode'), | ||||
| 	require('./gui/NoteEditor/commands/focusElementNoteBody'), | ||||
| 	require('./gui/NoteEditor/commands/focusElementNoteTitle'), | ||||
| 	require('./gui/NoteEditor/commands/showLocalSearch'), | ||||
| 	require('./gui/NoteEditor/commands/showRevisions'), | ||||
| 	require('./gui/NoteList/commands/focusElementNoteList'), | ||||
| 	require('./gui/NoteListControls/commands/focusSearch'), | ||||
| 	require('./gui/SideBar/commands/focusElementSideBar'), | ||||
| ]; | ||||
|  | ||||
| // Commands that are not tied to any particular component. | ||||
| // The runtime for these commands can be loaded when the app starts. | ||||
| const globalCommands = [ | ||||
| 	require('./commands/copyDevCommand'), | ||||
| 	require('./commands/exportFolders'), | ||||
| 	require('./commands/exportNotes'), | ||||
| 	require('./commands/focusElement'), | ||||
| 	require('./commands/openProfileDirectory'), | ||||
| 	require('./commands/startExternalEditing'), | ||||
| 	require('./commands/stopExternalEditing'), | ||||
| 	require('./commands/toggleExternalEditing'), | ||||
| 	require('./commands/copyDevCommand'), | ||||
| 	require('./commands/openProfileDirectory'), | ||||
| 	require('@joplin/lib/commands/synchronize'), | ||||
| 	require('@joplin/lib/commands/historyBackward'), | ||||
| 	require('@joplin/lib/commands/historyForward'), | ||||
| 	require('@joplin/lib/commands/synchronize'), | ||||
| ]; | ||||
|  | ||||
| const editorCommandDeclarations = require('./gui/NoteEditor/commands/editorCommandDeclarations').default; | ||||
|   | ||||
							
								
								
									
										22
									
								
								packages/app-desktop/commands/exportFolders.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								packages/app-desktop/commands/exportFolders.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| 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'; | ||||
|  | ||||
| export const declaration: CommandDeclaration = { | ||||
| 	name: 'exportFolders', | ||||
| }; | ||||
|  | ||||
| export const runtime = (): CommandRuntime => { | ||||
| 	return { | ||||
| 		execute: async (_context: any, folderIds: string[], format: string, targetDirectoryPath: string) => { | ||||
| 			const exportOptions: ExportOptions = { | ||||
| 				sourceFolderIds: folderIds, | ||||
| 				path: targetDirectoryPath, | ||||
| 				format: format, | ||||
| 				target: FileSystemItem.Directory, | ||||
| 			}; | ||||
|  | ||||
| 			return InteropService.instance().export(exportOptions); | ||||
| 		}, | ||||
| 	}; | ||||
| }; | ||||
							
								
								
									
										22
									
								
								packages/app-desktop/commands/exportNotes.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								packages/app-desktop/commands/exportNotes.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| 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'; | ||||
|  | ||||
| export const declaration: CommandDeclaration = { | ||||
| 	name: 'exportNotes', | ||||
| }; | ||||
|  | ||||
| export const runtime = (): CommandRuntime => { | ||||
| 	return { | ||||
| 		execute: async (_context: any, noteIds: string[], format: string, targetDirectoryPath: string) => { | ||||
| 			const exportOptions: ExportOptions = { | ||||
| 				path: targetDirectoryPath, | ||||
| 				format: format, | ||||
| 				target: FileSystemItem.Directory, | ||||
| 				sourceNoteIds: noteIds, | ||||
| 			}; | ||||
|  | ||||
| 			return InteropService.instance().export(exportOptions); | ||||
| 		}, | ||||
| 	}; | ||||
| }; | ||||
| @@ -216,21 +216,15 @@ export default class InteropService { | ||||
| 	 * https://github.com/laurent22/joplin/pull/1795#pullrequestreview-281574417 | ||||
| 	 */ | ||||
| 	newModuleFromPath_(type: ModuleType, options: any) { | ||||
| 		let modulePath = options && options.modulePath ? options.modulePath : ''; | ||||
|  | ||||
| 		if (!modulePath) { | ||||
| 			const moduleMetadata = this.findModuleByFormat_(type, options.format, options.target); | ||||
| 			if (!moduleMetadata) throw new Error(_('Cannot load "%s" module for format "%s" and target "%s"', type, options.format, options.target)); | ||||
| 			modulePath = this.modulePath(moduleMetadata); | ||||
| 		} | ||||
|  | ||||
| 		const moduleMetadata = this.findModuleByFormat_(type, options.format, options.target); | ||||
| 		if (!moduleMetadata) throw new Error(_('Cannot load "%s" module for format "%s" and target "%s"', type, options.format, options.target)); | ||||
|  | ||||
| 		let output = null; | ||||
|  | ||||
| 		if (moduleMetadata.isCustom) { | ||||
| 			output = this.newModuleFromCustomFactory(moduleMetadata); | ||||
| 		} else { | ||||
| 			const modulePath = this.modulePath(moduleMetadata); | ||||
| 			const ModuleClass = require(modulePath).default; | ||||
| 			output = new ModuleClass(); | ||||
| 		} | ||||
| @@ -238,6 +232,29 @@ export default class InteropService { | ||||
| 		output.setMetadata({ options, ...moduleMetadata }); | ||||
|  | ||||
| 		return output; | ||||
|  | ||||
| 		// let modulePath = options && options.modulePath ? options.modulePath : ''; | ||||
|  | ||||
| 		// if (!modulePath) { | ||||
| 		// 	const moduleMetadata = this.findModuleByFormat_(type, options.format, options.target); | ||||
| 		// 	if (!moduleMetadata) throw new Error(_('Cannot load "%s" module for format "%s" and target "%s"', type, options.format, options.target)); | ||||
| 		// 	modulePath = this.modulePath(moduleMetadata); | ||||
| 		// } | ||||
|  | ||||
| 		// const moduleMetadata = this.findModuleByFormat_(type, options.format, options.target); | ||||
|  | ||||
| 		// let output = null; | ||||
|  | ||||
| 		// if (moduleMetadata.isCustom) { | ||||
| 		// 	output = this.newModuleFromCustomFactory(moduleMetadata); | ||||
| 		// } else { | ||||
| 		// 	const ModuleClass = require(modulePath).default; | ||||
| 		// 	output = new ModuleClass(); | ||||
| 		// } | ||||
|  | ||||
| 		// output.setMetadata({ options, ...moduleMetadata }); | ||||
|  | ||||
| 		// return output; | ||||
| 	} | ||||
|  | ||||
| 	moduleByFileExtension_(type: ModuleType, ext: string) { | ||||
| @@ -280,15 +297,17 @@ export default class InteropService { | ||||
|  | ||||
| 		let result: ImportExportResult = { warnings: [] }; | ||||
|  | ||||
| 		let importer = null; | ||||
|  | ||||
| 		// let importer = null; | ||||
| 		// | ||||
| 		// Not certain the "modulePath" property still has any use at this point. Modules should be looked up | ||||
| 		// based on their format and outputFormat. | ||||
| 		if (options.modulePath) { | ||||
| 			importer = this.newModuleFromPath_(ModuleType.Importer, options); | ||||
| 		} else { | ||||
| 			importer = this.newModuleByFormat_(ModuleType.Importer, options.format, options.outputFormat); | ||||
| 		} | ||||
| 		// if (options.modulePath) { | ||||
| 		// 	importer = this.newModuleFromPath_(ModuleType.Importer, options); | ||||
| 		// } else { | ||||
| 		//	importer = this.newModuleByFormat_(ModuleType.Importer, options.format, options.outputFormat); | ||||
| 		// } | ||||
|  | ||||
| 		const importer = this.newModuleByFormat_(ModuleType.Importer, options.format, options.outputFormat); | ||||
|  | ||||
| 		await importer.init(options.path, options); | ||||
| 		result = await importer.exec(result); | ||||
|   | ||||
| @@ -38,7 +38,7 @@ export interface Module { | ||||
| 	format: string; | ||||
| 	fileExtensions: string[]; | ||||
| 	description: string; | ||||
| 	path?: string; | ||||
| 	// path?: string; | ||||
|  | ||||
| 	// Only applies to single file exporters or importers | ||||
| 	// It tells whether the format can package multiple notes into one file. | ||||
| @@ -80,7 +80,7 @@ export interface Module { | ||||
| export interface ImportOptions { | ||||
| 	path?: string; | ||||
| 	format?: string; | ||||
| 	modulePath?: string; | ||||
| 	// modulePath?: string; | ||||
| 	destinationFolderId?: string; | ||||
| 	destinationFolder?: any; | ||||
| 	outputFormat?: ImportModuleOutputFormat; | ||||
| @@ -91,7 +91,7 @@ export interface ExportOptions { | ||||
| 	path?: string; | ||||
| 	sourceFolderIds?: string[]; | ||||
| 	sourceNoteIds?: string[]; | ||||
| 	modulePath?: string; | ||||
| 	// modulePath?: string; | ||||
| 	target?: FileSystemItem; | ||||
| 	includeConflicts?: boolean; | ||||
| } | ||||
|   | ||||
| @@ -161,7 +161,7 @@ export interface ExportOptions { | ||||
| 	path?: string; | ||||
| 	sourceFolderIds?: string[]; | ||||
| 	sourceNoteIds?: string[]; | ||||
| 	modulePath?: string; | ||||
| 	// modulePath?: string; | ||||
| 	target?: FileSystemItem; | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user