[英]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. 我遇到一个问题,即使我否定了父文件夹以防止删除该文件夹,我的build:cleanfolder任务也会删除该父文件夹。
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: 这就是build:cleanfolder任务的样子:
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). 基本上,“ ../”和“ ParentFolder”都被否定,但是无论如何,del( https://www.npmjs.com/package/del )仍会删除父文件夹(和其他内容)。 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. 您可以使用
node-glob
的cwd
选项指定当前工作目录。 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. 这将删除一切
ParentFolder
除了src
和gulp
文件夹及其各自的内容。
This was the working solution I was given from the Github repo: 这是我从Github回购中获得的有效解决方案:
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
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.