Skip to content

Commit 1238dee

Browse files
MarshallOfSoundmalept
authored andcommitted
feat(starter): provide an executable to start forge in a vscode debugger compatible way
Currently only on darwin and linux, win32 implemenation to come
1 parent 2e00a9c commit 1238dee

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,26 @@ You must export a Function that returns a Promise. Your function will be called
228228
* tag - The value of `--tag`
229229

230230
You should use `ora` to indicate your publish progress.
231+
232+
## Debugging your application through VS Code
233+
234+
Debugging your Electron main process through VS Code is ridiculously
235+
easy with Forge. Simply add this as a launch config in VSCode and you're
236+
good to go.
237+
238+
```json
239+
{
240+
"type": "node",
241+
"request": "launch",
242+
"name": "Electron Main",
243+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-forge-vscode-nix",
244+
"windows": {
245+
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-forge-vscode-win.cmd"
246+
},
247+
// runtimeArgs will be passed directly to your Electron application
248+
"runtimeArgs": [
249+
"foo",
250+
"bar"
251+
]
252+
}
253+
```

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"main": "dist/api/index.js",
77
"bin": {
88
"electron-forge": "dist/electron-forge.js",
9-
"forge": "dist/electron-forge.js"
9+
"forge": "dist/electron-forge.js",
10+
"electron-forge-vscode-nix": "script/vscode.sh"
1011
},
1112
"scripts": {
1213
"build": "gulp build",

script/vscode.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
4+
ARGS=$@
5+
ARGS=${ARGS// /\~ \~}
6+
7+
node $DIR/../electron-forge/dist/electron-forge-start --vscode --- \~$ARGS\~

src/electron-forge-start.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { start } from './api';
2222
.option('-p, --app-path <path>', "Override the path to the Electron app to launch (defaults to '.')")
2323
.option('-l, --enable-logging', 'Enable advanced logging. This will log internal Electron things')
2424
.option('-n, --run-as-node', 'Run the Electron app as a Node.JS script')
25+
.option('--vscode', 'Used to enable arg transformation for debugging Electron through VSCode. Do not use yourself.')
2526
.action((cwd) => {
2627
if (!cwd) return;
2728
if (path.isAbsolute(cwd) && fs.existsSync(cwd)) {
@@ -47,6 +48,13 @@ import { start } from './api';
4748
runAsNode: !!program.runAsNode,
4849
};
4950

51+
if (program.vscode && appArgs) {
52+
appArgs = appArgs
53+
// Args are in the format ~arg~ so we need to strip the "~"
54+
.map(arg => arg.substr(1, arg.length - 2))
55+
.filter(arg => arg.length > 0);
56+
}
57+
5058
if (program.appPath) opts.appPath = program.appPath;
5159
if (appArgs) opts.args = appArgs;
5260

0 commit comments

Comments
 (0)