Skip to content

Instantly share code, notes, and snippets.

@abierbaum
Last active December 14, 2015 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abierbaum/5065053 to your computer and use it in GitHub Desktop.
Save abierbaum/5065053 to your computer and use it in GitHub Desktop.
Demonstrate a potential bug in file array format dest referencing.

I have been trying to find a way to get a list of the dest files from a copy task so I can use them in a later task through a template. It does not seem to work.

Reproduction:

  • npm install
  • ./node_modules/.bin/grunt
  • See the output of the dest files for copy and concat and how copy has none
/**
* Contents of a.
*/
a = 10;
/**
* Contents of b.
*/
b = 10;
module.exports = function(grunt) {
// -- LOAD GRUNT PLUGINS -- //
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerMultiTask('debug_files', 'debugs files passed in',
function() {
grunt.log.writeln('Inside task: ' + this.nameArgs);
try {
var files = this.filesSrc;
grunt.log.writeln('files: ' + files);
}
catch(ex) {
grunt.log.writeln('no files exception');
}
}
);
debugger;
var src_files = ['a.js', 'b.js'],
build_dir = 'build';
// --- CREATE CONFIGURATION --- //
var config = {
pkg: grunt.file.readJSON('package.json'),
// Clean up the build area
clean: {
options: {
force: true
},
full : [build_dir]
},
copy: {
dev: {
files: [
{ dest: 'build/', src: src_files }
]
},
prod: {
src: src_files,
dest: 'build/prod/'
}
},
concat: {
prod: {
files: [
{ dest: 'build/prod.js', src: src_files }
]
},
dev: {
src: src_files,
dest: 'build/dev.js'
}
},
// Write out the dest values from the items above.
// I would expect that all of these would print out valid files,
// but the ones that use the files array format don't seem to work.
debug_files: {
concat_prod_files: {
src: ['<%= concat.prod.dest %>']
},
concat_dev_files: {
src: ['<%= concat.dev.dest %>']
},
copy_dev_files: {
src: ['<%= copy.dev.dest %>']
},
copy_prod_files: {
src: ['<%= copy.prod.dest %>']
}
}
};
// Register config and aliases
grunt.initConfig(config);
grunt.registerTask('default', ['clean', 'copy', 'concat', 'debug_files']);
};
{
"name": "copy_bug",
"version": "1.0.0",
"devDependencies": {
"grunt": "~0.4.0",
"grunt-cli": "~0.1.0",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-copy": "~0.4.0",
"grunt-contrib-concat": "~0.1.3",
"node-inspector": ">= 0.2.0beta3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment