Check if folder exist before clearing stale js

If was failing the build for environments without a prior build.

+lint
This commit is contained in:
infinite-persistence 2021-07-08 10:20:49 +08:00
parent 5769a27151
commit 06e454e9dc
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0

View file

@ -81,9 +81,12 @@ if (fs.existsSync(CUSTOM_OG_PATH)) {
let regex = /^.*\.(json|js|map)$/;
// only run on nonprod environments to avoid side effects on prod
if (!isProduction) {
fs.readdirSync(`${DIST_ROOT}/public/`)
.filter(f => regex.test(f))
.map(f => fs.unlinkSync(`${DIST_ROOT}/public/` + f));
const path = `${DIST_ROOT}/public/`;
if (fs.existsSync(path)) {
fs.readdirSync(path)
.filter((f) => regex.test(f))
.map((f) => fs.unlinkSync(path + f));
}
}
const ROBOTS_TXT_PATH = `${CUSTOM_ROOT}/robots.txt`;