0

I'm trying to create a very simple copy task but it seems grunt-copy is not made for my usecase :-(.

All I needed is the following:

Source directory structure:

vendor
  L subdir1
      L assets
          L subdir2
              L subdir3
                  L file1.js
              L file2.js
  L subdir4
      L subdir5
          L subdir6
              L file3.js 

config:

src: [
   'vendor/subdir1/assets/**/*',
   'vendor/subdir4/**/*'
],
dest: 'build/assets/'

Destination file structure:

build
  L assets
      L subdir2
          L subdir3
              L file1.js
          L file2.js
      L subdir5
          L subdir6
              L file3.js

As you can see I want to preserve directory structure, but omit the basepath in src. Normally this can be done with cwd. But actually for this case I would need multiple cwds.

Sounds like a fair requirement to me. Is there really no easy solution?

Thanks for help,

Endian
  • 13
  • 1
  • 4

1 Answers1

0

You can use more comma separated 'file' definitions in your Gruntfile.js:

copy: {
    dist: {
        files: [
            {
                src: ['assets/**/*'],
                dest: 'build/assets/',
                cwd: 'vendor/subdir1'
            },
            {
                src: ['**/*'],
                dest: 'build/assets/',
                cwd: 'vendor/subdir4/'
            }]
    }
}

In Gruntfile you then run for example this task:

grunt.registerTask('build', [
    copy:dist
]);

And then run the task grunt build

jan2jen
  • 33
  • 6
  • Sorry for the late answer. Of course there are more than 2 (actually an undefined number of) subdirs in vendor. So this won't work. Thx, anyway. I did it completely different now and could so elude the problem. – Endian Aug 14 '14 at 12:00