Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:52:31+00:00 2026-06-15T22:52:31+00:00

I’m using http://gruntjs.com/ to create a build script that iterates over a themes.json file,

  • 0

I’m using http://gruntjs.com/ to create a build script that iterates over a themes.json file, the JSON include looks like this:

{
    "vintage" : {
        "_name"        : "vintage",
        "_long_name"   : "Vintage",
        "_js_includes" : [
            "assets/js/plugins/bootstrap/bootstrap-transition.js",
            [...]
            "assets/js/plugins/*.js",
            "assets/js/_*.js"
        ]
    },
    "pure" : {
        "_name"        : "pure",
        "_long_name"   : "Pure",
        "_js_includes" : [
            "assets/js/plugins/bootstrap/bootstrap-transition.js",
            [...]
            "assets/js/plugins/bootstrap/bootstrap-popover.js",
            "assets/js/plugins/*.js",
            "assets/js/_*.js"
        ]
    }, "mystique" : {
        "_name"        : "mystique",
        "_long_name"   : "Mystique",
        "_js_includes" : [
            [...]
            "assets/js/plugins/*.js",
            "assets/js/_*.js"
        ]
    }
}

I’m importing this file into grunt.initConfig via the

grunt.initConfig({
    themes: '<json:themes.json>',
    [...]

method, problem is that the final theme in the array mystique in my above example is somehow overriding the theme-specific tasks I’m trying to write. I want to be able to do grunt themes:pure and have it grab the action which I’m registering dynamically inside a for loop at this line for ( var new_key in themesObject ) { of the code linked here:

http://jsfiddle.net/6XKrp/3/

The relevant bits, where things aren’t working anyway, are the following:

for ( var key in themesObject ) {
    initCommand =  'themes:'+themesObject[thisThemeName]._name; // --> themes:pure
    taskString = themesObject[thisThemeName].taskString // --> lint pure:recess pure:concat pure:min pure:mincss pure:enqueue_ver
    grunt.task.registerMultiTask( initCommand, taskString, function() {
            grunt.log.writeln('Now executing task ['+this.target+'] for '+this.name+' theme...');
            grunt.log.writeln( grunt.log.writeflags( this.data, this.target ) );
            grunt.log.writeln( 'this.file = '+this.file);
     })

The above code logs the initConfig template in such a way that it seems correct and that running themes:[my-theme] should be executing, however, no actual command execution happens, only the logging aspect.

Do I need to pass the taskString along to the registerMultiTask function and repeat the task string inside the function itself, e.g.:

registerMultiTask( initCommand, taskString, function( taskString ) { taskString }) function and then do grunt.task.run(taskString) inside each registered function? I understand that this method of passing variables is intended to receive command line input, but is there a way to pass a string to the registered function?

It seems that it’s executing everything “flat” in the sense that it’s executing the top-level of the JSON config object but not recursing to the deeper nested JSON where the execution should be happening… am I right here?

For anyone who’s curious, this is Twitter Bootstrap with some modifications, basically, the goal here is to create child themes dynamically from themes.json and export them to a sibling directory to the source where the grunt tasks and everything live… should be like this:

|source-directory
|--assets
|--|--css
|--|--|--bootstrap
|--|--|--|--less
|--|--scripts
|--|--|--plugins
|pure
|--assets
|--|--css
|--|--|--main.js
|--|--|--main.min.js
|--|--js
|--|--|--scripts.js
|--|--|--scripts.min.js
| vintage
|--assets
|--|--css
|--|--|--main.js
|--|--|--main.min.js
|--|--js
|--|--|--scripts.js
|--|--|--scripts.min.js
... etc.

I have a sneaking suspicion that somehow grunt won’t let me dynamically define initConfig to fill in the blanks with the for loop in the way I’m intending… any light to shed on this would be much appreciated!

Update: since originally posting the question I’ve gotten things to the point where the dynamic assignment of themes inside initConfig is working as expected, but as of right now the template is echoing what I want but the tasks themselves are not running. I’m logging the results in each multiTask (see code here – http://jsfiddle.net/6XKrp/2/) and getting the expected result for this.data (the command I want specific to the theme->template), but the actions defined are not executing.

Update 2: things are logging as expected, and the tasks are being registered now, the problem is that they are either not executing, or just not executing recursively to the deeper levels of the JSON object, not sure why… does grunt.js not execute recursively when called in this way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:52:32+00:00Added an answer on June 15, 2026 at 10:52 pm

    Essentially, I was going about this incorrectly, not realizing that the JSON structure was non-negotiable at the top-level. You can have optional and/or multiple files, outputs, etc. nested beneath the top-level functions, but those top-level JSON data items are reserved for native functions and extensions.

    Here’s a gist of how I was able to accomplish what I outlined above:
    https://gist.github.com/4294776

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.