From 4f5e52c363854ec18e3a4bc33b15450509eb21de Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 8 May 2023 14:59:27 +0100 Subject: [PATCH] update --- .eslintignore | 3 +- .gitignore | 3 +- packages/app-cli/app/command-settingschema.ts | 3 +- packages/app-desktop/.gitignore | 3 +- packages/app-desktop/bridge.ts | 48 ++++++++--------- .../app-desktop/{main.js => main.source.js} | 0 packages/app-desktop/package.json | 7 +++ .../app-desktop/rollup-main-html.config.js | 24 +++++++++ packages/app-desktop/rollup-main.config.js | 16 ++++++ packages/app-desktop/rollup.config.js | 14 ----- packages/lib/models/Setting.ts | 42 +++++++++++++-- packages/lib/models/settings/FileHandler.ts | 4 +- packages/lib/models/settings/types.ts | 2 + .../mergeGlobalAndLocalSettings.ts | 22 -------- .../splitGlobalAndLocalSettings.ts | 19 ------- yarn.lock | 53 ++++++++++++++++++- 16 files changed, 171 insertions(+), 92 deletions(-) rename packages/app-desktop/{main.js => main.source.js} (100%) create mode 100644 packages/app-desktop/rollup-main-html.config.js create mode 100644 packages/app-desktop/rollup-main.config.js delete mode 100644 packages/app-desktop/rollup.config.js create mode 100644 packages/lib/models/settings/types.ts delete mode 100644 packages/lib/services/profileConfig/mergeGlobalAndLocalSettings.ts delete mode 100644 packages/lib/services/profileConfig/splitGlobalAndLocalSettings.ts diff --git a/.eslintignore b/.eslintignore index 8f6ff9b75..30dfd26d1 100644 --- a/.eslintignore +++ b/.eslintignore @@ -551,6 +551,7 @@ packages/lib/models/SmartFilter.js packages/lib/models/Tag.js packages/lib/models/dateTimeFormats.test.js packages/lib/models/settings/FileHandler.js +packages/lib/models/settings/types.js packages/lib/models/utils/itemCanBeEncrypted.js packages/lib/models/utils/paginatedFeed.js packages/lib/models/utils/paginationToSql.js @@ -685,8 +686,6 @@ packages/lib/services/plugins/utils/validatePluginVersion.test.js packages/lib/services/profileConfig/index.js packages/lib/services/profileConfig/index.test.js packages/lib/services/profileConfig/initProfile.js -packages/lib/services/profileConfig/mergeGlobalAndLocalSettings.js -packages/lib/services/profileConfig/splitGlobalAndLocalSettings.js packages/lib/services/profileConfig/types.js packages/lib/services/rest/Api.js packages/lib/services/rest/Api.test.js diff --git a/.gitignore b/.gitignore index 5130fe6c1..e53e2fde9 100644 --- a/.gitignore +++ b/.gitignore @@ -537,6 +537,7 @@ packages/lib/models/SmartFilter.js packages/lib/models/Tag.js packages/lib/models/dateTimeFormats.test.js packages/lib/models/settings/FileHandler.js +packages/lib/models/settings/types.js packages/lib/models/utils/itemCanBeEncrypted.js packages/lib/models/utils/paginatedFeed.js packages/lib/models/utils/paginationToSql.js @@ -671,8 +672,6 @@ packages/lib/services/plugins/utils/validatePluginVersion.test.js packages/lib/services/profileConfig/index.js packages/lib/services/profileConfig/index.test.js packages/lib/services/profileConfig/initProfile.js -packages/lib/services/profileConfig/mergeGlobalAndLocalSettings.js -packages/lib/services/profileConfig/splitGlobalAndLocalSettings.js packages/lib/services/profileConfig/types.js packages/lib/services/rest/Api.js packages/lib/services/rest/Api.test.js diff --git a/packages/app-cli/app/command-settingschema.ts b/packages/app-cli/app/command-settingschema.ts index 46d52bfa0..69d8245f6 100644 --- a/packages/app-cli/app/command-settingschema.ts +++ b/packages/app-cli/app/command-settingschema.ts @@ -1,4 +1,5 @@ import Setting, { SettingStorage } from '@joplin/lib/models/Setting'; +import { schemaUrl } from '@joplin/lib/models/settings/types'; import { SettingItemType } from '@joplin/lib/services/plugins/api/types'; import shim from '@joplin/lib/shim'; @@ -38,7 +39,7 @@ class Command extends BaseCommand { public async action(args: any) { const schema: Record = { title: 'JSON schema for Joplin setting files', - '$id': Setting.schemaUrl, + '$id': schemaUrl, '$schema': 'https://json-schema.org/draft-07/schema#', type: 'object', properties: {}, diff --git a/packages/app-desktop/.gitignore b/packages/app-desktop/.gitignore index db9858d02..363600429 100644 --- a/packages/app-desktop/.gitignore +++ b/packages/app-desktop/.gitignore @@ -14,4 +14,5 @@ style.min.css build/lib/ vendor/* !vendor/loadEmojiLib.js -main-html.bundle.js \ No newline at end of file +main-html.bundle.js +main.js \ No newline at end of file diff --git a/packages/app-desktop/bridge.ts b/packages/app-desktop/bridge.ts index c78098151..f00a651c6 100644 --- a/packages/app-desktop/bridge.ts +++ b/packages/app-desktop/bridge.ts @@ -84,35 +84,35 @@ export class Bridge { // Perhaps the easiest would be to patch electron-context-menu to // support the renderer process again. Or possibly revert to an old // version of electron-context-menu. - public setupContextMenu(_spellCheckerMenuItemsHandler: Function) { - require('electron-context-menu')({ - allWindows: [this.window()], + // public setupContextMenu(_spellCheckerMenuItemsHandler: Function) { + // require('electron-context-menu')({ + // allWindows: [this.window()], - electronApp: this.electronApp(), + // electronApp: this.electronApp(), - shouldShowMenu: (_event: any, params: any) => { - // params.inputFieldType === 'none' when right-clicking the text - // editor. This is a bit of a hack to detect it because in this - // case we don't want to use the built-in context menu but a - // custom one. - return params.isEditable && params.inputFieldType !== 'none'; - }, + // shouldShowMenu: (_event: any, params: any) => { + // // params.inputFieldType === 'none' when right-clicking the text + // // editor. This is a bit of a hack to detect it because in this + // // case we don't want to use the built-in context menu but a + // // custom one. + // return params.isEditable && params.inputFieldType !== 'none'; + // }, - // menu: (actions: any, props: any) => { - // const items = spellCheckerMenuItemsHandler(props.misspelledWord, props.dictionarySuggestions); - // const spellCheckerMenuItems = items.map((item: any) => new MenuItem(item)); //SpellCheckerService.instance().contextMenuItems(props.misspelledWord, props.dictionarySuggestions).map((item: any) => new MenuItem(item)); + // // menu: (actions: any, props: any) => { + // // const items = spellCheckerMenuItemsHandler(props.misspelledWord, props.dictionarySuggestions); + // // const spellCheckerMenuItems = items.map((item: any) => new MenuItem(item)); //SpellCheckerService.instance().contextMenuItems(props.misspelledWord, props.dictionarySuggestions).map((item: any) => new MenuItem(item)); - // const output = [ - // actions.cut(), - // actions.copy(), - // actions.paste(), - // ...spellCheckerMenuItems, - // ]; + // // const output = [ + // // actions.cut(), + // // actions.copy(), + // // actions.paste(), + // // ...spellCheckerMenuItems, + // // ]; - // return output; - // }, - }); - } + // // return output; + // // }, + // }); + // } public window() { return this.electronWrapper_.window(); diff --git a/packages/app-desktop/main.js b/packages/app-desktop/main.source.js similarity index 100% rename from packages/app-desktop/main.js rename to packages/app-desktop/main.source.js diff --git a/packages/app-desktop/package.json b/packages/app-desktop/package.json index 5f3340083..73ad577d5 100644 --- a/packages/app-desktop/package.json +++ b/packages/app-desktop/package.json @@ -6,6 +6,8 @@ "private": true, "scripts": { "dist": "yarn run electronRebuild && npx electron-builder", + "pack-html": "rollup --config rollup-main-html.config.js", + "pack-main": "rollup --config rollup-main.config.js", "build": "gulp build", "postinstall": "yarn run build", "electronBuilder": "gulp electronBuilder", @@ -36,6 +38,9 @@ "build/images/**", "build/defaultPlugins/**" ], + "files": [ + "!node_modules/**/*" + ], "afterAllArtifactBuild": "./generateSha512.js", "asar": true, "asarUnpack": "./node_modules/node-notifier/vendor/**", @@ -110,6 +115,8 @@ "devDependencies": { "@joplin/tools": "~2.11", "@rollup/plugin-commonjs": "24.1.0", + "@rollup/plugin-json": "6.0.0", + "@rollup/plugin-node-resolve": "15.0.2", "@testing-library/react-hooks": "8.0.1", "@types/jest": "29.2.6", "@types/node": "18.11.18", diff --git a/packages/app-desktop/rollup-main-html.config.js b/packages/app-desktop/rollup-main-html.config.js new file mode 100644 index 000000000..e34c7d064 --- /dev/null +++ b/packages/app-desktop/rollup-main-html.config.js @@ -0,0 +1,24 @@ +const commonjs = require('@rollup/plugin-commonjs'); +const nodeResolve = require('@rollup/plugin-node-resolve'); +const pluginJson = require('@rollup/plugin-json'); + +module.exports = { + input: 'main-html.js', + output: { + file: 'main-html.bundle.js', + format: 'cjs', + }, + plugins: [ + nodeResolve(), + pluginJson(), + commonjs({ + dynamicRequireTargets: [ + 'codemirror/mode/python/python', + ], + }), + ], + external: [ + 'keytar', + 'fsevents', + ], +}; diff --git a/packages/app-desktop/rollup-main.config.js b/packages/app-desktop/rollup-main.config.js new file mode 100644 index 000000000..be5879eb3 --- /dev/null +++ b/packages/app-desktop/rollup-main.config.js @@ -0,0 +1,16 @@ +const commonjs = require('@rollup/plugin-commonjs'); +const nodeResolve = require('@rollup/plugin-node-resolve'); +const pluginJson = require('@rollup/plugin-json'); + +module.exports = { + input: 'main.source.js', + output: { + file: 'main.js', + format: 'cjs', + }, + plugins: [ + nodeResolve(), + pluginJson(), + commonjs(), + ], +}; diff --git a/packages/app-desktop/rollup.config.js b/packages/app-desktop/rollup.config.js deleted file mode 100644 index 13e9d62fa..000000000 --- a/packages/app-desktop/rollup.config.js +++ /dev/null @@ -1,14 +0,0 @@ -const commonjs = require('@rollup/plugin-commonjs'); - -module.exports = { - input: 'main-html.js', - output: { - file: 'main-html.bundle.js', - format: 'cjs', - }, - plugins: [commonjs({ - dynamicRequireTargets: [ - 'codemirror/mode/python/python', - ], - })], -}; diff --git a/packages/lib/models/Setting.ts b/packages/lib/models/Setting.ts index 173f3d0d6..b53e03370 100644 --- a/packages/lib/models/Setting.ts +++ b/packages/lib/models/Setting.ts @@ -7,8 +7,6 @@ import SyncTargetRegistry from '../SyncTargetRegistry'; import time from '../time'; import FileHandler, { SettingValues } from './settings/FileHandler'; import Logger from '../Logger'; -import mergeGlobalAndLocalSettings from '../services/profileConfig/mergeGlobalAndLocalSettings'; -import splitGlobalAndLocalSettings from '../services/profileConfig/splitGlobalAndLocalSettings'; const { sprintf } = require('sprintf-js'); const ObjectUtils = require('../ObjectUtils'); const { toTitleCase } = require('../string-utils.js'); @@ -16,6 +14,44 @@ const { rtrimSlashes, toSystemSlashes } = require('../path-utils'); const logger = Logger.create('models/Setting'); +const mergeGlobalAndLocalSettings = (rootSettings: Record, subProfileSettings: Record) => { + const output: Record = { ...subProfileSettings }; + + for (const k of Object.keys(output)) { + const md = Setting.settingMetadata(k); + if (md.isGlobal) { + delete output[k]; + if (k in rootSettings) output[k] = rootSettings[k]; + } + } + + for (const k of Object.keys(rootSettings)) { + const md = Setting.settingMetadata(k); + if (md.isGlobal) { + output[k] = rootSettings[k]; + } + } + + return output; +}; + +const splitGlobalAndLocalSettings = (settings: SettingValues) => { + const globalSettings: SettingValues = {}; + const localSettings: SettingValues = {}; + + for (const [k, v] of Object.entries(settings)) { + const md = Setting.settingMetadata(k); + + if (md.isGlobal) { + globalSettings[k] = v; + } else { + localSettings[k] = v; + } + } + + return { globalSettings, localSettings }; +}; + export enum SettingItemType { Int = 1, String = 2, @@ -219,8 +255,6 @@ const userSettingMigration: UserSettingMigration[] = [ class Setting extends BaseModel { - public static schemaUrl = 'https://joplinapp.org/schema/settings.json'; - // For backward compatibility public static TYPE_INT = SettingItemType.Int; public static TYPE_STRING = SettingItemType.String; diff --git a/packages/lib/models/settings/FileHandler.ts b/packages/lib/models/settings/FileHandler.ts index 7f6601354..64a9535fa 100644 --- a/packages/lib/models/settings/FileHandler.ts +++ b/packages/lib/models/settings/FileHandler.ts @@ -1,6 +1,6 @@ import Logger from '../../Logger'; import shim from '../../shim'; -import Setting from '../Setting'; +import { schemaUrl } from './types'; const logger = Logger.create('Settings'); @@ -41,7 +41,7 @@ export default class FileHandler { public async save(values: SettingValues) { const json = `${JSON.stringify({ - '$schema': Setting.schemaUrl, + '$schema': schemaUrl, ...values, }, null, '\t')}\n`; diff --git a/packages/lib/models/settings/types.ts b/packages/lib/models/settings/types.ts new file mode 100644 index 000000000..34cb61213 --- /dev/null +++ b/packages/lib/models/settings/types.ts @@ -0,0 +1,2 @@ +// eslint-disable-next-line import/prefer-default-export +export const schemaUrl = 'https://joplinapp.org/schema/settings.json'; diff --git a/packages/lib/services/profileConfig/mergeGlobalAndLocalSettings.ts b/packages/lib/services/profileConfig/mergeGlobalAndLocalSettings.ts deleted file mode 100644 index e5dfacf4c..000000000 --- a/packages/lib/services/profileConfig/mergeGlobalAndLocalSettings.ts +++ /dev/null @@ -1,22 +0,0 @@ -import Setting from '../../models/Setting'; - -export default (rootSettings: Record, subProfileSettings: Record) => { - const output: Record = { ...subProfileSettings }; - - for (const k of Object.keys(output)) { - const md = Setting.settingMetadata(k); - if (md.isGlobal) { - delete output[k]; - if (k in rootSettings) output[k] = rootSettings[k]; - } - } - - for (const k of Object.keys(rootSettings)) { - const md = Setting.settingMetadata(k); - if (md.isGlobal) { - output[k] = rootSettings[k]; - } - } - - return output; -}; diff --git a/packages/lib/services/profileConfig/splitGlobalAndLocalSettings.ts b/packages/lib/services/profileConfig/splitGlobalAndLocalSettings.ts deleted file mode 100644 index c4a19660c..000000000 --- a/packages/lib/services/profileConfig/splitGlobalAndLocalSettings.ts +++ /dev/null @@ -1,19 +0,0 @@ -import Setting from '../../models/Setting'; -import { SettingValues } from '../../models/settings/FileHandler'; - -export default (settings: SettingValues) => { - const globalSettings: SettingValues = {}; - const localSettings: SettingValues = {}; - - for (const [k, v] of Object.entries(settings)) { - const md = Setting.settingMetadata(k); - - if (md.isGlobal) { - globalSettings[k] = v; - } else { - localSettings[k] = v; - } - } - - return { globalSettings, localSettings }; -}; diff --git a/yarn.lock b/yarn.lock index 3c5e8d28a..e3e02c24a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6254,6 +6254,8 @@ __metadata: "@joplin/renderer": ~2.11 "@joplin/tools": ~2.11 "@rollup/plugin-commonjs": 24.1.0 + "@rollup/plugin-json": 6.0.0 + "@rollup/plugin-node-resolve": 15.0.2 "@testing-library/react-hooks": 8.0.1 "@types/jest": 29.2.6 "@types/node": 18.11.18 @@ -8827,6 +8829,39 @@ __metadata: languageName: node linkType: hard +"@rollup/plugin-json@npm:6.0.0": + version: 6.0.0 + resolution: "@rollup/plugin-json@npm:6.0.0" + dependencies: + "@rollup/pluginutils": ^5.0.1 + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + checksum: 77cfc941edaf77a5307977704ffaba706d83bea66f265b2b68f14be2a0af6d08b0fb1b04fdd773146c84cc70938ff64b00ae946808fd6ac057058af824d78128 + languageName: node + linkType: hard + +"@rollup/plugin-node-resolve@npm:15.0.2": + version: 15.0.2 + resolution: "@rollup/plugin-node-resolve@npm:15.0.2" + dependencies: + "@rollup/pluginutils": ^5.0.1 + "@types/resolve": 1.20.2 + deepmerge: ^4.2.2 + is-builtin-module: ^3.2.1 + is-module: ^1.0.0 + resolve: ^1.22.1 + peerDependencies: + rollup: ^2.78.0||^3.0.0 + peerDependenciesMeta: + rollup: + optional: true + checksum: 328eafee06ff967a36441b55e77fbd0d4f599d256e5d1977800ee71915846c46bc1b6185df35c7b512ad2b4023b05b65a332be77b8b00b9d8a20f87d056b8166 + languageName: node + linkType: hard + "@rollup/pluginutils@npm:^5.0.1": version: 5.0.2 resolution: "@rollup/pluginutils@npm:5.0.2" @@ -9931,6 +9966,13 @@ __metadata: languageName: node linkType: hard +"@types/resolve@npm:1.20.2": + version: 1.20.2 + resolution: "@types/resolve@npm:1.20.2" + checksum: 61c2cad2499ffc8eab36e3b773945d337d848d3ac6b7b0a87c805ba814bc838ef2f262fc0f109bfd8d2e0898ff8bd80ad1025f9ff64f1f71d3d4294c9f14e5f6 + languageName: node + linkType: hard + "@types/responselike@npm:*, @types/responselike@npm:^1.0.0": version: 1.0.0 resolution: "@types/responselike@npm:1.0.0" @@ -12949,7 +12991,7 @@ __metadata: languageName: node linkType: hard -"builtin-modules@npm:3.3.0": +"builtin-modules@npm:3.3.0, builtin-modules@npm:^3.3.0": version: 3.3.0 resolution: "builtin-modules@npm:3.3.0" checksum: db021755d7ed8be048f25668fe2117620861ef6703ea2c65ed2779c9e3636d5c3b82325bd912244293959ff3ae303afa3471f6a15bf5060c103e4cc3a839749d @@ -22222,6 +22264,15 @@ __metadata: languageName: node linkType: hard +"is-builtin-module@npm:^3.2.1": + version: 3.2.1 + resolution: "is-builtin-module@npm:3.2.1" + dependencies: + builtin-modules: ^3.3.0 + checksum: e8f0ffc19a98240bda9c7ada84d846486365af88d14616e737d280d378695c8c448a621dcafc8332dbf0fcd0a17b0763b845400709963fa9151ddffece90ae88 + languageName: node + linkType: hard + "is-callable@npm:^1.1.3, is-callable@npm:^1.1.4, is-callable@npm:^1.2.4": version: 1.2.4 resolution: "is-callable@npm:1.2.4"