Skip to content

Commit

Permalink
Merge pull request #12 from NomarCub/folderpath-feature
Browse files Browse the repository at this point in the history
Folderpath feature
  • Loading branch information
NomarCub authored Jan 3, 2024
2 parents 8963be3 + 72de252 commit a264f83
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 63 deletions.
5 changes: 3 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
npm node_modules
build
node_modules/

main.js
51 changes: 28 additions & 23 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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**

Expand Down
63 changes: 40 additions & 23 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -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 =
`/*
Expand All @@ -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();
}
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -13,11 +13,12 @@
"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",
"obsidian": "^0.16.3",
"esbuild": "0.17.3",
"eslint": "8.46.0",
"obsidian": "^1.4.11",
"tslib": "2.4.0",
"typescript": "4.7.4"
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -76,13 +76,15 @@ 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');

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) {
Expand Down
2 changes: 1 addition & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"baseUrl": ".",
"baseUrl": "src",
"inlineSourceMap": true,
"inlineSources": true,
"module": "ESNext",
Expand All @@ -10,7 +10,7 @@
"moduleResolution": "node",
"importHelpers": true,
"isolatedModules": true,
"strictNullChecks": true,
"strictNullChecks": true,
"lib": [
"DOM",
"ES5",
Expand All @@ -19,6 +19,6 @@
]
},
"include": [
"**/*.ts"
"src/**/*.ts"
]
}
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit a264f83

Please sign in to comment.