title: Compiling coffeescript files with grunt
body: <p>I am trying to write a grunt task to compile numerous .coffee files to corresponding .js files and .map files using grunt. I have the grunt coffee plugin, but there are some problems:</p>
  
  <ol>
  <li>It compiles all files into one common destination folder instead of keeping the .js files in same folder as the .coffee file.</li>
  <li>It merges two .coffee files of the same name in different directories into one file in the destination directory.</li>
  </ol>
  
  <p>Please help solving these:</p>
  
  <p>Grunt plugin: <a href="https://www.npmjs.org/package/grunt-contrib-coffee" rel="nofollow noreferrer">https://www.npmjs.org/package/grunt-contrib-coffee</a></p>
  
  <p>Gruntfile.coffee:</p>
  
  <pre><code>module.exports = (grunt) -&gt;
    grunt.initConfig(
      pkg: grunt.file.readJSON 'package.json'
      coffee:
        coffee_to_js:
          options:
            bare: true
            sourceMap: true
          expand: true
          flatten: true
          cwd: "client"
          src: ["**/*.coffee"]
          dest: 'client'
          ext: ".js"
    )
  
    #Load Tasks
    grunt.loadNpmTasks 'grunt-contrib-coffee'
    grunt.registerTask('compile', ['coffee']);
  
    null
  </code></pre>
  
  <p>Compiled Gruntfile.js</p>
  
  <pre><code>module.exports = function(grunt) {
    grunt.initConfig({
      pkg: grunt.file.readJSON('package.json'),
      coffee: {
        coffee_to_js: {
          options: {
            bare: true,
            sourceMap: true
          },
          expand: true,
          flatten: true,
          cwd: "client",
          src: ["**/*.coffee"],
          dest: 'client',
          ext: ".js"
        }
      }
    });
    grunt.loadNpmTasks('grunt-contrib-coffee');
    grunt.registerTask('compile', ['coffee']);
    return null;
  };
  </code></pre>
  
  <p>File structure before compile:</p>
  
  <p><img src="https://i.stack.imgur.com/DeEGe.png" alt="enter image description here"></p>
  
  <p>File structure after compile:</p>
  
  <p><img src="https://i.stack.imgur.com/Sma7u.png" alt="enter image description here"></p>
  
  <p>Compilation message:</p>
  
  <p><img src="https://i.stack.imgur.com/3p9aE.png" alt="enter image description here"></p>