How to get feed output of a grunt task to another grunt task?

543 Views Asked by At

I'm not sure if grunt can do this. I have two grunt tasks that I want to run. The first task is to create a mock post and the second is to run penthouse task to inline css. Any hacky way is welcome.

This is the exec task that I have to run to create a blog post in WordPress.

    exec: {
        create_mock: {
            cmd: 'cd ~/MyProjects/project/vip-quickstart && vagrant ssh -c \'sh /srv/www/wp-content/themes/vip/the-theme/bin/mock-post.sh\'',
            callback: function(err, stdout, stderr) {
                grunt.log.write('stdout: ' + stdout); // This is the url of the created post.
            }

        }
    },

The output is the url that the blog post was created and I have this penthouse task to run which I need to feed in the url that this task will look to get all the above-the-fold css.

   penthouse: {
        singular: {
            outfile: 'assets/css/inline/_singular.css',
            css: 'assets/css/theme.css',
            minify: true,
            url: $URL, // << I want to feed in the url from the previous task to here.
            width: 1300,
            height: 900
        }
    },

The hacky way I can think of is to save the out to a file and read that in penthouse task but I think there's must be a better way to do this.

Thanks a lot.

1

There are 1 best solutions below

0
Pete TNT On

You can use grunt.config.set to set the value directly (or to another property and using it with grunt.template if you need to use the value multiple times.)

 exec: {
    create_mock: {
        cmd: 'cd ~/MyProjects/project/vip-quickstart && vagrant ssh -c \'sh /srv/www/wp-content/themes/vip/the-theme/bin/mock-post.sh\'',
        callback: function(err, stdout, stderr) {
            grunt.config.set("penthouse.singular.url", stdout);
        }

    }
},