Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grunt-contrib-clean to remove all folders/files except for one folder and its contents

How would you negate the cleaning of a particular folder using grunt-contrib-clean. Negating the match doesn't appear to work.

clean: {
    plugins: [ 
        'app/plugins/myplugin',
        '!app/plugins/myplugin/assets'
    ]
}

I've tried a couple different negation patterns, such as:

'!app/plugins/myplugin/assets'
'!app/plugins/myplugin/assets/**'

as well as, reversing the positions in the array in case that mattered. Can't seem to hold onto the assets folder/contents on clean. The assets folder contains jQuery, AngularJS, and built Bootstrap (SASS), which I don't want to have to keep copying/building, seems a waste of time.

like image 348
mtpultz Avatar asked Jul 04 '14 06:07

mtpultz


1 Answers

I quickly set up a folder structure like you're referencing and tried the following, that works for me:

clean: {
    options: {
        'no-write': true
    },
    plugins: ['app/plugins/myplugin/**/*', '!app/plugins/myplugin/assets/**']
}

The first wildcard selects all files inside the myplugin folder and all subfolders (but not the directory myplugin itself!), while the negation deselects the whole assets directory including all subfolders and files.

You should remove the options field for real testing, as no-write: true is only simulating a clean but doesn't actually delete files.

Hope that helps!

like image 95
ConcurrentHashMap Avatar answered Nov 03 '22 18:11

ConcurrentHashMap