Skip to content

Commit

Permalink
Configure VSCode debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
benjammin4dayz committed Oct 30, 2024
1 parent 02bf3cf commit 69988f9
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm run vscode:debug",
// "env": { "NO_COLOR": "1" }, // If terminal does not display ANSI escapes
"internalConsoleOptions": "openOnFirstSessionStart",
"name": "Neu React Vite Runner",
"request": "launch",
"type": "node-terminal",
"serverReadyAction": {
"action": "debugWithChrome",
"killOnServerStop": true,
"pattern": "Local:.*http://localhost:([0-9]+)/",
"uriFormat": "http://localhost:%s",
"webRoot": "${workspaceFolder}${pathSeparator}react-src"
},
"postDebugTask": "npm: vscode:postdebug"
}
]
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"clean": "rimraf .tmp/ dist/ node_modules/ react-src/dist/ react-src/node_modules/",
"lint": "npm run lint --workspaces --if-present",
"setup": "npm ci && neu update",
"start": "neu run -- --window-enable-inspector"
"start": "neu run -- --window-enable-inspector",
"vscode:debug": "node scripts/debug.cjs",
"vscode:postdebug": "node scripts/debug.cjs --postdebug"
},
"devDependencies": {
"@neutralinojs/neu": "^11.3.0",
Expand Down
35 changes: 35 additions & 0 deletions scripts/debug.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
const neuConfig = require('../neutralino.config.json');

const root = path.join(__dirname, '..');

const patchFile = path.join(root, neuConfig.cli.frontendLibrary.patchFile);
const patchFileExists = fs.existsSync(patchFile);
const backupPatchFile = path.join(path.dirname(patchFile), 'index.org.html');
const backupPatchFileExists = fs.existsSync(backupPatchFile);

const restorePatchFile = () => {
fs.rmSync(patchFile);
fs.renameSync(backupPatchFile, patchFile);
};

if (process.argv.includes('--postdebug')) {
if (backupPatchFileExists) restorePatchFile();
} else {
if (patchFileExists) fs.cpSync(patchFile, backupPatchFile);
spawn(
'npx',
['@neutralinojs/neu', 'run', '--', '--mode=cloud'],
//
// Cloud mode is a convenience to avoid the window popup. The NL_TOKEN is
// not consumed until the debugger attaches; all other clients are rejected
//
{
cwd: path.join(root),
stdio: 'inherit',
shell: true,
}
);
}

0 comments on commit 69988f9

Please sign in to comment.