From 1238dee524ecc533d8937ce511c749cc1bd002f9 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Sun, 16 Apr 2017 19:15:50 +1200 Subject: [PATCH] feat(starter): provide an executable to start forge in a vscode debugger compatible way Currently only on darwin and linux, win32 implemenation to come --- README.md | 23 +++++++++++++++++++++++ package.json | 3 ++- script/vscode.sh | 7 +++++++ src/electron-forge-start.js | 8 ++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100755 script/vscode.sh diff --git a/README.md b/README.md index 3cafd702f1..146b70390f 100644 --- a/README.md +++ b/README.md @@ -228,3 +228,26 @@ You must export a Function that returns a Promise. Your function will be called * tag - The value of `--tag` You should use `ora` to indicate your publish progress. + +## Debugging your application through VS Code + +Debugging your Electron main process through VS Code is ridiculously +easy with Forge. Simply add this as a launch config in VSCode and you're +good to go. + +```json +{ + "type": "node", + "request": "launch", + "name": "Electron Main", + "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-forge-vscode-nix", + "windows": { + "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-forge-vscode-win.cmd" + }, + // runtimeArgs will be passed directly to your Electron application + "runtimeArgs": [ + "foo", + "bar" + ] +} +``` diff --git a/package.json b/package.json index 62b4a0fbba..6f6a777ccf 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "main": "dist/api/index.js", "bin": { "electron-forge": "dist/electron-forge.js", - "forge": "dist/electron-forge.js" + "forge": "dist/electron-forge.js", + "electron-forge-vscode-nix": "script/vscode.sh" }, "scripts": { "build": "gulp build", diff --git a/script/vscode.sh b/script/vscode.sh new file mode 100755 index 0000000000..9e6f80e197 --- /dev/null +++ b/script/vscode.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +ARGS=$@ +ARGS=${ARGS// /\~ \~} + +node $DIR/../electron-forge/dist/electron-forge-start --vscode --- \~$ARGS\~ \ No newline at end of file diff --git a/src/electron-forge-start.js b/src/electron-forge-start.js index 8de6f61799..90a2e2175f 100644 --- a/src/electron-forge-start.js +++ b/src/electron-forge-start.js @@ -22,6 +22,7 @@ import { start } from './api'; .option('-p, --app-path ', "Override the path to the Electron app to launch (defaults to '.')") .option('-l, --enable-logging', 'Enable advanced logging. This will log internal Electron things') .option('-n, --run-as-node', 'Run the Electron app as a Node.JS script') + .option('--vscode', 'Used to enable arg transformation for debugging Electron through VSCode. Do not use yourself.') .action((cwd) => { if (!cwd) return; if (path.isAbsolute(cwd) && fs.existsSync(cwd)) { @@ -47,6 +48,13 @@ import { start } from './api'; runAsNode: !!program.runAsNode, }; + if (program.vscode && appArgs) { + appArgs = appArgs + // Args are in the format ~arg~ so we need to strip the "~" + .map(arg => arg.substr(1, arg.length - 2)) + .filter(arg => arg.length > 0); + } + if (program.appPath) opts.appPath = program.appPath; if (appArgs) opts.args = appArgs;