UNPKG

@bemedev/core

Version:

The core library of @bemedev

38 lines (35 loc) 1.17 kB
import { config } from '../constants.js'; import { getFolderPath } from '@bemedev/codebase/lib/helpers.js'; import edit from 'edit-json-file'; import { rmSync } from 'fs'; import { join } from '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 = join(cwd, config.json); let file = edit(jsonPath); const root = file?.get('path'); if (root) { const fullPath = getFolderPath(root); try { 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 { rmSync(jsonPath, { force: true }); console.log(`Configuration file ("${config.json}") has been removed.`); } catch { console.error(`Error while removing the configuration file ("${config.json}").`); } } export { destroy }; //# sourceMappingURL=destroy.js.map