Skip to content

Commit

Permalink
Fix for nvm
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed May 4, 2021
1 parent 625bb54 commit a0a21a0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [1.15.1] - 2020-05-04

- Add the ability to specify a custom Node path

## [1.15.0] - 2020-05-04

- Added the ability to add your own custom scripts as panel actions.
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,14 @@ Allows you to specify a title and script path (starting relative from the root o
{
"frontMatter.custom.scripts": [{
"title": "Generate social image",
"script": "./scripts/social-img.js"
"script": "./scripts/social-img.js",
"nodeBin": "~/.nvm/versions/node/v14.15.5/bin/node"
}]
}
```

> **Important**: When the command execution would fail when it cannot find the `node` command. You are able to specify your path to the node app. This is for instance required when using `nvm`.
## Usage

- Start by opening the command prompt:
Expand Down
1 change: 1 addition & 0 deletions src/models/PanelSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export interface Slug {
export interface CustomScript {
title: string;
script: string;
nodeBin?: string;
}
34 changes: 19 additions & 15 deletions src/webview/ExplorerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,23 +176,27 @@ export class ExplorerView implements WebviewViewProvider, Disposable {
const scripts: CustomScript[] | undefined = config.get(SETTING_CUSTOM_SCRIPTS);


if (msg?.data?.title && msg?.data?.script && scripts && scripts.find((s: CustomScript) => s.title === msg?.data?.title)?.title) {
const editor = window.activeTextEditor;
const wsFolders = workspace.workspaceFolders;
if (wsFolders && wsFolders.length > 0) {
const wsPath = wsFolders[0].uri.fsPath;
exec(`node ${path.join(wsPath, msg.data.script)} "${wsPath}" "${editor?.document.uri.fsPath}"`, (error, stdout) => {
if (error) {
window.showErrorMessage(`${msg?.data?.title}: ${error.message}`);
return;
}

window.showInformationMessage(`${msg?.data?.title}: ${stdout || "Executed your custom script."}`, 'Copy output').then(value => {
if (value === 'Copy output') {
vscodeEnv.clipboard.writeText(stdout);
if (msg?.data?.title && msg?.data?.script && scripts) {
const customScript = scripts.find((s: CustomScript) => s.title === msg.data.title);
if (customScript?.script && customScript?.title) {
const editor = window.activeTextEditor;
const wsFolders = workspace.workspaceFolders;
if (wsFolders && wsFolders.length > 0) {
const wsPath = wsFolders[0].uri.fsPath;

exec(`${customScript.nodeBin || "node"} ${path.join(wsPath, msg.data.script)} "${wsPath}" "${editor?.document.uri.fsPath}"`, (error, stdout) => {
if (error) {
window.showErrorMessage(`${msg?.data?.title}: ${error.message}`);
return;
}

window.showInformationMessage(`${msg?.data?.title}: ${stdout || "Executed your custom script."}`, 'Copy output').then(value => {
if (value === 'Copy output') {
vscodeEnv.clipboard.writeText(stdout);
}
});
});
});
}
}
}
}
Expand Down

0 comments on commit a0a21a0

Please sign in to comment.