简体   繁体   中英

Negating Parent Folder with Gulp Del not working

I'm running into a problem where my build:cleanfolder task deletes the parent folder even though I negated the parent folder to prevent it get deleted.

I use the following folder structure:

Parent Folder
- gulp (gulp file/content)
- src (working dir)

And this is what the build:cleanfolder task looks like:

gulp.task('build:cleanfolder', function() {
    del([
        '!ParentFolder',
        '!../',
        '!../gulp',
        '!../src',
        '../**'
        ], {force: true});
});

Basically both "../" and "ParentFolder" are negated, but somehow del ( https://www.npmjs.com/package/del ) still deletes the parent folder (and other content). Is there any other way to prevent this or am I missing something obvious?

Edit: Putting the '../**' on top of that list doesn't work either unfortunately

You can use the cwd option of node-glob to specifiy the current working directory. All globbing patterns will be relative to this directory:

gulp.task('build:cleanfolder', function() {
    del([
        '**',
        '!gulp/**',
        '!src/**',
        ], { force: true, cwd: '..' });
});

This deletes everything in ParentFolder except for the src and gulp folders and their respective contents.

This was the working solution I was given from the Github repo:

gulp.task('build:cleanfolder', function() {
  return del([               // Return the Promise!
        '../**',
        '!..',               // i.e. '../../ParentFolder'; Note: no trailing '/'!
        '!../gulp/**',       // exclude gulp and everything within
        '!../src/**',        // exclude src and everything within
        ], {
            force: true,
            //dryRun: true  // just for debugging
        }
  ) //.then(console.log);  // just for debugging
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM