grunt-contrib-copy copy directory into another without root dir

304 views Asked by At

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?

1

There are 1 answers

1
Fraser On

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}