From c529b972e3fd7ebbb5383e6f1f8423b90ae3e69d Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sat, 4 Sep 2021 13:43:25 +0100 Subject: [PATCH] Chore: Automatically create command index for desktop app --- .eslintignore | 27 ++++++- .gitignore | 27 ++++++- gulpfile.js | 1 + package.json | 1 + packages/app-desktop/app.ts | 70 ++++--------------- packages/app-desktop/commands/index.ts | 29 ++++++++ .../app-desktop/gui/MainScreen/MainScreen.tsx | 34 +-------- .../gui/MainScreen/commands/index.ts | 65 +++++++++++++++++ .../gui/NoteEditor/commands/index.ts | 15 ++++ .../editorCommandDeclarations.ts | 0 .../utils/useWindowCommandHandler.ts | 2 +- .../gui/NoteList/commands/index.ts | 9 +++ .../gui/NoteListControls/commands/index.ts | 9 +++ .../app-desktop/gui/Sidebar/commands/index.ts | 9 +++ packages/app-desktop/gulpfile.js | 2 + packages/lib/commands/index.ts | 13 ++++ .../tools/gulp/tasks/buildCommandIndex.js | 56 +++++++++++++++ packages/tools/gulp/utils.js | 16 +++++ 18 files changed, 289 insertions(+), 96 deletions(-) create mode 100644 packages/app-desktop/commands/index.ts create mode 100644 packages/app-desktop/gui/MainScreen/commands/index.ts create mode 100644 packages/app-desktop/gui/NoteEditor/commands/index.ts rename packages/app-desktop/gui/NoteEditor/{commands => }/editorCommandDeclarations.ts (100%) create mode 100644 packages/app-desktop/gui/NoteList/commands/index.ts create mode 100644 packages/app-desktop/gui/NoteListControls/commands/index.ts create mode 100644 packages/app-desktop/gui/Sidebar/commands/index.ts create mode 100644 packages/lib/commands/index.ts create mode 100644 packages/tools/gulp/tasks/buildCommandIndex.js diff --git a/.eslintignore b/.eslintignore index 1b1440e6c..608e283f4 100644 --- a/.eslintignore +++ b/.eslintignore @@ -141,6 +141,9 @@ 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 +packages/app-desktop/commands/index.d.ts +packages/app-desktop/commands/index.js +packages/app-desktop/commands/index.js.map packages/app-desktop/commands/openProfileDirectory.d.ts packages/app-desktop/commands/openProfileDirectory.js packages/app-desktop/commands/openProfileDirectory.js.map @@ -246,6 +249,9 @@ packages/app-desktop/gui/MainScreen/commands/gotoAnything.js.map packages/app-desktop/gui/MainScreen/commands/hideModalMessage.d.ts packages/app-desktop/gui/MainScreen/commands/hideModalMessage.js packages/app-desktop/gui/MainScreen/commands/hideModalMessage.js.map +packages/app-desktop/gui/MainScreen/commands/index.d.ts +packages/app-desktop/gui/MainScreen/commands/index.js +packages/app-desktop/gui/MainScreen/commands/index.js.map packages/app-desktop/gui/MainScreen/commands/moveToFolder.d.ts packages/app-desktop/gui/MainScreen/commands/moveToFolder.js packages/app-desktop/gui/MainScreen/commands/moveToFolder.js.map @@ -402,21 +408,24 @@ packages/app-desktop/gui/NoteEditor/NoteEditor.js.map packages/app-desktop/gui/NoteEditor/NoteTitle/NoteTitleBar.d.ts packages/app-desktop/gui/NoteEditor/NoteTitle/NoteTitleBar.js packages/app-desktop/gui/NoteEditor/NoteTitle/NoteTitleBar.js.map -packages/app-desktop/gui/NoteEditor/commands/editorCommandDeclarations.d.ts -packages/app-desktop/gui/NoteEditor/commands/editorCommandDeclarations.js -packages/app-desktop/gui/NoteEditor/commands/editorCommandDeclarations.js.map packages/app-desktop/gui/NoteEditor/commands/focusElementNoteBody.d.ts packages/app-desktop/gui/NoteEditor/commands/focusElementNoteBody.js packages/app-desktop/gui/NoteEditor/commands/focusElementNoteBody.js.map packages/app-desktop/gui/NoteEditor/commands/focusElementNoteTitle.d.ts packages/app-desktop/gui/NoteEditor/commands/focusElementNoteTitle.js packages/app-desktop/gui/NoteEditor/commands/focusElementNoteTitle.js.map +packages/app-desktop/gui/NoteEditor/commands/index.d.ts +packages/app-desktop/gui/NoteEditor/commands/index.js +packages/app-desktop/gui/NoteEditor/commands/index.js.map packages/app-desktop/gui/NoteEditor/commands/showLocalSearch.d.ts packages/app-desktop/gui/NoteEditor/commands/showLocalSearch.js packages/app-desktop/gui/NoteEditor/commands/showLocalSearch.js.map packages/app-desktop/gui/NoteEditor/commands/showRevisions.d.ts packages/app-desktop/gui/NoteEditor/commands/showRevisions.js packages/app-desktop/gui/NoteEditor/commands/showRevisions.js.map +packages/app-desktop/gui/NoteEditor/editorCommandDeclarations.d.ts +packages/app-desktop/gui/NoteEditor/editorCommandDeclarations.js +packages/app-desktop/gui/NoteEditor/editorCommandDeclarations.js.map packages/app-desktop/gui/NoteEditor/styles/index.d.ts packages/app-desktop/gui/NoteEditor/styles/index.js packages/app-desktop/gui/NoteEditor/styles/index.js.map @@ -471,12 +480,18 @@ packages/app-desktop/gui/NoteList/NoteList.js.map packages/app-desktop/gui/NoteList/commands/focusElementNoteList.d.ts packages/app-desktop/gui/NoteList/commands/focusElementNoteList.js packages/app-desktop/gui/NoteList/commands/focusElementNoteList.js.map +packages/app-desktop/gui/NoteList/commands/index.d.ts +packages/app-desktop/gui/NoteList/commands/index.js +packages/app-desktop/gui/NoteList/commands/index.js.map packages/app-desktop/gui/NoteListControls/NoteListControls.d.ts packages/app-desktop/gui/NoteListControls/NoteListControls.js packages/app-desktop/gui/NoteListControls/NoteListControls.js.map packages/app-desktop/gui/NoteListControls/commands/focusSearch.d.ts packages/app-desktop/gui/NoteListControls/commands/focusSearch.js packages/app-desktop/gui/NoteListControls/commands/focusSearch.js.map +packages/app-desktop/gui/NoteListControls/commands/index.d.ts +packages/app-desktop/gui/NoteListControls/commands/index.js +packages/app-desktop/gui/NoteListControls/commands/index.js.map packages/app-desktop/gui/NoteListItem.d.ts packages/app-desktop/gui/NoteListItem.js packages/app-desktop/gui/NoteListItem.js.map @@ -573,6 +588,9 @@ packages/app-desktop/gui/Sidebar/Sidebar.js.map packages/app-desktop/gui/Sidebar/commands/focusElementSideBar.d.ts packages/app-desktop/gui/Sidebar/commands/focusElementSideBar.js packages/app-desktop/gui/Sidebar/commands/focusElementSideBar.js.map +packages/app-desktop/gui/Sidebar/commands/index.d.ts +packages/app-desktop/gui/Sidebar/commands/index.js +packages/app-desktop/gui/Sidebar/commands/index.js.map packages/app-desktop/gui/Sidebar/styles/index.d.ts packages/app-desktop/gui/Sidebar/styles/index.js packages/app-desktop/gui/Sidebar/styles/index.js.map @@ -900,6 +918,9 @@ packages/lib/commands/historyBackward.js.map packages/lib/commands/historyForward.d.ts packages/lib/commands/historyForward.js packages/lib/commands/historyForward.js.map +packages/lib/commands/index.d.ts +packages/lib/commands/index.js +packages/lib/commands/index.js.map packages/lib/commands/synchronize.d.ts packages/lib/commands/synchronize.js packages/lib/commands/synchronize.js.map diff --git a/.gitignore b/.gitignore index a2a04558e..5b853f4ae 100644 --- a/.gitignore +++ b/.gitignore @@ -127,6 +127,9 @@ 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 +packages/app-desktop/commands/index.d.ts +packages/app-desktop/commands/index.js +packages/app-desktop/commands/index.js.map packages/app-desktop/commands/openProfileDirectory.d.ts packages/app-desktop/commands/openProfileDirectory.js packages/app-desktop/commands/openProfileDirectory.js.map @@ -232,6 +235,9 @@ packages/app-desktop/gui/MainScreen/commands/gotoAnything.js.map packages/app-desktop/gui/MainScreen/commands/hideModalMessage.d.ts packages/app-desktop/gui/MainScreen/commands/hideModalMessage.js packages/app-desktop/gui/MainScreen/commands/hideModalMessage.js.map +packages/app-desktop/gui/MainScreen/commands/index.d.ts +packages/app-desktop/gui/MainScreen/commands/index.js +packages/app-desktop/gui/MainScreen/commands/index.js.map packages/app-desktop/gui/MainScreen/commands/moveToFolder.d.ts packages/app-desktop/gui/MainScreen/commands/moveToFolder.js packages/app-desktop/gui/MainScreen/commands/moveToFolder.js.map @@ -388,21 +394,24 @@ packages/app-desktop/gui/NoteEditor/NoteEditor.js.map packages/app-desktop/gui/NoteEditor/NoteTitle/NoteTitleBar.d.ts packages/app-desktop/gui/NoteEditor/NoteTitle/NoteTitleBar.js packages/app-desktop/gui/NoteEditor/NoteTitle/NoteTitleBar.js.map -packages/app-desktop/gui/NoteEditor/commands/editorCommandDeclarations.d.ts -packages/app-desktop/gui/NoteEditor/commands/editorCommandDeclarations.js -packages/app-desktop/gui/NoteEditor/commands/editorCommandDeclarations.js.map packages/app-desktop/gui/NoteEditor/commands/focusElementNoteBody.d.ts packages/app-desktop/gui/NoteEditor/commands/focusElementNoteBody.js packages/app-desktop/gui/NoteEditor/commands/focusElementNoteBody.js.map packages/app-desktop/gui/NoteEditor/commands/focusElementNoteTitle.d.ts packages/app-desktop/gui/NoteEditor/commands/focusElementNoteTitle.js packages/app-desktop/gui/NoteEditor/commands/focusElementNoteTitle.js.map +packages/app-desktop/gui/NoteEditor/commands/index.d.ts +packages/app-desktop/gui/NoteEditor/commands/index.js +packages/app-desktop/gui/NoteEditor/commands/index.js.map packages/app-desktop/gui/NoteEditor/commands/showLocalSearch.d.ts packages/app-desktop/gui/NoteEditor/commands/showLocalSearch.js packages/app-desktop/gui/NoteEditor/commands/showLocalSearch.js.map packages/app-desktop/gui/NoteEditor/commands/showRevisions.d.ts packages/app-desktop/gui/NoteEditor/commands/showRevisions.js packages/app-desktop/gui/NoteEditor/commands/showRevisions.js.map +packages/app-desktop/gui/NoteEditor/editorCommandDeclarations.d.ts +packages/app-desktop/gui/NoteEditor/editorCommandDeclarations.js +packages/app-desktop/gui/NoteEditor/editorCommandDeclarations.js.map packages/app-desktop/gui/NoteEditor/styles/index.d.ts packages/app-desktop/gui/NoteEditor/styles/index.js packages/app-desktop/gui/NoteEditor/styles/index.js.map @@ -457,12 +466,18 @@ packages/app-desktop/gui/NoteList/NoteList.js.map packages/app-desktop/gui/NoteList/commands/focusElementNoteList.d.ts packages/app-desktop/gui/NoteList/commands/focusElementNoteList.js packages/app-desktop/gui/NoteList/commands/focusElementNoteList.js.map +packages/app-desktop/gui/NoteList/commands/index.d.ts +packages/app-desktop/gui/NoteList/commands/index.js +packages/app-desktop/gui/NoteList/commands/index.js.map packages/app-desktop/gui/NoteListControls/NoteListControls.d.ts packages/app-desktop/gui/NoteListControls/NoteListControls.js packages/app-desktop/gui/NoteListControls/NoteListControls.js.map packages/app-desktop/gui/NoteListControls/commands/focusSearch.d.ts packages/app-desktop/gui/NoteListControls/commands/focusSearch.js packages/app-desktop/gui/NoteListControls/commands/focusSearch.js.map +packages/app-desktop/gui/NoteListControls/commands/index.d.ts +packages/app-desktop/gui/NoteListControls/commands/index.js +packages/app-desktop/gui/NoteListControls/commands/index.js.map packages/app-desktop/gui/NoteListItem.d.ts packages/app-desktop/gui/NoteListItem.js packages/app-desktop/gui/NoteListItem.js.map @@ -559,6 +574,9 @@ packages/app-desktop/gui/Sidebar/Sidebar.js.map packages/app-desktop/gui/Sidebar/commands/focusElementSideBar.d.ts packages/app-desktop/gui/Sidebar/commands/focusElementSideBar.js packages/app-desktop/gui/Sidebar/commands/focusElementSideBar.js.map +packages/app-desktop/gui/Sidebar/commands/index.d.ts +packages/app-desktop/gui/Sidebar/commands/index.js +packages/app-desktop/gui/Sidebar/commands/index.js.map packages/app-desktop/gui/Sidebar/styles/index.d.ts packages/app-desktop/gui/Sidebar/styles/index.js packages/app-desktop/gui/Sidebar/styles/index.js.map @@ -886,6 +904,9 @@ packages/lib/commands/historyBackward.js.map packages/lib/commands/historyForward.d.ts packages/lib/commands/historyForward.js packages/lib/commands/historyForward.js.map +packages/lib/commands/index.d.ts +packages/lib/commands/index.js +packages/lib/commands/index.js.map packages/lib/commands/synchronize.d.ts packages/lib/commands/synchronize.js packages/lib/commands/synchronize.js.map diff --git a/gulpfile.js b/gulpfile.js index 7925460fb..f3c542b62 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,6 +5,7 @@ const tasks = { // copyLib: require('./packages/tools/gulp/tasks/copyLib'), // tsc: require('./packages/tools/gulp/tasks/tsc'), updateIgnoredTypeScriptBuild: require('./packages/tools/gulp/tasks/updateIgnoredTypeScriptBuild'), + buildCommandIndex: require('./packages/tools/gulp/tasks/buildCommandIndex'), // deleteBuildDirs: require('./packages/tools/gulp/tasks/deleteBuildDirs'), completePublishAll: { fn: async () => { diff --git a/package.json b/package.json index 2448f4edf..1ab940b48 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "bootstrapServerOnly": "lerna bootstrap --force-local --no-ci --include-dependents --include-dependencies --scope @joplin/server", "build": "lerna run build && npm run tsc", "buildApiDoc": "npm start --prefix=packages/app-cli -- apidoc ../../readme/api/references/rest_api.md", + "buildCommandIndex": "gulp buildCommandIndex", "buildDoc": "./packages/tools/build-all.sh", "buildPluginDoc": "typedoc --name 'Joplin Plugin API Documentation' --mode file -theme './Assets/PluginDocTheme/' --readme './Assets/PluginDocTheme/index.md' --excludeNotExported --excludeExternals --excludePrivate --excludeProtected --out docs/api/references/plugin_api packages/lib/services/plugins/api/", "buildSettingJsonSchema": "npm start --prefix=packages/app-cli -- settingschema ../../docs/schema/settings.json", diff --git a/packages/app-desktop/app.ts b/packages/app-desktop/app.ts index 081283b15..75076020f 100644 --- a/packages/app-desktop/app.ts +++ b/packages/app-desktop/app.ts @@ -38,68 +38,26 @@ const PluginManager = require('@joplin/lib/services/PluginManager'); import RevisionService from '@joplin/lib/services/RevisionService'; import MigrationService from '@joplin/lib/services/MigrationService'; import { loadCustomCss, injectCustomStyles } from '@joplin/lib/CssUtils'; +import mainScreenCommands from './gui/MainScreen/commands/index'; +import noteEditorCommands from './gui/NoteEditor/commands/index'; +import noteListCommands from './gui/NoteList/commands/index'; +import noteListControlsCommands from './gui/NoteListControls/commands/index'; +import sidebarCommands from './gui/Sidebar/commands/index'; +import appCommands from './commands/index'; +import libCommands from '@joplin/lib/commands/index'; // import populateDatabase from '@joplin/lib/services/debug/populateDatabase'; -const commands = [ - require('./gui/MainScreen/commands/editAlarm'), - require('./gui/MainScreen/commands/exportPdf'), - require('./gui/MainScreen/commands/gotoAnything'), - require('./gui/MainScreen/commands/commandPalette'), - require('./gui/MainScreen/commands/hideModalMessage'), - require('./gui/MainScreen/commands/moveToFolder'), - 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'), - require('./gui/MainScreen/commands/search'), - require('./gui/MainScreen/commands/setTags'), - require('./gui/MainScreen/commands/showModalMessage'), - require('./gui/MainScreen/commands/showNoteContentProperties'), - require('./gui/MainScreen/commands/showNoteProperties'), - require('./gui/MainScreen/commands/showPrompt'), - require('./gui/MainScreen/commands/showShareFolderDialog'), - 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/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'), -]; +const commands = mainScreenCommands + .concat(noteEditorCommands) + .concat(noteListCommands) + .concat(noteListControlsCommands) + .concat(sidebarCommands); // 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/replaceMisspelling'), - require('./commands/startExternalEditing'), - require('./commands/stopExternalEditing'), - require('./commands/toggleExternalEditing'), - require('./commands/toggleSafeMode'), - require('./commands/restoreNoteRevision'), - require('@joplin/lib/commands/historyBackward'), - require('@joplin/lib/commands/historyForward'), - require('@joplin/lib/commands/synchronize'), -]; +const globalCommands = appCommands.concat(libCommands); -import editorCommandDeclarations from './gui/NoteEditor/commands/editorCommandDeclarations'; +import editorCommandDeclarations from './gui/NoteEditor/editorCommandDeclarations'; import ShareService from '@joplin/lib/services/share/ShareService'; import checkForUpdates from './checkForUpdates'; diff --git a/packages/app-desktop/commands/index.ts b/packages/app-desktop/commands/index.ts new file mode 100644 index 000000000..99a1d55fd --- /dev/null +++ b/packages/app-desktop/commands/index.ts @@ -0,0 +1,29 @@ +// AUTO-GENERATED using `gulp buildCommandIndex` +import * as copyDevCommand from './copyDevCommand'; +import * as exportFolders from './exportFolders'; +import * as exportNotes from './exportNotes'; +import * as focusElement from './focusElement'; +import * as openProfileDirectory from './openProfileDirectory'; +import * as replaceMisspelling from './replaceMisspelling'; +import * as restoreNoteRevision from './restoreNoteRevision'; +import * as startExternalEditing from './startExternalEditing'; +import * as stopExternalEditing from './stopExternalEditing'; +import * as toggleExternalEditing from './toggleExternalEditing'; +import * as toggleSafeMode from './toggleSafeMode'; + +const index: any[] = [ + copyDevCommand, + exportFolders, + exportNotes, + focusElement, + openProfileDirectory, + replaceMisspelling, + restoreNoteRevision, + startExternalEditing, + stopExternalEditing, + toggleExternalEditing, + toggleSafeMode, +]; + +export default index; +// AUTO-GENERATED using `gulp buildCommandIndex` diff --git a/packages/app-desktop/gui/MainScreen/MainScreen.tsx b/packages/app-desktop/gui/MainScreen/MainScreen.tsx index ed3a60f22..d27fee187 100644 --- a/packages/app-desktop/gui/MainScreen/MainScreen.tsx +++ b/packages/app-desktop/gui/MainScreen/MainScreen.tsx @@ -37,6 +37,7 @@ import { reg } from '@joplin/lib/registry'; import removeKeylessItems from '../ResizableLayout/utils/removeKeylessItems'; import { localSyncInfoFromState } from '@joplin/lib/services/synchronizer/syncInfoUtils'; import { showMissingMasterKeyMessage } from '@joplin/lib/services/e2ee/utils'; +import commands from './commands/index'; const { connect } = require('react-redux'); const { PromptDialog } = require('../PromptDialog.min.js'); @@ -110,39 +111,6 @@ const defaultLayout: LayoutItem = { ], }; -const commands = [ - require('./commands/editAlarm'), - require('./commands/exportPdf'), - require('./commands/gotoAnything'), - require('./commands/commandPalette'), - require('./commands/hideModalMessage'), - require('./commands/moveToFolder'), - require('./commands/newFolder'), - require('./commands/newNote'), - require('./commands/newSubFolder'), - require('./commands/newTodo'), - require('./commands/openFolder'), - require('./commands/openNote'), - require('./commands/openTag'), - require('./commands/print'), - require('./commands/renameFolder'), - require('./commands/renameTag'), - require('./commands/search'), - require('./commands/setTags'), - require('./commands/showModalMessage'), - require('./commands/showNoteContentProperties'), - require('./commands/showNoteProperties'), - require('./commands/showPrompt'), - require('./commands/showShareFolderDialog'), - require('./commands/showShareNoteDialog'), - require('./commands/showSpellCheckerMenu'), - require('./commands/toggleEditors'), - require('./commands/toggleLayoutMoveMode'), - require('./commands/toggleNoteList'), - require('./commands/toggleSideBar'), - require('./commands/toggleVisiblePanes'), -]; - class MainScreenComponent extends React.Component { private waitForNotesSavedIID_: any; diff --git a/packages/app-desktop/gui/MainScreen/commands/index.ts b/packages/app-desktop/gui/MainScreen/commands/index.ts new file mode 100644 index 000000000..a16f51aad --- /dev/null +++ b/packages/app-desktop/gui/MainScreen/commands/index.ts @@ -0,0 +1,65 @@ +// AUTO-GENERATED using `gulp buildCommandIndex` +import * as commandPalette from './commandPalette'; +import * as editAlarm from './editAlarm'; +import * as exportPdf from './exportPdf'; +import * as gotoAnything from './gotoAnything'; +import * as hideModalMessage from './hideModalMessage'; +import * as moveToFolder from './moveToFolder'; +import * as newFolder from './newFolder'; +import * as newNote from './newNote'; +import * as newSubFolder from './newSubFolder'; +import * as newTodo from './newTodo'; +import * as openFolder from './openFolder'; +import * as openNote from './openNote'; +import * as openTag from './openTag'; +import * as print from './print'; +import * as renameFolder from './renameFolder'; +import * as renameTag from './renameTag'; +import * as search from './search'; +import * as setTags from './setTags'; +import * as showNoteContentProperties from './showNoteContentProperties'; +import * as showNoteProperties from './showNoteProperties'; +import * as showPrompt from './showPrompt'; +import * as showShareFolderDialog from './showShareFolderDialog'; +import * as showShareNoteDialog from './showShareNoteDialog'; +import * as showSpellCheckerMenu from './showSpellCheckerMenu'; +import * as toggleEditors from './toggleEditors'; +import * as toggleLayoutMoveMode from './toggleLayoutMoveMode'; +import * as toggleNoteList from './toggleNoteList'; +import * as toggleSideBar from './toggleSideBar'; +import * as toggleVisiblePanes from './toggleVisiblePanes'; + +const index: any[] = [ + commandPalette, + editAlarm, + exportPdf, + gotoAnything, + hideModalMessage, + moveToFolder, + newFolder, + newNote, + newSubFolder, + newTodo, + openFolder, + openNote, + openTag, + print, + renameFolder, + renameTag, + search, + setTags, + showNoteContentProperties, + showNoteProperties, + showPrompt, + showShareFolderDialog, + showShareNoteDialog, + showSpellCheckerMenu, + toggleEditors, + toggleLayoutMoveMode, + toggleNoteList, + toggleSideBar, + toggleVisiblePanes, +]; + +export default index; +// AUTO-GENERATED using `gulp buildCommandIndex` diff --git a/packages/app-desktop/gui/NoteEditor/commands/index.ts b/packages/app-desktop/gui/NoteEditor/commands/index.ts new file mode 100644 index 000000000..d6425d1d8 --- /dev/null +++ b/packages/app-desktop/gui/NoteEditor/commands/index.ts @@ -0,0 +1,15 @@ +// AUTO-GENERATED using `gulp buildCommandIndex` +import * as focusElementNoteBody from './focusElementNoteBody'; +import * as focusElementNoteTitle from './focusElementNoteTitle'; +import * as showLocalSearch from './showLocalSearch'; +import * as showRevisions from './showRevisions'; + +const index: any[] = [ + focusElementNoteBody, + focusElementNoteTitle, + showLocalSearch, + showRevisions, +]; + +export default index; +// AUTO-GENERATED using `gulp buildCommandIndex` diff --git a/packages/app-desktop/gui/NoteEditor/commands/editorCommandDeclarations.ts b/packages/app-desktop/gui/NoteEditor/editorCommandDeclarations.ts similarity index 100% rename from packages/app-desktop/gui/NoteEditor/commands/editorCommandDeclarations.ts rename to packages/app-desktop/gui/NoteEditor/editorCommandDeclarations.ts diff --git a/packages/app-desktop/gui/NoteEditor/utils/useWindowCommandHandler.ts b/packages/app-desktop/gui/NoteEditor/utils/useWindowCommandHandler.ts index cd8025253..b31e2dd29 100644 --- a/packages/app-desktop/gui/NoteEditor/utils/useWindowCommandHandler.ts +++ b/packages/app-desktop/gui/NoteEditor/utils/useWindowCommandHandler.ts @@ -1,6 +1,6 @@ import { useEffect } from 'react'; import { FormNote, ScrollOptionTypes } from './types'; -import editorCommandDeclarations from '../commands/editorCommandDeclarations'; +import editorCommandDeclarations from '../editorCommandDeclarations'; import CommandService, { CommandDeclaration, CommandRuntime, CommandContext } from '@joplin/lib/services/CommandService'; import time from '@joplin/lib/time'; import { reg } from '@joplin/lib/registry'; diff --git a/packages/app-desktop/gui/NoteList/commands/index.ts b/packages/app-desktop/gui/NoteList/commands/index.ts new file mode 100644 index 000000000..69b914359 --- /dev/null +++ b/packages/app-desktop/gui/NoteList/commands/index.ts @@ -0,0 +1,9 @@ +// AUTO-GENERATED using `gulp buildCommandIndex` +import * as focusElementNoteList from './focusElementNoteList'; + +const index: any[] = [ + focusElementNoteList, +]; + +export default index; +// AUTO-GENERATED using `gulp buildCommandIndex` diff --git a/packages/app-desktop/gui/NoteListControls/commands/index.ts b/packages/app-desktop/gui/NoteListControls/commands/index.ts new file mode 100644 index 000000000..58f8eb037 --- /dev/null +++ b/packages/app-desktop/gui/NoteListControls/commands/index.ts @@ -0,0 +1,9 @@ +// AUTO-GENERATED using `gulp buildCommandIndex` +import * as focusSearch from './focusSearch'; + +const index: any[] = [ + focusSearch, +]; + +export default index; +// AUTO-GENERATED using `gulp buildCommandIndex` diff --git a/packages/app-desktop/gui/Sidebar/commands/index.ts b/packages/app-desktop/gui/Sidebar/commands/index.ts new file mode 100644 index 000000000..195188c2a --- /dev/null +++ b/packages/app-desktop/gui/Sidebar/commands/index.ts @@ -0,0 +1,9 @@ +// AUTO-GENERATED using `gulp buildCommandIndex` +import * as focusElementSideBar from './focusElementSideBar'; + +const index: any[] = [ + focusElementSideBar, +]; + +export default index; +// AUTO-GENERATED using `gulp buildCommandIndex` diff --git a/packages/app-desktop/gulpfile.js b/packages/app-desktop/gulpfile.js index 10a1f4d3b..43b1b56bc 100644 --- a/packages/app-desktop/gulpfile.js +++ b/packages/app-desktop/gulpfile.js @@ -19,6 +19,7 @@ const tasks = { }, tsc: require('@joplin/tools/gulp/tasks/tsc'), updateIgnoredTypeScriptBuild: require('@joplin/tools/gulp/tasks/updateIgnoredTypeScriptBuild'), + buildCommandIndex: require('@joplin/tools/gulp/tasks/buildCommandIndex'), }; utils.registerGulpTasks(gulp, tasks); @@ -29,6 +30,7 @@ const buildParallel = [ 'copyPluginAssets', 'copyTinyMceLangs', 'updateIgnoredTypeScriptBuild', + 'buildCommandIndex', ]; gulp.task('build', gulp.parallel(...buildParallel)); diff --git a/packages/lib/commands/index.ts b/packages/lib/commands/index.ts new file mode 100644 index 000000000..a6f768534 --- /dev/null +++ b/packages/lib/commands/index.ts @@ -0,0 +1,13 @@ +// AUTO-GENERATED using `gulp buildCommandIndex` +import * as historyBackward from './historyBackward'; +import * as historyForward from './historyForward'; +import * as synchronize from './synchronize'; + +const index: any[] = [ + historyBackward, + historyForward, + synchronize, +]; + +export default index; +// AUTO-GENERATED using `gulp buildCommandIndex` diff --git a/packages/tools/gulp/tasks/buildCommandIndex.js b/packages/tools/gulp/tasks/buildCommandIndex.js new file mode 100644 index 000000000..703302d2f --- /dev/null +++ b/packages/tools/gulp/tasks/buildCommandIndex.js @@ -0,0 +1,56 @@ +const utils = require('../utils'); +const glob = require('glob'); +const rootDir = utils.rootDir(); +const pathUtils = require('@joplin/lib/path-utils'); + +async function processDirectory(dir) { + const tsFiles = glob.sync('*.ts', { + cwd: dir, + }).filter(f => f !== 'index.ts'); + + const fileContent = []; + + for (const tsFile of tsFiles) { + const f = pathUtils.filename(tsFile); + fileContent.push(`import * as ${f} from './${f}';`); + } + + fileContent.push(''); + + fileContent.push('const index:any[] = ['); + + for (const tsFile of tsFiles) { + const f = pathUtils.filename(tsFile); + fileContent.push(`\t${f},`); + } + + fileContent.push('];'); + + fileContent.push(''); + + fileContent.push('export default index;'); + + const destFile = `${dir}/index.ts`; + + console.info(`Generating ${destFile}...`); + + await utils.insertContentIntoFile( + destFile, + '// AUTO-GENERATED using `gulp buildCommandIndex`', + fileContent.join('\n'), + true + ); +} + +module.exports = { + src: '', + fn: async function() { + await processDirectory(`${rootDir}/packages/app-desktop/commands`); + await processDirectory(`${rootDir}/packages/app-desktop/gui/MainScreen/commands`); + await processDirectory(`${rootDir}/packages/app-desktop/gui/NoteEditor/commands`); + await processDirectory(`${rootDir}/packages/app-desktop/gui/NoteList/commands`); + await processDirectory(`${rootDir}/packages/app-desktop/gui/NoteListControls/commands`); + await processDirectory(`${rootDir}/packages/app-desktop/gui/Sidebar/commands`); + await processDirectory(`${rootDir}/packages/lib/commands`); + }, +}; diff --git a/packages/tools/gulp/utils.js b/packages/tools/gulp/utils.js index 0f2136c4c..71097643f 100644 --- a/packages/tools/gulp/utils.js +++ b/packages/tools/gulp/utils.js @@ -166,4 +166,20 @@ utils.setPackagePrivateField = async function(filePath, value) { await fs.writeFile(filePath, JSON.stringify(obj, null, 2), 'utf8'); }; +utils.insertContentIntoFile = async (filePath, marker, contentToInsert, createIfNotExist = false) => { + const fs = require('fs-extra'); + const fileExists = await fs.pathExists(filePath); + + if (!fileExists) { + if (!createIfNotExist) throw new Error(`File not found: ${filePath}`); + await fs.writeFile(filePath, `${marker}\n${contentToInsert}\n${marker}`); + } else { + let content = await fs.readFile(filePath, 'utf-8'); + // [^]* matches any character including new lines + const regex = new RegExp(`${marker}[^]*?${marker}`); + content = content.replace(regex, `${marker}\n${contentToInsert}\n${marker}`); + await fs.writeFile(filePath, content); + } +}; + module.exports = utils;