1

I am trying to copy a structure like so:

src
|-a
|-b
|-c
||-ca
||-cb
dest
|-a
|-b
|-c
||-ca
||-cb

However, I appear to not be able to accomplish this without the src directory itself appearing in the dest directory. ie

src
|-a
|-b
|-c
||-ca
||-cb
dest
|src
||-a
||-b
||-c
|||-ca
|||-cb

My copy config is set up like so:

files: [
    {src: [targetDirectory+"index.html"], dest: buildDirectory, expand: true},
    {src: [targetDirectory+"*.png"], dest: buildDirectory, expand: true},
    {src: [targetDirectory+minJSDestination], dest: buildDirectory, expand: true},
    {src: [targetDirectory+minCSSDestination], dest: buildDirectory, expand: true},
    {src: [targetDirectory+"assets/fonts/**.*"], dest: buildDirectory, expand: true},
    {src: [targetDirectory+"assets/images/**.*"], dest: buildDirectory, expand: true},
    {src: [targetDirectory+"assets/partials/**.*"], dest: buildDirectory, expand: true},
    {src: [targetDirectory+"src/*.js"], dest: buildDirectory, expand: true}
]

I've tried the flatten option which removes the 'src' directory from dest, but it also removes the other directories and puts each of the files at the root level of dest.

I've tried setting 'cwd' to the destination and source directories but this just seems to prevent the copy all together.

I'm sure there must be an option which allows this but I'm yet to find it. Anyone have any ideas?

Fraser
  • 14,036
  • 22
  • 73
  • 118
  • Possible duplicate of [How to get Grunt-Contrib-Copy to copy files/directories relative to given source path](https://stackoverflow.com/questions/22697919/how-to-get-grunt-contrib-copy-to-copy-files-directories-relative-to-given-source) – 9ilsdx 9rvj 0lo Oct 01 '18 at 09:57

1 Answers1

2

I solved it. I needed to remove the base directory from the src and add in the cwd:

ie:

{src: ["src/*.js"], dest: buildDirectory, expand: true, cwd: srcDirectory}

rather than

{src: [srcDirectory+"src/*.js"], dest: buildDirectory, expand: true, cwd: srcDirectory}
Fraser
  • 14,036
  • 22
  • 73
  • 118