From 6fdd93316dad9439684e588d5a5231f86f68ea32 Mon Sep 17 00:00:00 2001 From: antoKeinanen Date: Wed, 4 Oct 2023 15:53:12 +0300 Subject: [PATCH] chore: fromat project --- .eslintrc | 42 ++++---- .github/ISSUE_TEMPLATE/bug_report.md | 13 +-- .github/ISSUE_TEMPLATE/feature_request.md | 7 +- .gitignore | 2 + .husky/pre-commit | 2 +- main.ts | 124 +++++++++++++--------- package.json | 49 ++++----- tsconfig.json | 37 +++---- 8 files changed, 144 insertions(+), 132 deletions(-) diff --git a/.eslintrc b/.eslintrc index 0807290..7fc8ba5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,23 +1,21 @@ { - "root": true, - "parser": "@typescript-eslint/parser", - "env": { "node": true }, - "plugins": [ - "@typescript-eslint" - ], - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/eslint-recommended", - "plugin:@typescript-eslint/recommended" - ], - "parserOptions": { - "sourceType": "module" - }, - "rules": { - "no-unused-vars": "off", - "@typescript-eslint/no-unused-vars": ["error", { "args": "none" }], - "@typescript-eslint/ban-ts-comment": "off", - "no-prototype-builtins": "off", - "@typescript-eslint/no-empty-function": "off" - } - } \ No newline at end of file + "root": true, + "parser": "@typescript-eslint/parser", + "env": { "node": true }, + "plugins": ["@typescript-eslint"], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended" + ], + "parserOptions": { + "sourceType": "module" + }, + "rules": { + "no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": ["error", { "args": "none" }], + "@typescript-eslint/ban-ts-comment": "off", + "no-prototype-builtins": "off", + "@typescript-eslint/no-empty-function": "off" + } +} diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 81f7b01..f6387b4 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,10 +1,9 @@ --- name: Bug report about: Create a report to help us improve -title: '' -labels: '' +title: "" +labels: "" assignees: antoKeinanen - --- **Describe the bug** @@ -12,6 +11,7 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: + 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' @@ -24,9 +24,10 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots to help explain your problem. **System information:** - - OS: [e.g. iOS8.1, linux] - - Obsidian version [e.g. 1.1.16] *(can be found at about page in settings)* - - Plugin version [e.g. 1.0.0] *(can be found at community plugins page in settings)* + +- OS: [e.g. iOS8.1, linux] +- Obsidian version [e.g. 1.1.16] _(can be found at about page in settings)_ +- Plugin version [e.g. 1.0.0] _(can be found at community plugins page in settings)_ **Additional context** Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index bbcbbe7..2bc5d5f 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,10 +1,9 @@ --- name: Feature request about: Suggest an idea for this project -title: '' -labels: '' -assignees: '' - +title: "" +labels: "" +assignees: "" --- **Is your feature request related to a problem? Please describe.** diff --git a/.gitignore b/.gitignore index 0b30a97..c3bd6c0 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ data.json # Exclude macOS Finder (System Explorer) View States .DS_Store + +bun.lockb \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit index 0da96d6..547f5dc 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -npx pretty-quick --staged +npx prettier . --write diff --git a/main.ts b/main.ts index 42478df..eb0857e 100644 --- a/main.ts +++ b/main.ts @@ -35,16 +35,19 @@ const TRANSLATIONS: { [name: string]: Translation } = { OverwriteFileQuestion: "Vorhandene Datei überschreiben", Settings: "Einstellungen", SettingIncludeNestedFolders: "Verschachtelte Ordner einbeziehen", - SettingIncludeNestedFoldersDescription: "Wenn aktiviert, werden Dateien in verschachtelten Ordnern zusammengeführt. Andernfalls werden nur Dateien im ausgewählten Ordner zusammengeführt (Standardverhalten).", + SettingIncludeNestedFoldersDescription: + "Wenn aktiviert, werden Dateien in verschachtelten Ordnern zusammengeführt. Andernfalls werden nur Dateien im ausgewählten Ordner zusammengeführt (Standardverhalten).", SettingIncludeFoldersAsSections: "Ordner als Abschnitte einbeziehen", - SettingIncludeFoldersAsSectionsDescription: "Ordner werden als benannte Abschnitte in die Ausgabedatei eingefügt.", + SettingIncludeFoldersAsSectionsDescription: + "Ordner werden als benannte Abschnitte in die Ausgabedatei eingefügt.", Yes: "Ja", No: "Nein", SettingSortMode: "Sortiermodus", - SettingSortModeDescription: "Wählen Sie den Sortiermodus für das Zusammenführen von Notizen.", + SettingSortModeDescription: + "Wählen Sie den Sortiermodus für das Zusammenführen von Notizen.", SettingSortDateCreated: "Erstellungsdatum", SettingSortLogical: "Logisch", - SettingSortAlphabetically: "Alphabetisch" + SettingSortAlphabetically: "Alphabetisch", }, en: { MergeFolder: "Merge folder", @@ -52,16 +55,18 @@ const TRANSLATIONS: { [name: string]: Translation } = { OverwriteFileQuestion: "Overwite exising file", Settings: "Settings", SettingIncludeNestedFolders: "Include nested folders", - SettingIncludeNestedFoldersDescription: "If enabled, files in nested folders will be included in merge. Otherwise, only files in selected folder will be merged (default behaviour).", + SettingIncludeNestedFoldersDescription: + "If enabled, files in nested folders will be included in merge. Otherwise, only files in selected folder will be merged (default behaviour).", SettingIncludeFoldersAsSections: "Include folders as sections", - SettingIncludeFoldersAsSectionsDescription: "Folders will be included as named sections into output file.", + SettingIncludeFoldersAsSectionsDescription: + "Folders will be included as named sections into output file.", Yes: "Yes", No: "No", SettingSortMode: "Sort mode", SettingSortModeDescription: "Pick the sorting mode for merging notes.", SettingSortDateCreated: "Date created", SettingSortLogical: "Logical", - SettingSortAlphabetically: "Alphabetical" + SettingSortAlphabetically: "Alphabetical", }, fi: { MergeFolder: "Yhdistä kansio", @@ -69,16 +74,19 @@ const TRANSLATIONS: { [name: string]: Translation } = { OverwriteFileQuestion: "Korvaa olemassa oleva tiedosto", Settings: "Asetukset", SettingIncludeNestedFolders: "Sisällytä sisäkkäiset kansiot", - SettingIncludeNestedFoldersDescription: "Jos käytössä, sisäkkäisten kansioiden tiedostot yhdistetään. Muussa tapauksessa vain valitun kansion tiedostot yhdistetään (oletustoiminto).", + SettingIncludeNestedFoldersDescription: + "Jos käytössä, sisäkkäisten kansioiden tiedostot yhdistetään. Muussa tapauksessa vain valitun kansion tiedostot yhdistetään (oletustoiminto).", SettingIncludeFoldersAsSections: "Sisällytä kansiot osioihin", - SettingIncludeFoldersAsSectionsDescription: "Kansiot sisällytetään nimettyinä osina tulostiedostoon.", + SettingIncludeFoldersAsSectionsDescription: + "Kansiot sisällytetään nimettyinä osina tulostiedostoon.", Yes: "Kyllä", No: "Ei", SettingSortMode: "Lajittelu järjestys", - SettingSortModeDescription: "Valitse lajittelutapa muistiinpanojen yhdistämistä varten.", + SettingSortModeDescription: + "Valitse lajittelutapa muistiinpanojen yhdistämistä varten.", SettingSortDateCreated: "Luontipäivämäärä", SettingSortLogical: "Looginen", - SettingSortAlphabetically: "Aakkosjärjestys" + SettingSortAlphabetically: "Aakkosjärjestys", }, fr: { MergeFolder: "Fusionner le dossier", @@ -86,16 +94,20 @@ const TRANSLATIONS: { [name: string]: Translation } = { OverwriteFileQuestion: "Remplacer le fichier existant", Settings: "Paramètres", SettingIncludeNestedFolders: "Inclure les dossiers imbriqués", - SettingIncludeNestedFoldersDescription: "Si activé, les fichiers des dossiers imbriqués seront inclus dans la fusion. Sinon, seuls les fichiers du dossier sélectionné seront fusionnés (comportement par défaut).", - SettingIncludeFoldersAsSections: "Inclure les dossiers en tant que sections", - SettingIncludeFoldersAsSectionsDescription: "Les dossiers seront inclus en tant que sections nommées dans le fichier de sortie.", + SettingIncludeNestedFoldersDescription: + "Si activé, les fichiers des dossiers imbriqués seront inclus dans la fusion. Sinon, seuls les fichiers du dossier sélectionné seront fusionnés (comportement par défaut).", + SettingIncludeFoldersAsSections: + "Inclure les dossiers en tant que sections", + SettingIncludeFoldersAsSectionsDescription: + "Les dossiers seront inclus en tant que sections nommées dans le fichier de sortie.", Yes: "Oui", No: "Non", SettingSortMode: "mode de tri", - SettingSortModeDescription: "Choisissez le mode de tri pour la fusion des notes.", + SettingSortModeDescription: + "Choisissez le mode de tri pour la fusion des notes.", SettingSortDateCreated: "Date de création", SettingSortLogical: "Logique", - SettingSortAlphabetically: "Alphabétique" + SettingSortAlphabetically: "Alphabétique", }, ru: { MergeFolder: "Объединить папку", @@ -103,16 +115,19 @@ const TRANSLATIONS: { [name: string]: Translation } = { OverwriteFileQuestion: "Перезаписать существующий файл", Settings: "Настройки", SettingIncludeNestedFolders: "Влючать вложенные папки", - SettingIncludeNestedFoldersDescription: "Если включено, файлы во вложенных папках будут включены в слияние. В противном случае будут объединены только файлы в выбранной папке (поведение по умолчанию).", + SettingIncludeNestedFoldersDescription: + "Если включено, файлы во вложенных папках будут включены в слияние. В противном случае будут объединены только файлы в выбранной папке (поведение по умолчанию).", SettingIncludeFoldersAsSections: "Включать папки как разделы", - SettingIncludeFoldersAsSectionsDescription: "Папки будут включены в выходной файл в качестве разделов.", + SettingIncludeFoldersAsSectionsDescription: + "Папки будут включены в выходной файл в качестве разделов.", Yes: "Да", No: "Нет", SettingSortMode: "режим сортировки", - SettingSortModeDescription: "Выберите режим сортировки при объединении заметок.", + SettingSortModeDescription: + "Выберите режим сортировки при объединении заметок.", SettingSortDateCreated: "Дата создания", SettingSortLogical: "Логический", - SettingSortAlphabetically: "Алфавитный указатель" + SettingSortAlphabetically: "Алфавитный указатель", }, ua: { MergeFolder: "Об'єднати папку", @@ -120,16 +135,19 @@ const TRANSLATIONS: { [name: string]: Translation } = { OverwriteFileQuestion: "Перезаписати існуючий файл", Settings: "Налаштування", SettingIncludeNestedFolders: "Включити вкладені папки", - SettingIncludeNestedFoldersDescription: "Якщо ввімкнено, файли у вкладених папках будуть включені в об’єднання. В іншому випадку буде об’єднано лише файли у вибраній папці (поведінка за замовчуванням).", + SettingIncludeNestedFoldersDescription: + "Якщо ввімкнено, файли у вкладених папках будуть включені в об’єднання. В іншому випадку буде об’єднано лише файли у вибраній папці (поведінка за замовчуванням).", SettingIncludeFoldersAsSections: "Включити папки як розділи", - SettingIncludeFoldersAsSectionsDescription: "Папки будуть включені як іменовані розділи у вихідний файл.", + SettingIncludeFoldersAsSectionsDescription: + "Папки будуть включені як іменовані розділи у вихідний файл.", Yes: "Так", No: "Ні", SettingSortMode: "Логический", - SettingSortModeDescription: "Виберіть режим сортування для об'єднання нотаток.", + SettingSortModeDescription: + "Виберіть режим сортування для об'єднання нотаток.", SettingSortDateCreated: "Дата створення", SettingSortLogical: "Логічний", - SettingSortAlphabetically: "За алфавітом" + SettingSortAlphabetically: "За алфавітом", }, }; @@ -216,10 +234,10 @@ export default class AdvancedMerge extends Plugin { .setIcon(ICON_NAME) .onClick( async (evt) => - await this.onClickCallback(folder, evt) + await this.onClickCallback(folder, evt), ); }); - }) + }), ); // This adds a settings tab so the user can configure various aspects of the plugin @@ -228,7 +246,7 @@ export default class AdvancedMerge extends Plugin { private async onClickCallback( folder: TFolder, - _evt: MouseEvent | KeyboardEvent + _evt: MouseEvent | KeyboardEvent, ): Promise { const { vault } = this.app; @@ -251,7 +269,7 @@ export default class AdvancedMerge extends Plugin { }); const entries = this.sortNotes( - documentEntries.filter((entry) => this.filterNotes(folder, entry)) + documentEntries.filter((entry) => this.filterNotes(folder, entry)), ); const outputFileName = `${folder.path}-${ @@ -266,18 +284,18 @@ export default class AdvancedMerge extends Plugin { async (deleteFile) => { if (!deleteFile) { console.info( - `file "${outputFileName}" already exists, but user cancelled deleting..` + `file "${outputFileName}" already exists, but user cancelled deleting..`, ); return; } console.info( - `file "${outputFileName}" already exists, deleting..` + `file "${outputFileName}" already exists, deleting..`, ); await vault.adapter.remove(outputFileName); await this.mergeNotes(vault, entries, outputFileName); - } + }, ).open(); return; } @@ -293,7 +311,7 @@ export default class AdvancedMerge extends Plugin { private async mergeNotes( vault: Vault, entries: Array, - outputFileName: string + outputFileName: string, ): Promise { const outputFile = await vault.create(outputFileName, ""); @@ -309,19 +327,19 @@ export default class AdvancedMerge extends Plugin { const fileSectionName = folderOrFile.name.replace(/\.md$/, ""); // For the first file in a row, we shouldnt add new line sectionContents = `${SECTION_CHAR.repeat( - sectionLevel + sectionLevel, )} ${fileSectionName}${DOUBLE_NEW_LINE_CHAR}${sectionContents}${ lastEntry ? "" : DOUBLE_NEW_LINE_CHAR }`; console.info( - `Adding file "${folderOrFile.name}" as section "${fileSectionName}" into file "${outputFileName}"..` + `Adding file "${folderOrFile.name}" as section "${fileSectionName}" into file "${outputFileName}"..`, ); } else if (folderOrFile instanceof TFolder) { sectionContents += `${SECTION_CHAR.repeat(sectionLevel)} ${ folderOrFile.name }${DOUBLE_NEW_LINE_CHAR}`; console.info( - `Adding folder "${folderOrFile.name}" as section "${sectionContents}" into file "${outputFileName}"..` + `Adding folder "${folderOrFile.name}" as section "${sectionContents}" into file "${outputFileName}"..`, ); } vault.append(outputFile, sectionContents); @@ -353,7 +371,7 @@ export default class AdvancedMerge extends Plugin { numeric: true, sensitivity: "base", usage: "sort", - }) + }), ); case SortOptions.CreationDate: return files.sort((a, b) => a.stat.ctime - b.stat.ctime); @@ -370,7 +388,7 @@ export default class AdvancedMerge extends Plugin { this.settings = Object.assign( {}, DEFAULT_SETTINGS, - await this.loadData() + await this.loadData(), ); } @@ -409,16 +427,16 @@ class AdvancedMergeSettingTab extends PluginSettingTab { // Add "sort mode" dropdown in settings new Setting(containerEl) .setName(this.plugin.translation.get().SettingSortMode) - .setDesc( - this.plugin.translation.get() - .SettingSortModeDescription - ) + .setDesc(this.plugin.translation.get().SettingSortModeDescription) .addDropdown((dropdown) => dropdown.addOptions({ - [SortOptions.Alphabetically]: this.plugin.translation.get().SettingSortAlphabetically, - [SortOptions.CreationDate]: this.plugin.translation.get().SettingSortDateCreated, - [SortOptions.Logical]: this.plugin.translation.get().SettingSortLogical, - }) + [SortOptions.Alphabetically]: + this.plugin.translation.get().SettingSortAlphabetically, + [SortOptions.CreationDate]: + this.plugin.translation.get().SettingSortDateCreated, + [SortOptions.Logical]: + this.plugin.translation.get().SettingSortLogical, + }), ); // Add "include nested folders" toggle in settings @@ -426,7 +444,7 @@ class AdvancedMergeSettingTab extends PluginSettingTab { .setName(this.plugin.translation.get().SettingIncludeNestedFolders) .setDesc( this.plugin.translation.get() - .SettingIncludeNestedFoldersDescription + .SettingIncludeNestedFoldersDescription, ) .addToggle((toggle) => toggle @@ -439,7 +457,7 @@ class AdvancedMergeSettingTab extends PluginSettingTab { : this.plugin.settings.includeFoldersAsSections; await this.plugin.saveSettings(); this.showIncludeFolderAsSectionSetting(containerEl); - }) + }), ); this.showIncludeFolderAsSectionSetting(containerEl); @@ -454,11 +472,11 @@ class AdvancedMergeSettingTab extends PluginSettingTab { // Add "include folders as sections" toggle in settings this.includeFolderAsSectionSetting = new Setting(containerEl) .setName( - this.plugin.translation.get().SettingIncludeFoldersAsSections + this.plugin.translation.get().SettingIncludeFoldersAsSections, ) .setDesc( this.plugin.translation.get() - .SettingIncludeFoldersAsSectionsDescription + .SettingIncludeFoldersAsSectionsDescription, ) .addToggle((toggle) => toggle @@ -466,7 +484,7 @@ class AdvancedMergeSettingTab extends PluginSettingTab { .onChange(async (value) => { this.plugin.settings.includeFoldersAsSections = value; await this.plugin.saveSettings(); - }) + }), ); } } @@ -488,7 +506,7 @@ class AdvancedMergeOverwriteFileModal extends Modal { app: App, translation: AdvancedMergeTranslation, existingFileName: string, - handler: (result: boolean) => void + handler: (result: boolean) => void, ) { super(app); this.tranlation = translation; @@ -516,7 +534,7 @@ class AdvancedMergeOverwriteFileModal extends Modal { .onClick(() => { this.close(); this.onSubmitHandler(false); - }) + }), ) .addButton((btn) => btn @@ -525,7 +543,7 @@ class AdvancedMergeOverwriteFileModal extends Modal { .onClick(() => { this.close(); this.onSubmitHandler(true); - }) + }), ); } diff --git a/package.json b/package.json index b506620..2714d1a 100644 --- a/package.json +++ b/package.json @@ -1,34 +1,11 @@ { "name": "obsidian-advanced-merger", "version": "1.4.0", - "description": "Merge a folder of notes for easier export. This plugin is designed for Obsidian (https://obsidian.md).", - "homepage": "https://github.com/antoKeinanen/obsidian-advanced-merger", - "contributors": [ - { - "name": "Dmitry Besedin", - "email": "endarvaluk@gmail.com", - "url": "https://github.com/EndarValuk/" - } - ], - "funding": [ - { - "type": "individual", - "url": "https://www.buymeacoffee.com/antokeinanen" - } - ], - "main": "main.js", - "scripts": { - "dev": "node esbuild.config.mjs", - "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", - "version": "node version-bump.mjs && git add manifest.json versions.json", - "prepare": "husky install" - }, - "keywords": [], "author": { "name": "Anto Keinänen", "url": "https://github.com/antoKeinanen/" }, - "license": "MIT", + "main": "main.js", "devDependencies": { "@types/node": "^16.11.6", "@typescript-eslint/eslint-plugin": "5.29.0", @@ -37,8 +14,32 @@ "esbuild": "0.17.3", "husky": "^8.0.0", "obsidian": "latest", + "prettier": "^3.0.3", "pretty-quick": "^3.1.3", "tslib": "2.4.0", "typescript": "4.7.4" + }, + "contributors": [ + { + "name": "Dmitry Besedin", + "email": "endarvaluk@gmail.com", + "url": "https://github.com/EndarValuk/" + } + ], + "description": "Merge a folder of notes for easier export. This plugin is designed for Obsidian (https://obsidian.md).", + "funding": [ + { + "type": "individual", + "url": "https://www.buymeacoffee.com/antokeinanen" + } + ], + "homepage": "https://github.com/antoKeinanen/obsidian-advanced-merger", + "keywords": [], + "license": "MIT", + "scripts": { + "dev": "node esbuild.config.mjs", + "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", + "version": "node version-bump.mjs && git add manifest.json versions.json", + "prepare": "husky install" } } diff --git a/tsconfig.json b/tsconfig.json index 2d6fbdf..c3939c0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,24 +1,17 @@ { - "compilerOptions": { - "baseUrl": ".", - "inlineSourceMap": true, - "inlineSources": true, - "module": "ESNext", - "target": "ES6", - "allowJs": true, - "noImplicitAny": true, - "moduleResolution": "node", - "importHelpers": true, - "isolatedModules": true, - "strictNullChecks": true, - "lib": [ - "DOM", - "ES5", - "ES6", - "ES7" - ] - }, - "include": [ - "**/*.ts" - ] + "compilerOptions": { + "baseUrl": ".", + "inlineSourceMap": true, + "inlineSources": true, + "module": "ESNext", + "target": "ES6", + "allowJs": true, + "noImplicitAny": true, + "moduleResolution": "node", + "importHelpers": true, + "isolatedModules": true, + "strictNullChecks": true, + "lib": ["DOM", "ES5", "ES6", "ES7"] + }, + "include": ["**/*.ts"] }