From fc471d57f5664e5b4f3243c3ecfac1d1dd6d473c Mon Sep 17 00:00:00 2001 From: NomarCub Date: Wed, 3 Jan 2024 22:57:26 +0100 Subject: [PATCH 1/5] add `{{folderpath}}` template variable, closes https://github.com/NomarCub/obsidian-open-vscode/issues/8 --- README.md | 4 ++-- src/main.ts | 2 ++ src/settings.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2b1492d..29ae717 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ You can template the command opening VSCode however you like with its [provided Note that on MacOS, a full path to the VSCode executable is required (generally "/usr/local/bin/code"). -You can use the following variables: `{{vaultpath}}` (absolute), `{{filepath}}` (relative). +You can use the following variables: `{{vaultpath}}` (absolute), `{{filepath}}` (relative), `{{folderpath}}` (relative). The default template is `code "{{vaultpath}}" "{{vaultpath}}/{{filepath}}"`, which opens the current file (if there is one) in the workspace that is the vault's root folder. This gets expanded to be executed in your shell as `code "C:\Users\YourUser\Documents\vault" "C:\Users\YourUser\Documents\vault/Note.md"`, for example. ### Settings for `open-vscode-via-url` @@ -42,7 +42,7 @@ On some systems, this may be faster than using the `child_process` approach. - **Path to VSCode Workspace** - Defaults to the {{vaultpath}} template variable. You can set this to an absolute path to a ".code-workspace" file if you prefer to use a [Multi Root workspace file](https://code.visualstudio.com/docs/editor/workspaces#_multiroot-workspaces) + Defaults to the `{{vaultpath}}` template variable. You can set this to an absolute path to a ".code-workspace" file if you prefer to use a [Multi Root workspace file](https://code.visualstudio.com/docs/editor/workspaces#_multiroot-workspaces) - **Open VSCode using a `vscode-insiders://` URL** diff --git a/src/main.ts b/src/main.ts index 6fe85d7..02365e9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -76,6 +76,7 @@ export default class OpenVSCode extends Plugin { const path = this.app.vault.adapter.getBasePath(); const file = this.app.workspace.getActiveFile(); const filePath = file?.path ?? ''; + const folderPath = file?.parent.path ?? ''; // eslint-disable-next-line @typescript-eslint/no-var-requires const { exec } = require('child_process'); @@ -83,6 +84,7 @@ export default class OpenVSCode extends Plugin { let command = executeTemplate.trim() === '' ? DEFAULT_SETTINGS.executeTemplate : executeTemplate; command = replaceAll(command, '{{vaultpath}}', path); command = replaceAll(command, '{{filepath}}', filePath); + command = replaceAll(command, '{{folderpath}}', folderPath); if (DEV) console.log('[openVSCode]', { command }); exec(command, (error: never, stdout: never, stderr: never) => { if (error) { diff --git a/src/settings.ts b/src/settings.ts index 0d94286..5d8b5d4 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -58,7 +58,7 @@ export class OpenVSCodeSettingsTab extends PluginSettingTab { new Setting(containerEl) .setName('Template for executing the `code` command') .setDesc( - 'You can use the following variables: `{{vaultpath}}` (absolute), `{{filepath}}` (relative). Note that on MacOS, a full path to the VSCode executable is required (generally "/usr/local/bin/code"). Example: `/usr/local/bin/code "{{vaultpath}}" "{{vaultpath}}/{{filepath}}"`', + 'You can use the following variables: `{{vaultpath}}` (absolute), `{{filepath}}` (relative), `{{folderpath}}` (relative). Note that on MacOS, a full path to the VSCode executable is required (generally "/usr/local/bin/code"). Example: `/usr/local/bin/code "{{vaultpath}}" "{{vaultpath}}/{{filepath}}"`', ) .addText((text) => text From 17ba79eb7637bac1d1c6bcf186d354f29e616a02 Mon Sep 17 00:00:00 2001 From: NomarCub Date: Wed, 3 Jan 2024 23:02:08 +0100 Subject: [PATCH 2/5] bump version to 1.2.2, and Obsidian dependency version to 1.4.11 --- manifest.json | 4 ++-- package.json | 4 ++-- versions.json | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/manifest.json b/manifest.json index 47830a3..9253289 100644 --- a/manifest.json +++ b/manifest.json @@ -1,8 +1,8 @@ { "id": "open-vscode", "name": "Open vault in VSCode", - "version": "1.2.1", - "minAppVersion": "0.16.3", + "version": "1.2.2", + "minAppVersion": "1.4.11", "description": "Ribbon button and command to open vault as a Visual Studio Code workspace", "author": "NomarCub", "authorUrl": "https://github.com/NomarCub", diff --git a/package.json b/package.json index 92952de..8150fed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "open-vscode", - "version": "1.2.1", + "version": "1.2.2", "description": "Open vault in Visual Studio Code ribbon button and command for Obsidian (https://obsidian.md)", "main": "main.js", "scripts": { @@ -17,7 +17,7 @@ "@typescript-eslint/parser": "5.29.0", "builtin-modules": "3.3.0", "esbuild": "0.14.47", - "obsidian": "^0.16.3", + "obsidian": "^1.4.11", "tslib": "2.4.0", "typescript": "4.7.4" } diff --git a/versions.json b/versions.json index 20dc140..f7dfbdf 100644 --- a/versions.json +++ b/versions.json @@ -1,5 +1,6 @@ { "1.0.0": "0.11.13", "1.2.0": "0.14.8", - "1.2.1": "0.16.3" + "1.2.1": "0.16.3", + "1.2.2": "1.4.11" } \ No newline at end of file From ccdbd41f04ec89055faa90daa05637d93ecf1eec Mon Sep 17 00:00:00 2001 From: NomarCub Date: Wed, 3 Jan 2024 23:03:19 +0100 Subject: [PATCH 3/5] fix build error --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 02365e9..627b93c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -76,7 +76,7 @@ export default class OpenVSCode extends Plugin { const path = this.app.vault.adapter.getBasePath(); const file = this.app.workspace.getActiveFile(); const filePath = file?.path ?? ''; - const folderPath = file?.parent.path ?? ''; + const folderPath = file?.parent?.path ?? ''; // eslint-disable-next-line @typescript-eslint/no-var-requires const { exec } = require('child_process'); From 8a8cb9a5d6abd8f9cec08947325f4e20c458c066 Mon Sep 17 00:00:00 2001 From: NomarCub Date: Wed, 3 Jan 2024 23:08:12 +0100 Subject: [PATCH 4/5] fix https://github.com/NomarCub/obsidian-open-vscode/issues/10 --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 627b93c..ef34238 100644 --- a/src/main.ts +++ b/src/main.ts @@ -50,7 +50,7 @@ export default class OpenVSCode extends Plugin { DEV = (this.app as AppWithPlugins).plugins.enabledPlugins.has('hot-reload') && - (this.app as AppWithPlugins).plugins.plugins['hot-reload'].enabledPlugins.has(this.manifest.id); + (this.app as AppWithPlugins).plugins.plugins['hot-reload']?.enabledPlugins.has(this.manifest.id); if (DEV) { this.addCommand({ From 72de252eee3a4039465baec85aa563d91c2cc27d Mon Sep 17 00:00:00 2001 From: NomarCub Date: Wed, 3 Jan 2024 23:43:44 +0100 Subject: [PATCH 5/5] copy build system changes from obsidian-sample-plugin --- .eslintignore | 5 ++-- .gitignore | 51 ++++++++++++++++++++----------------- esbuild.config.mjs | 63 +++++++++++++++++++++++++++++----------------- package.json | 7 +++--- tsconfig.json | 6 ++--- 5 files changed, 78 insertions(+), 54 deletions(-) diff --git a/.eslintignore b/.eslintignore index 32909b2..e019f3c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ -npm node_modules -build \ No newline at end of file +node_modules/ + +main.js diff --git a/.gitignore b/.gitignore index fa22dbe..8930eac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,28 @@ -# vscode -.vscode - -# Intellij -*.iml -.idea - -# npm -node_modules -package-lock.json - -# Don't include the compiled main.js file in the repo. -# They should be uploaded to GitHub releases instead. -main.js - -# Exclude sourcemaps -*.map - -# obsidian -data.json - -# Exclude macOS Finder (System Explorer) View States -.DS_Store +# vscode +.vscode + +# Intellij +*.iml +.idea + +# npm +node_modules +package-lock.json +pnpm-lock.yaml + +# Don't include the compiled main.js file in the repo. +# They should be uploaded to GitHub releases instead. +main.js + +# Exclude sourcemaps +*.map + +# obsidian +data.json + +# Exclude macOS Finder (System Explorer) View States +.DS_Store + +# Exclude files specific to personal development process +.hotreload +.devtarget diff --git a/esbuild.config.mjs b/esbuild.config.mjs index b33ec53..03fce24 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -1,6 +1,8 @@ +import builtins from "builtin-modules"; import esbuild from "esbuild"; +import fs from "fs"; +import path from "path"; import process from "process"; -import builtins from 'builtin-modules' const banner = `/* @@ -9,34 +11,49 @@ if you want to view the source, please visit the github repository of this plugi */ `; -const prod = (process.argv[2] === 'production'); +const prod = (process.argv[2] === "production"); -esbuild.build({ +let outfile = "main.js"; +if (fs.existsSync('./.devtarget')) { + outfile = path.join(fs.readFileSync('./.devtarget', 'utf8').trim(), outfile); + console.log('Temporary output location:', outfile); +} + + +const context = await esbuild.context({ banner: { js: banner, }, - entryPoints: ['src/main.ts'], + entryPoints: ["src/main.ts"], bundle: true, external: [ - 'obsidian', - 'electron', - '@codemirror/autocomplete', - '@codemirror/collab', - '@codemirror/commands', - '@codemirror/language', - '@codemirror/lint', - '@codemirror/search', - '@codemirror/state', - '@codemirror/view', - '@lezer/common', - '@lezer/highlight', - '@lezer/lr', + "obsidian", + "electron", + "@codemirror/autocomplete", + "@codemirror/collab", + "@codemirror/commands", + "@codemirror/language", + "@codemirror/lint", + "@codemirror/search", + "@codemirror/state", + "@codemirror/view", + "@lezer/common", + "@lezer/highlight", + "@lezer/lr", ...builtins], - format: 'cjs', - watch: !prod, - target: 'es2018', + format: "cjs", + target: "es2018", logLevel: "info", - sourcemap: prod ? false : 'inline', + sourcemap: prod ? false : "inline", + minify: prod, + platform: 'browser', treeShaking: true, - outfile: 'main.js', -}).catch(() => process.exit(1)); + outfile, +}); + +if (prod) { + await context.rebuild(); + process.exit(0); +} else { + await context.watch(); +} \ No newline at end of file diff --git a/package.json b/package.json index 8150fed..25e3b98 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,11 @@ "license": "MIT", "devDependencies": { "@types/node": "^16.11.6", - "@typescript-eslint/eslint-plugin": "5.29.0", - "@typescript-eslint/parser": "5.29.0", + "@typescript-eslint/eslint-plugin": "6.2.1", + "@typescript-eslint/parser": "6.2.1", "builtin-modules": "3.3.0", - "esbuild": "0.14.47", + "esbuild": "0.17.3", + "eslint": "8.46.0", "obsidian": "^1.4.11", "tslib": "2.4.0", "typescript": "4.7.4" diff --git a/tsconfig.json b/tsconfig.json index 2d6fbdf..4618f6e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "baseUrl": ".", + "baseUrl": "src", "inlineSourceMap": true, "inlineSources": true, "module": "ESNext", @@ -10,7 +10,7 @@ "moduleResolution": "node", "importHelpers": true, "isolatedModules": true, - "strictNullChecks": true, + "strictNullChecks": true, "lib": [ "DOM", "ES5", @@ -19,6 +19,6 @@ ] }, "include": [ - "**/*.ts" + "src/**/*.ts" ] }