gluegun
gluegun copied to clipboard
How to debug using vscode debugger?
It has a way to debug my cli using vscode or something like that? I didn't find any information about it.
Hi @MarceloBritoWD!
I should write up a debugging guide, that's a great idea.
Is there something in particular you're having trouble debugging?
Hi @jamonholmgren, thank you for answering me.
I already solve the problem and was a bug that I had created, but I missed a way to debug my cli app, so basically found the solution with console.log
haha
console.log
works pretty well, to be honest. I also like toolbox.print.debug()
which is built in to Gluegun's toolbox.
I'll work on this when I'm back from my Florida conference.
Hi @jamonholmgren,
may I ask, if you found the time to write some docs about debugging? I am struggling to get the debugger work properly.
I've started a new project following your docs by issuing npx gluegun new movies
.
I added a new command and I see it is called - everything fine so far.
Now, before I start writing real functionality, I tried to setup the debugger with VScode.
I added a launch.json with the following configuration:
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/bin/my-project",
"preLaunchTask": "tsc: build - tsconfig.json",
"sourceMaps": true,
"smartStep": true,
"internalConsoleOptions": "openOnSessionStart",
"outFiles": ["${workspaceFolder}/build/**/*.js"],
}
The app gets compiled and the debugger will be attached, but unfortunately it is debugging the compiled js files. I am quite new to typescript and glue gun ... Could you please guide me through?
For anyone else that comes across this, I was able to get debugging working by adding a call to the run() function at the end of the entry TS file (default generated file is cli.ts). The launch configurations program value should be the entry TS file (not the executable script in the bin folder). In my case I also needed to accept user input from the terminal so I also added the console configuration value.
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/src/cli.ts",
"preLaunchTask": "tsc: build - tsconfig.json",
"sourceMaps": true,
"smartStep": true,
"console": "integratedTerminal",
"outFiles": [
"${workspaceFolder}/build/**/*.js"
]
}
]
Would definitely like to add more of this sort of guide to the docs. Thanks for the help @sawyerit.
@jamonholmgren Have you considered the possibility of generating a launch.json that's included with the project when its generated, so people wouldn't have to do any trial and error, hunting on the internet, or reading of docs?