swtdrgn
swtdrgn

Reputation: 1184

Grunt: Destination File Same Name as Source File After Templating

I'm trying to template all of the files in a directory and put the result in bin/admin directory such that the destination file has the same name as the source file. However, it seems like the dest in data is the name of file and cannot be specified as a destination directory.

module.exports = function(grunt) {
  grunt.initConfig({
    'template': {
      'process-html-template': {
        'options': {
          'data': {
            'api_url': 'My blog post'
          }
        },
        'files': {
          'bin/admin/': ['src/admin/*'] // <-- Here
        }
      }
    }
  });

  grunt.loadNpmTasks('grunt-template');
  grunt.registerTask('default', ['template']);
}

What can I do to template all of the files in src/ and put them in a destination folder with the same name as the source? I tried to use bin/admin/* as the destination, but that just create a file with the filename * in bin/admin. I want to avoid listing all of the files in the source directory manually.

Upvotes: 1

Views: 916

Answers (1)

swtdrgn
swtdrgn

Reputation: 1184

I figured it out. It's an object with a src and dest attribute.

module.exports = function(grunt) {
  grunt.initConfig({
    'template': {
      'process-html-template': {
        'options': {
          'data': {
            'api_url': 'My blog post'
          }
        },
        'files': [
          {
            expand:true,
            src: 'src/admin/*',
            dest: 'bin/admin/'
          }
        ]
      }
    }
  });

  grunt.loadNpmTasks('grunt-template');
  grunt.registerTask('default', ['template']);
}

Upvotes: 2

Related Questions