title: Dynamic Mapping and Concat with Grunt Uglify
body: <p>I'm trying to use <a href="http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically" rel="nofollow">dynamic mapping</a> AND concat Javascript files with Grunt Uglify.</p>
  
  <p>I have the following which is not working correctly.</p>
  
  <p>Here is my folder structure:</p>
  
  <pre><code>javascript
      |- account
          |- custom.js
      |- bills
          |- billing-one.js
          |- billing-two.js
      |- test (output folder)
  </code></pre>
  
  <p>Here is what I'm expecting:</p>
  
  <pre><code>javascript
      |- account
          |- custom.js
      |- bills
          |- billing-one.js
          |- billing-two.js
      |- test
          |- billing-one.min.js (this file includes billing-one.js AND custom.js)
          |- billing-two.min.js (this file includes billing-two.js AND custom.js)
  </code></pre>
  
  <p>This is what I'm currently getting:</p>
  
  <pre><code>javascript
      |- account
          |- custom.js
      |- bills
          |- billing-one.js
          |- billing-two.js
      |- test
          |- bills
              |- billing-one.min.js (this file includes just billing-one.js)
              |- billing-two.min.js (this file includes just billing-two.js)
          |- account 
              |- custom.min.js (this file includes just custom.js)
  </code></pre>
  
  <p>It is not including the custom.js file but instead creates a 2 folders <code>test/account/custom.min.js</code>
  'test/bills/billing-one.js' - see above</p>
  
  <pre><code>options: {
      beautify: true,
      mangle: false,
      compress: false,
      preserveComments: 'all'
  },
  files: [
    {
      expand: true,     // Enable dynamic expansion.
      cwd: 'javascript/',      // Src matches are relative to this path.
      src: [[bills/*.js'], 'account/custom.js'], // Actual pattern(s) to match.
      dest: 'test/',   // Destination path prefix.
      ext: '.min.js',   // Dest filepaths will have this extension.
      extDot: 'first'   // Extensions in filenames begin after the first dot
    },
  ],
  </code></pre>
  
  <p>I want all the Javascript files within the <code>bills/</code> folder to contain custom.js</p>
  
  <p>So if there are 2 files:
  <code>bills/billing-one.js</code>
  <code>bills/billing-two.js</code></p>
  
  <p>I would expect test/ folder to include</p>
  
  <p><code>test/billing-one.min.js</code> (this file would contain billing-one + custom.js)
  <code>test/billing-two.min.js</code> (this file would contain billing-two + custom.js)</p>
  
  <p>I don't want to hard code the file names in. If more files are added to<code>bills/</code> folder the should be concat and output to the <code>test/</code> folder.</p>
  
  <p>Any help much appreciated.</p>
  
  <p><strong>UPDATE SINCE ANSWER ACCEPTED:</strong></p>
  
  <p>Use the follow updated code to make sure this works as intended - otherwise you'll run into errors when running GRUNT.</p>
  
  <p>I did try adding this to the answer by submitting an edit for review. But it got rejected, twice, by the all knowing all superior mods... when in fact it's a valid input and improves on the answer given. Note the <code>[]</code>, <code>cwd</code> and <code>src</code> changes.</p>
  
  <pre><code>files: [{
      expand: true,
      cwd: 'javascript/bills/',
      src: ['*.js'],
      dest: 'test/',
      ext: '.min.js',
      extDot: 'first'
  }],
  </code></pre>