1
votes

In my project I have many grunt tasks that should process a bunch of files and put them into a folder, keeping the structure of folders the same, e.g. for a coffee translator:

/src/*.coffee -> /dest/*.js
/src/foo/*.coffee -> /dest/foo/*.js

I tried different obvious gruntfile.coffee configuration styles, none of them seem to work:

    coffee:
        compile: 
            files:
                'dest/': 'src/**/*.coffee'

--

    coffee:
        compile: 
            src: 'src/**/*.coffee'
            dest: 'dest/'

--

    coffee:
        compile:
            files: [{ src: 'src/**/*.coffee', dest: 'dest/' }]

All of the above (with and without brackets around src value) get me "Warning: Unable to write "dest/" file (Error code: EISDIR). Use --force to continue."

This one, however, turned out to be working:

    coffee:
        compile:
            expand: yes
            cwd: 'src'
            src: '**/*.coffee'
            dest:  'dest/'
            ext: '.js'

I have read the official grunt task configuration guide but couldn't find anything dest-folder related. English is not my native language - am I missing something?

Versions:

 grunt: 0.4.1
 grunt-autoprefixer: 0.1.20130615 
 grunt-cli: 0.1.9
 grunt-contrib: 0.7.0 
 grunt-contrib-clean: 0.5.0
 grunt-contrib-compass: 0.2.0
 grunt-contrib-copy: 0.4.1
 grunt-contrib-htmlmin: 0.1.3
 grunt-contrib-sass: 0.3.0
 grunt-contrib-uglify: 0.2.2
 grunt-dot-compiler: 0.5.2 
 grunt-git: 0.1.3 
 grunt-htmlcompressor: 0.1.8
 grunt-iced-coffee: 0.7.0-a
 grunt-jade: 0.4.0
 grunt-shell: 0.3.1 
1
@SindreSorhus, well, I guess the solution I found working is the only proper one, although not confirmed by anyone. Thanks for the hint!Alexander Gonchiy

1 Answers

2
votes

Do this:

files: [
  {
    expand: true, 
    cwd: 'src', 
    src: ['**/*.coffee'], 
    dest: 'dest/', 
    ext: '.js'
  }
]

A slash should be used after dest (although it will probably work without it), but the ext is necessary.