From bd44c76709b693ac861ffbcc9f07e5f740bb351b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Mal=C3=BD?= <michal.maly@ibt.cas.cz> Date: Fri, 10 Dec 2021 09:11:52 +0100 Subject: [PATCH] Make cleanup script work with older versions of Node.js --- scripts/clean.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/scripts/clean.js b/scripts/clean.js index d1a61e9ec..1dbb4cd1b 100644 --- a/scripts/clean.js +++ b/scripts/clean.js @@ -7,6 +7,23 @@ const fs = require('fs'); const path = require('path'); +function removeDir(dirPath) { + for (const ent of fs.readdirSync(dirPath)) { + const entryPath = path.join(dirPath, ent); + remove(entryPath); + } + + fs.rmdirSync(dirPath); +} + +function remove(entryPath) { + const st = fs.statSync(entryPath); + if (st.isDirectory()) + removeDir(entryPath); + else + fs.unlinkSync(entryPath); +} + const toClean = [ path.resolve(__dirname, '../build'), path.resolve(__dirname, '../lib'), @@ -14,6 +31,11 @@ const toClean = [ ]; toClean.forEach(ph => { - if (fs.existsSync(ph)) - fs.rm(ph, { recursive: true }, err => { if (err) console.warn(`Failed to delete ${ph}: ${err}`); }); + if (fs.existsSync(ph)) { + try { + remove(ph); + } catch (err) { + console.warn(`Cleanup failed: ${err}`); + } + } }); -- GitLab