UNPKG

@bemedev/core

Version:

The core library of @bemedev

40 lines (36 loc) 1.27 kB
'use strict'; var scripts_constants = require('../constants.cjs'); var helpers_js = require('@bemedev/codebase/lib/helpers.js'); var edit = require('edit-json-file'); var fs = require('fs'); var path = require('path'); /** * Supprime un fichier JSON ou un dossier de façon récursive. * @param targetPath Chemin absolu ou relatif du fichier ou dossier à supprimer */ function destroy() { const cwd = process.cwd(); const jsonPath = path.join(cwd, scripts_constants.config.json); let file = edit(jsonPath); const root = file?.get('path'); if (root) { const fullPath = helpers_js.getFolderPath(root); try { fs.rmSync(fullPath, { recursive: true, force: true }); console.log(`Folder ("${root}") has been removed.`); } catch { console.error(`Error while removing the folder ("${root}").`); } } file = undefined; try { fs.rmSync(jsonPath, { force: true }); console.log(`Configuration file ("${scripts_constants.config.json}") has been removed.`); } catch { console.error(`Error while removing the configuration file ("${scripts_constants.config.json}").`); } } exports.destroy = destroy; //# sourceMappingURL=destroy.cjs.map