I'm fairly new to Grunt. I am trying to copy each sub directory from one location and place each in another destination directory. I am doing this in a custom grunt task because I cannot be sure how many sub directories will exist in the source location. The issue I am facing is each time a copy is performed the previous directory structure is overridden.
I've tried setting 'cwd' to root of the sub directories from which I am copying but the problem remains.
Folder structure:
container
|
- dist/ *I want to copy each src folder here
|
GruntFile.js
subapps
|
- thing1/dist
| *I want to copy each of these dirs (thing1/dist, thing2/dist) to container/dist eg: container/dist/thing1/dist, container/dist/thing2/dist
- thing2/dist
My task:
grunt.registerTask('copySubApps', function () {
grunt.file.expand({filter : 'isDirectory'}, '../subapps/*/').forEach(function (subapp) {
var subAppName = path.basename(subapp);
var subAppDest = grunt.template.process('dist/subapps/<%= appName %>/dist/',{data:{appName:subAppName}});
grunt.config('subAppDest', subAppDest);
grunt.config('subAppName', subAppName);
grunt.task.run('copy:subapp');
});
});
Configuration:
copy: {
subapp: {
expand: true,
src: '**/*',
dest: '<%= subAppDest %>',
cwd: '../subapps/<%= subAppName %>/dist'
}
}
Each subsequent copy overwrites the one preceding it. How do I avoid this? I'm sure that this is a pretty naive approach so suggestions and guidance are very welcome. :-) Once this is working I need to further filter which items from each sub folder are copied. eg subapps/thing1/style, !subapps/thing1/common etc.
Thanks!