From 69988f9540f60ebee6c07fb53d7cdefb70cfc295 Mon Sep 17 00:00:00 2001 From: Jam <42326027+benjammin4dayz@users.noreply.github.com> Date: Tue, 29 Oct 2024 20:43:27 -0400 Subject: [PATCH] Configure VSCode debugger --- .vscode/launch.json | 21 +++++++++++++++++++++ package.json | 4 +++- scripts/debug.cjs | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json create mode 100644 scripts/debug.cjs diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..81d925c --- /dev/null +++ b/.vscode/launch.json @@ -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" + } + ] +} diff --git a/package.json b/package.json index 77e7b90..966342d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/debug.cjs b/scripts/debug.cjs new file mode 100644 index 0000000..bc3ed2b --- /dev/null +++ b/scripts/debug.cjs @@ -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, + } + ); +}