diff --git a/.eslintignore b/.eslintignore index 8eddcaf960..76734040fb 100644 --- a/.eslintignore +++ b/.eslintignore @@ -64,7 +64,7 @@ packages/tools/PortableAppsLauncher packages/fork-* plugin_types/ readme/ -commands/index.ts +**/commands/index.ts # AUTO-GENERATED - EXCLUDED TYPESCRIPT BUILD packages/app-cli/app/LinkSelector.d.ts @@ -886,6 +886,9 @@ packages/lib/JoplinServerApi.js.map packages/lib/Logger.d.ts packages/lib/Logger.js packages/lib/Logger.js.map +packages/lib/ObjectUtils.d.ts +packages/lib/ObjectUtils.js +packages/lib/ObjectUtils.js.map packages/lib/PoorManIntervals.d.ts packages/lib/PoorManIntervals.js packages/lib/PoorManIntervals.js.map diff --git a/.gitignore b/.gitignore index 5b853f4aec..9cb006831f 100644 --- a/.gitignore +++ b/.gitignore @@ -871,6 +871,9 @@ packages/lib/JoplinServerApi.js.map packages/lib/Logger.d.ts packages/lib/Logger.js packages/lib/Logger.js.map +packages/lib/ObjectUtils.d.ts +packages/lib/ObjectUtils.js +packages/lib/ObjectUtils.js.map packages/lib/PoorManIntervals.d.ts packages/lib/PoorManIntervals.js packages/lib/PoorManIntervals.js.map diff --git a/packages/lib/ObjectUtils.js b/packages/lib/ObjectUtils.ts similarity index 66% rename from packages/lib/ObjectUtils.js rename to packages/lib/ObjectUtils.ts index e0b2664533..02fc566cf8 100644 --- a/packages/lib/ObjectUtils.js +++ b/packages/lib/ObjectUtils.ts @@ -1,6 +1,4 @@ -const ObjectUtils = {}; - -ObjectUtils.sortByValue = function(object) { +export function sortByValue(object: any) { const temp = []; for (const k in object) { if (!object.hasOwnProperty(k)) continue; @@ -19,16 +17,16 @@ ObjectUtils.sortByValue = function(object) { return v1 < v2 ? -1 : +1; }); - const output = {}; + const output: any = {}; for (let i = 0; i < temp.length; i++) { const item = temp[i]; output[item.key] = item.value; } return output; -}; +} -ObjectUtils.fieldsEqual = function(o1, o2) { +export function fieldsEqual(o1: any, o2: any) { if ((!o1 || !o2) && o1 !== o2) return false; for (const k in o1) { @@ -42,10 +40,10 @@ ObjectUtils.fieldsEqual = function(o1, o2) { if (c1.length !== c2.length) return false; return true; -}; +} -ObjectUtils.convertValuesToFunctions = function(o) { - const output = {}; +export function convertValuesToFunctions(o: any) { + const output: any = {}; for (const n in o) { if (!o.hasOwnProperty(n)) continue; output[n] = () => { @@ -53,11 +51,26 @@ ObjectUtils.convertValuesToFunctions = function(o) { }; } return output; -}; +} -ObjectUtils.isEmpty = function(o) { +export function isEmpty(o: any) { if (!o) return true; return Object.keys(o).length === 0 && o.constructor === Object; -}; +} -module.exports = ObjectUtils; +// export function isStringifiable(o:any):boolean { +// if (o === null || o === undefined) return true; + +// if (Array.isArray(o)) { +// for (const e of o) { +// if (!isStringifiable(e)) return false; +// } +// return true; +// } + +// if (typeof o === 'object') { + +// } + +// return true; +// } diff --git a/packages/lib/services/interop/InteropService_Importer_Base.ts b/packages/lib/services/interop/InteropService_Importer_Base.ts index 199ca63605..f44ac26356 100644 --- a/packages/lib/services/interop/InteropService_Importer_Base.ts +++ b/packages/lib/services/interop/InteropService_Importer_Base.ts @@ -5,27 +5,28 @@ import { ImportExportResult } from './types'; import Setting from '../../models/Setting'; export default class InteropService_Importer_Base { + private metadata_: any = null; protected sourcePath_: string = ''; protected options_: any = {}; - setMetadata(md: any) { + public setMetadata(md: any) { this.metadata_ = md; } - metadata() { + public metadata() { return this.metadata_; } - async init(sourcePath: string, options: any) { + public async init(sourcePath: string, options: any) { this.sourcePath_ = sourcePath; this.options_ = options; } // @ts-ignore - async exec(result: ImportExportResult): Promise {} + public async exec(result: ImportExportResult): Promise {} - async temporaryDirectory_(createIt: boolean) { + protected async temporaryDirectory_(createIt: boolean) { const md5 = require('md5'); const tempDir = `${Setting.value('tempDir')}/${md5(Math.random() + Date.now())}`; if (createIt) await require('fs-extra').mkdirp(tempDir); diff --git a/packages/lib/services/interop/InteropService_Importer_Custom.ts b/packages/lib/services/interop/InteropService_Importer_Custom.ts index e289b2e8ef..4d0c5641c1 100644 --- a/packages/lib/services/interop/InteropService_Importer_Custom.ts +++ b/packages/lib/services/interop/InteropService_Importer_Custom.ts @@ -5,15 +5,27 @@ export default class InteropService_Importer_Custom extends InteropService_Impor private module_: Module = null; - constructor(handler: Module) { + public constructor(handler: Module) { super(); this.module_ = handler; } - async exec(result: ImportExportResult): Promise { + public async exec(result: ImportExportResult): Promise { + // When passing the options to the plugin, we strip off any function + // because they won't serialized over ipc. + + const processedOptions: any = {}; + + if (this.options_) { + for (const [k, v] of Object.entries(this.options_)) { + if (typeof v === 'function') continue; + processedOptions[k] = v; + } + } + return this.module_.onExec({ sourcePath: this.sourcePath_, - options: this.options_, + options: processedOptions, warnings: result.warnings, }); }