gluegun icon indicating copy to clipboard operation
gluegun copied to clipboard

How to debug using vscode debugger?

Open MarceloBritoWD opened this issue 4 years ago • 7 comments

It has a way to debug my cli using vscode or something like that? I didn't find any information about it.

MarceloBritoWD avatar Sep 29 '19 06:09 MarceloBritoWD

Hi @MarceloBritoWD!

I should write up a debugging guide, that's a great idea.

Is there something in particular you're having trouble debugging?

jamonholmgren avatar Sep 30 '19 18:09 jamonholmgren

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

MarceloBritoWD avatar Sep 30 '19 18:09 MarceloBritoWD

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.

jamonholmgren avatar Sep 30 '19 23:09 jamonholmgren

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?

phhoef avatar Sep 15 '21 18:09 phhoef

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"
            ]
        }
    ]

sawyerit avatar Dec 29 '21 05:12 sawyerit

Would definitely like to add more of this sort of guide to the docs. Thanks for the help @sawyerit.

jamonholmgren avatar Jan 19 '22 19:01 jamonholmgren

@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?

ElonVolo avatar Apr 19 '22 22:04 ElonVolo