X

Technical Articles relating to Oracle Development Tools and Frameworks

  • JET
    June 21, 2018

Debugging your JET Command Line Build Scripts

Duncan Mills
Architect

The JET ojet command line tool provides you with a bunch of helpful capabilities ranging from scaffolding applications through to running them.  One of the features that I use extensively is the ability to decorate the build and serve functions with custom hooks. If you are not familiar with this feature have a look in the /scripts/hooks folder of your JET project and you will see a set of after_* and before_* javascript files that will be run when you issue a command such as "ojet serve web". 

The default implementation of these hook scripts are empty but they are there for you to carry out any extra tasks that you might want to complete as part of the standard build or build-serve processes. For example you might want to automatically package your /web output directory into a WAR file every time that you do a release build so that you can then deploy that artefact to an application server.

Now, as with any programming, it's just possible that you might make a mistake and need to be able to debug these hooks scripts.  There is only so much that you can do with console.log() after all!  

I use these ojet hook scripts a lot (and occasionally make mistakes), so I though that I'd share my setup for effectively debugging them.  I'm going to explain how to do it, based on my O/S and preferred editing environment for write node code. I'm not telling you that this is the "correct" way to do it, other IDEs and editors are available and of course details will differ from O/S to O/S. However, you should be able to apply the same principle to your chosen combination of O/S and editing environment.

Debugging in My Setup

My preferred environment is OS/X and the editor I use for node javascript is Visual Studio Code, a good all around editor for this kind of thing.  Visual Studio Code is super easy to configure for node debugging and debugging the ojet-cli. 

To configure it, pull down the Debug menu and select  Open Configurations

You are then asked to select and environment. The ojet-cli is a node program so you should select that:

This will then create a .vscode folder in the root of your project folder  and inside of that a launch.json file - it might look a little like this by default:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceFolder}/scripts/hooks/before_build.js"
    }
  ]
}

We need to edit this initial file for our purpose:

  1. We need to make it run the ojet command rather than just running the file that I had open in the editor at the time
  2. We need to tell the cli what command to run so we can debug
  3. And let's give it a better name 

After applying those changes here's the result:

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Debug ojet build",
      "program": "/usr/local/bin/ojet",
      "args": [
        "build"
      ]
    }
  ]
}

Notice how the launch program now points to the ojet script and how I've added the build command line argument.

Having saved the amended launch.json file I can now set a breakpoint in (for example) a before_build.js hook and select this profile to run:

Then we hit the breakpoint and you can do all the things you would normally do in a debugger. Here, for example, I'm inspecting the values of the configObj that is passed into the before_build hook callback:

Hopefully this will prove to be useful to you.  If you happen to use an different IDE to do the same task, why not write up a similar article, let me know and then I'll link to that here as well.
Happy debugging!

 

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.