assemble/grunt-assemble

Build callback in grunt

Closed this issue · 2 comments

Moved over from (assemble/assemble) [https://github.com/assemble/assemble]. Sorry about that, @jonschlinkert

Hello guys, I've been search high and low for reference on this but to no avail, thus my presence here.

Background
I'm running multiple assemble targets and would like to add a callback that copies a folder of assets (CSS, JS, etc) to the destination directory every time a target build is complete—preferably by referencing to a grunt-contrib-copy module already present.

What does the grunt file look like?

// some grunt configs
assemble: {

            options: {
                site:         '<%= site %>',
                assets:       '<%= site.assets %>',
                data:         '<%= site.data %>',
                helpers:      '<%= site.helpers %>',
                layout:       '<%= site.layout %>',
                layoutdir:    '<%= site.layouts %>',
                partials:     '<%= site.includes %>',
                plugins:      '<%= site.plugins %>'
            },

            target_1: { options: { site_id: 'foobar' }, expand: true, cwd: '<%= site.pages %>/foo/bar', src: '<%= site.pages_src %>', dest: '<%= site.dest %>/foo/bar' },
            target_2: { options: { site_id: 'foobar2' }, expand: true, cwd: '<%= site.pages %>/foo/bar2', src: '<%= site.pages_src %>', dest: '<%= site.dest %>/foo/bar2' }

        }
// more grunt configs

I'm aware of the build method found on this page but I haven't been able to figure out on how to implement it within the grunt file.

Thank you for taking time to read this and activating your brain cells in coming up with an answer.

no worries!

Unless I'm missing something, I think you just need to define tasks for that:

grunt.registerTask('foo', ['assemble:foo', 'copy:foo']);
grunt.registerTask('bar', ['assemble:bar', 'copy:bar']);
grunt.registerTask('baz', ['assemble:baz', 'copy:baz']);

If this isn't what you mean, perhaps take a look at the creating tasks page on the grunt docs. hope this helps.

(closing though since we try to keep issues focused on bugs and feature requests)

Ah, I was looking for something more dynamic:

// some grunt configs
assemble: {

            options: {
                site:         '<%= site %>',
                assets:       '<%= site.assets %>',
                data:         '<%= site.data %>',
                helpers:      '<%= site.helpers %>',
                layout:       '<%= site.layout %>',
                layoutdir:    '<%= site.layouts %>',
                partials:     '<%= site.includes %>',
                plugins:      '<%= site.plugins %>',
                build: function(options, dest) {
                    // something along the lines of:
                    some.grunt.task.caller('copy', {src: 'path/of/src', dest: dest});
                }
            },

            target_1: { options: { site_id: 'foobar' }, expand: true, cwd: '<%= site.pages %>/foo/bar', src: '<%= site.pages_src %>', dest: '<%= site.dest %>/foo/bar' },
            target_2: { options: { site_id: 'foobar2' }, expand: true, cwd: '<%= site.pages %>/foo/bar2', src: '<%= site.pages_src %>', dest: '<%= site.dest %>/foo/bar2' }

        }
// more grunt configs

... because we may end up with 60 assemble targets, but if there isn't an option that's as dynamic, I'll look into what you're recommending. Thanks @jonschlinkert!