Created
August 6, 2012 14:36
-
-
Save drsm79/3274880 to your computer and use it in GitHub Desktop.
Bundle task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bundle: { | |
// Files to bundle up that aren't css/js managed by release. Copied into | |
// same directory structure | |
files: ['*.html'], | |
// Folders to bundle up that aren't managed by release. Copy files and | |
// folders from src (key) to destination (value), relative to the | |
// destination parameter. | |
folders: {'assets/img':'assets/img', 'dist/release':''}, | |
destination: 'bundle' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copy files and folders into a new directory structure | |
grunt.registerTask("bundle", "Bundle files and directories.", function(){ | |
// bail if release hasn't run | |
grunt.task.requires('release'); | |
// TODO: ditch this when grunt v0.4 is released | |
grunt.util = grunt.util || grunt.utils; | |
var _ = grunt.util._; | |
var options = _.defaults(grunt.config("bundle") || {}, { | |
destination: 'bundle', | |
files: ['*.html'], | |
folders: {'dist': ''} | |
}); | |
grunt.file.mkdir(options.destination); | |
function recurse_expand(source, dest){ | |
var files = {}; | |
grunt.file.recurse(source, function(abspath, r, s, f){ | |
files[abspath] = abspath.replace(source, dest); | |
}); | |
return files; | |
} | |
// Copy over (wild carded) files | |
_.each(options.files, function(f){ | |
_.each(grunt.file.expand(f), function(source){ | |
var dest = options.destination + '/' + source; | |
grunt.log.writeln('copy ' + source + ' to ' + dest); | |
grunt.file.copy(source, dest); | |
}); | |
}); | |
// Copy over (wild carded) directory contents | |
_.each(options.folders, function(dest, origin, list){ | |
_.each(recurse_expand(origin, dest), function(newpath, path, l){ | |
var destination = options.destination + '/' + newpath; | |
destination = destination.replace('//', '/'); | |
grunt.log.writeln('copy ' + path + ' to ' + destination); | |
grunt.file.copy(path, destination); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Build a release (lint, test, minify css/js) then copy resulting | |
// files and all other assets into a bundle directory | |
grunt.registerTask("package", "release bundle"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment