gpt4 book ai didi

javascript - 在 Grunt.js 中使用 clean 或 clean-empty 任务删除空文件夹

转载 作者:行者123 更新时间:2023-12-03 12:37:42 28 4
gpt4 key购买 nike

我正在尝试创建一个 Grunt 任务来清理目录中的所有文件、子目录及其文件等。

我可以删除所有文件,但文件夹始终保留。

 clean: {
preview: ["live_preview>/**/*"],
dist: ["dist/**/*"]
},
cleanempty: {
options: {
folders: true
},
src: ['live_preview/**', 'tmp/**']
},

我正在尝试清空 live_preview 文件夹。我尝试了几种通配符的组合。更令人费解的是,-v 的终端输出使它看起来好像有效,但空文件夹仍然存在。

Verifying property cleanempty.src exists in config...OK
Files: live_preview, live_preview/fonts, live_preview/images, live_preview/partials, live_preview/partials/elements, live_preview/scripts, live_preview/scripts/data, live_preview/styles, live_preview/views, tmp, tmp/styles, tmp/styles/live_preview.css, tmp/styles/live_preview.css.map, tmp/styles/theme.css, tmp/styles/theme.css.map -> src
Options: folders
Options: files, folders, force=false, no-write=false
Options: files, folders, force=false, no-write=false
Cleaning live_preview/views...Deleting live_preview/views...OK
OK
Cleaning live_preview/styles...Deleting live_preview/styles...OK
OK
Cleaning live_preview/scripts/data...Deleting live_preview/scripts/data...OK
OK
Cleaning live_preview/partials/elements...Deleting live_preview/partials/elements...OK
OK
Cleaning live_preview/images...Deleting live_preview/images...OK
OK
Cleaning live_preview/fonts...Deleting live_preview/fonts...OK
OK

Done, without errors.

最佳答案

我正在使用 Grunt 任务来清理临时目录,当我运行该任务时,整个文件夹将被删除。我假设您使用的是相同的插件,但只是为了确定:https://github.com/gruntjs/grunt-contrib-clean

这是我的设置的简化版本:

clean: {
tests: ['testXmls'] // testXmls is a directory in the top level of my app
}

grunt.registerTask('clean-tests', ['clean:tests']);

当我运行 grunt clean-tests 时,testXmls 目录及其所有内容都会被删除。

我认为你的问题是你在目录路径中使用通配符来告诉 grunt 删除 live_preview 的所有子目录。如果您想删除顶级目录,则只需使用它即可。其中包含的所有文件和目录都将被递归删除。认为 rm -rf

尝试:

clean: {
preview: ["live_preview"],
dist: ["dist"]
}

此外,在您的终端中,当您看到:

Deleting live_preview/styles

这只是意味着它正在删除 styles 目录 - 它为您提供了/styles 的完整路径,而 live_preview 是该路径的一部分,这就是您看到它的原因 - 没有任何迹象表明 live_preview 本身已被删除。所以输出实际上是正确的。

关于javascript - 在 Grunt.js 中使用 clean 或 clean-empty 任务删除空文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23661807/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com