diff --git a/tools/cleanup.js b/tools/cleanup.js index 6f4daa3..da6a2c1 100644 --- a/tools/cleanup.js +++ b/tools/cleanup.js @@ -1,29 +1,21 @@ /* eslint-disable */ -const fs = require('fs') +const fs = require('fs/promises'); const Path = require('path') /* eslint-enable */ -const deleteFolderRecursive = (path) => { - if (fs.existsSync(path)) { - fs.readdirSync(path).forEach((file) => { - const curPath = Path.join(path, file) - if (fs.lstatSync(curPath).isDirectory()) { - deleteFolderRecursive(curPath) - } else { - fs.unlinkSync(curPath) - } - }) - fs.rmdirSync(path) +async function removeFolderRecursive(folderPath) { + try { + await fs.rm(folderPath, { recursive: true, force: true }); + console.log(`Folder and its contents removed successfully: ${folderPath}`); + } catch (err) { + console.error(`Error removing folder: ${folderPath}`, err); } } const folder = process.argv.slice(2)[0] if (folder) { - deleteFolderRecursive(Path.join(__dirname, '../dist', folder)) + removeFolderRecursive(Path.join(__dirname, '../dist', folder)); } else { - deleteFolderRecursive(Path.join(__dirname, '../dist/cjs')) - deleteFolderRecursive(Path.join(__dirname, '../dist/esm')) - deleteFolderRecursive(Path.join(__dirname, '../dist/umd')) - deleteFolderRecursive(Path.join(__dirname, '../dist/types')) + removeFolderRecursive(Path.join(__dirname, '../dist')); }