Blog

What's New in Commandbox 4 — Ad-hoc Module Loading

Eric Peterson July 18, 2018

Spread the word

Eric Peterson

July 18, 2018

Spread the word


Share your thoughts

CommandBox has a new super power for your task runners — you can now load ad-hoc modules on the fly!

The syntax is pretty straight-forward: call loadModule passing in the path to the module you want to load.

Let me show you the beginning of a task runner I whipped up to create a PR to add adobe@2018 to all of our Travis builds. I wanted to use Hyper, an HTTP client, instead of raw cfhttp calls. First, I installed Hyper from ForgeBox in to the same folder as my task runner. Then I referenced the relative path in my loadModule call.

function run(
    string searchQuery,
	string newEngine,,
	string user,
	string forkUser,
	string githubToken
) {
    loadModule( "modules/hyper" );
    var githubAPI = getInstance( "HyperBuilder@hyper" );
    githubAPI.defaults.setAutoSerializeQueryString( false );
    githubAPI.defaults.setBaseUrl( "https://api.github.com" );
    githubAPI.defaults.setHeader( "Authorization", "token #githubToken#" );

    var results = githubAPI.get( "/search/code", {
        "q" = "#encodeForURL( searchQuery )#+user:#user#+filename:.travis.yml"
    } );

    /* .... */
}

Now I can update all my own personal modules that use Travis CI to test on Adobe 2018 with my task runner:

CommandBox:>task run taskFile=AddEngineToTravisBuilds :searchQuery=adobe@2016 :newEngine=adobe@2018 :user=elpete :forkUser=elpete :githubToken=hahahahahaha

You can check out the full code here in this gist.

There you have it! It's even easier to use task runners now for those one off commands. loadModule is available on the latest stable version of CommandBox (4.1.0).

Recent Entries

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Hackers demand a ransom to restore data from my ColdFusion web applications!

Unfortunately, we often hear this message from clients who thought it would never happen to them... until it did. Some believed they could delay the expense of Implementing ColdFusion security best practices for one year, while others were tempted to put it off for just a few months. However, in today's rapidly evolving digital landscape, the security of web applications, including ColdFusio...

Cristobal Escobar
Cristobal Escobar
April 16, 2024
Ortus March Newsletter

Ortus March Newsletter

Welcome to Ortus Solutions’ monthly roundup, where we're thrilled to showcase cutting-edge advancements, product updates, and exciting events! Join us as we delve into the latest innovations shaping the future of technology.

Maria Jose Herrera
Maria Jose Herrera
April 01, 2024
Into the Box 2024 Last Early Bird Days!

Into the Box 2024 Last Early Bird Days!

Time is ticking, with less than 60 days remaining until the excitement of Into the Box 2024 unfolds! Don't let this golden opportunity slip away; our exclusive Early Bird Pricing is here for a limited time only, available until March 31st. Why wait? Secure your seat now and take advantage of this steal!

Maria Jose Herrera
Maria Jose Herrera
March 20, 2024