Reputation: 326
I am using grunt, and I want to copy my bower dependencies when creating a production distribution
These dependencies already exist in ./components
I generate a production directory with index.html inside and want to copy only the dependencies from the bower.json file.
I thought this would be as simple as generating a list from the deps:
prodComponents = Object.keys(grunt.file.readJSON('./bower.json').dependencies)
(which produces from a simple console.log(prodComponents)
[ 'requirejs',
'requirejs-text',
'jquery',
'underscore-amd',
'backbone-amd',
'backbone.wreqr',
'backbone.babysitter',
'marionette' ]
and then simply copying the matching files:
copy:
deps:
files: [
expand: true
cwd: './components'
src: ['./<%= prodComponents %>/*']
dest: './dev/components'
]
This works, but copies ALL the components. i.e. my file spec is failing
Running "copy:deps" (copy) task
Created 15 directories
if I remove the ./ then it fails with:
Warning: Unable to read "components/Applications" file (Error code: ENOENT). Use --force to continue.
Can't help but think I'm either trying to be too clever, or nearly there with this.
What am I doing wrong with the specification of the file spec?
Thanks
Upvotes: 4
Views: 1853
Reputation: 19480
I think you are close. I would save the directories with globbing patterns applied into prodComponents
:
prodComponents = Object.keys(grunt.file.readJSON('./bower.json').dependencies).map(
function(prodComponent) {
return prodComponent + "/**/*";
}
);
So prodComponents
would contain:
["requirejs/**/*",
"requirejs-text/**/*",
"jquery/**/*",
"underscore-amd/**/*",
"backbone-amd/**/*",
"backbone.wreqr/**/*",
"backbone.babysitter/**/*",
"marionette/**/*" ]
And the copy
configuration would be:
copy:
deps:
files: [
expand: true
cwd: 'components'
src: '<%= prodComponents %>'
dest: 'dev/components'
]
Note that for you to be able to use prodComponents
in a template in this way, it needs to be set in your grunt config.
Upvotes: 2