I recently gave the npm package grunt-contrib-copy
a go. I had some issues with it creating a folder level more than I would have expected. This turns out to be due to it copying from the current working directory.
I found the following two posts on the issue and it took me some time to figure it out:
- https://stackoverflow.com/questions/23875740/grunt-contrib-copy-files-are-not-copied-to-the-correct-locaiton?lq=1
- https://stackoverflow.com/questions/19297067/how-to-copy-files-without-the-full-path-with-grunt-js
I tried the above but none of it worked. What the posts did not say is that the CWD means "current working directory"! In my example I have the following folder structure and the result I want:
Root
---website //Gruntfile located here
------css
------js
------index.html
------page.html
---gruntfile.js
---build
------css //expected newly created
------js //expected newly created
------index.html //expected newly created
------page.html //expected newly created
So I am executing my grunt commands from "root". However when copy is run from this location it takes the "website" folder with it. That I did not want. I wanted what is portrayed in the above. In order to do this I needed to understand the cwd parameter. This has to be set to "website/" in the above, so my current working directory is "website/". Then I can just set "**" as source. That gave me the above result. My grunt task look like the following:
copy: {
main: {
files: [
{
expand: true,
cwd: 'website/', //This is the important part
src: ['**'],
dest: '../build/'
},
],
},
},
I hope this helps you and if it does, please let me know in the comments!