Skip to content

Commit

Permalink
feat(starter): provide an executable to start forge in a vscode debug…
Browse files Browse the repository at this point in the history
…ger compatible way

Currently only on darwin and linux, win32 implemenation to come
  • Loading branch information
MarshallOfSound authored and malept committed Apr 17, 2017
1 parent 2e00a9c commit 1238dee
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
23 changes: 23 additions & 0 deletions README.md
Expand Up @@ -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"
]
}
```
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions 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\~
8 changes: 8 additions & 0 deletions src/electron-forge-start.js
Expand Up @@ -22,6 +22,7 @@ import { start } from './api';
.option('-p, --app-path <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)) {
Expand All @@ -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;

Expand Down

0 comments on commit 1238dee

Please sign in to comment.