Last active
December 9, 2015 22:38
-
-
Save cowboy/4338353 to your computer and use it in GitHub Desktop.
grunt 0.4 file.expandMapping and templates
This file contains hidden or 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
module.exports = function(grunt) { | |
grunt.initConfig({ | |
stuff: { | |
dest: 'foo/', | |
ext: '.bar', | |
}, | |
log_files: { | |
my_target: { | |
files: grunt.file.expandMapping('**/*.js', '<%= stuff.dest %>', { | |
cwd: 'test/fixtures/expand', | |
rename: function(destBase, destPath) { | |
return destBase + destPath.replace(/\.js$/, '<%= stuff.ext %>'); | |
} | |
}) | |
} | |
} | |
}); | |
console.log('\nThe files object generated with grunt.file.expandMapping:'); | |
console.log(grunt.config('log_files.my_target.files')); | |
console.log(''); | |
grunt.registerMultiTask('log_files', 'Log src/dest pairs in a files object.', function() { | |
console.log('%s -> %s', this.file.src, this.file.dest); | |
}); | |
grunt.registerTask('update_stuff', 'Update the stuff object', function(dest, ext) { | |
grunt.config.set('stuff', {dest: dest + '/', ext: '.' + ext}); | |
}); | |
}; |
This file contains hidden or 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
# Given the source files: | |
# test/fixtures/expand/js/bar.js | |
# test/fixtures/expand/js/foo.js | |
$ grunt log_files update_stuff:aaa:bbb log_files | |
The files object generated with grunt.file.expandMapping: | |
{ '<%= stuff.dest %>js/bar<%= stuff.ext %>': 'test/fixtures/expand/js/bar.js', | |
'<%= stuff.dest %>js/foo<%= stuff.ext %>': 'test/fixtures/expand/js/foo.js' } | |
Running "log_files:my_target" (log_files) task | |
test/fixtures/expand/js/bar.js -> foo/js/bar.bar | |
test/fixtures/expand/js/foo.js -> foo/js/foo.bar | |
Running "update_stuff:aaa:bbb" (update_stuff) task | |
Running "log_files:my_target" (log_files) task | |
test/fixtures/expand/js/bar.js -> aaa/js/bar.bbb | |
test/fixtures/expand/js/foo.js -> aaa/js/foo.bbb | |
Done, without errors. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment