How to omit a folder from the output file structure of a Grunt task

58 Views Asked by At

Im running a grunt task to build an Assemble site.

My task is configured as follows:

    assemble: {

        options: {
            flatten: false,
            assets: '<%= config.dist %>',
            dist: '<%= config.dist %>',
            layout: 'default.hbs',
            layoutdir: 'templates/layouts/',
            partials: 'templates/partials/*.hbs',
        },

        pages: {
            files: { '<%= config.dist %>': ['pages/{,*/}*.hbs'] }
        }

    },

In my source files, I have a structure like this:

 pages
    cat1
    cat2

This is outputting something like:

  dist
      pages
         cat1
         cat2

How can I setup the task so that it won't include the /pages folder but still generate the subfolders?

2

There are 2 best solutions below

1
On BEST ANSWER

@jakerella is close but missing one piece, ext. It should be:

files: [
  {
    expand: true, 
    cwd: 'pages', 
    src: ['**/*.hbs'], 
    dest: '<%= config.dist %>/', 
    ext: '.html'
  }
]
0
On

So you want it to be just dist->cat1 and dist->cat2? I think you'll need to tweak your pages target a bit, but I think you're looking for the expand and cwd options:

pages: {
    files: {
        expand: true,
        cwd: 'pages/',
        src: ['**/*.hbs'],
        dest: '<%= config.dist %>',
        ext: '.html'
    }
}

(This was partially yanked from this answer.)

EDIT Added the ext option as well.