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).

Add Your Comment

Recent Entries

Into the Box is Going Online, Register Now!

Into the Box is Going Online, Register Now!

Dive into the Future of Web Development with Into the Box 2024 - now going global and online! No matter where you are, you're invited to join us for an amazing and enriching two-day experience on May 16th and 17th, packed with groundbreaking insights, expert sessions, and game-changing announcements.

Maria Jose Herrera
Maria Jose Herrera
May 01, 2024
Into the Box 2024: Your Gateway to the Future of Tech!

Into the Box 2024: Your Gateway to the Future of Tech!

Are you ready to advance your coding skills? The future of Modern Web Development awaits at Into the Box 2024, and we're thrilled to announce that due to high demand, we're extending our Early Bird pricing for an additional week!

Maria Jose Herrera
Maria Jose Herrera
April 26, 2024