我正在检查项目中的特定文件夹是否包含 .bundle 文件,如果有,请将其移动到某个位置,否则使用默认值。我遇到的问题是,我无法使用查看来检查文件是否存在 fs-extra 。
.bundle
fs-extra
这就是我现在拥有的,如果它存在或不存在,它仍然记录为真。
fs.exists(themeDir + "Lights.bundle").then(() => { console.log("true"); }
据我所知,如果文件不存在,它应该抛出一个promise错误。
结果我只需要使用 fs.existsSync()
fs.existsSync()
var lightsBundlePath = buildDir + `templates/Lights.bundle`; if ((themeLightsBundle = fs.existsSync(themeDir + `Lights.bundle`))) { lightsBundlePath = themeLightsBundle; }