{"version":3,"sources":["../src/clean.ts"],"names":[],"mappings":";AAyBA,OAAO,EAAC,MAAM,EAAC,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,YAAY,EAAC,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAC,GAAG,EAAC,MAAM,aAAa,CAAC;AAShC,qBAAa,KAAK;IACjB,SAAgB,MAAM,EAAE,YAAY,CAAC;IACrC,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,GAAG,EAAE,GAAG,CAAC;gBAEb,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,GAAG;IAahD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAqCpD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;CAG9D","file":"clean.d.ts","sourcesContent":["/**\n *\tMIT License\n *\n *\tCopyright (c) 2019 - 2022 Toreda, Inc.\n *\n *\tPermission is hereby granted, free of charge, to any person obtaining a copy\n *\tof this software and associated documentation files (the \"Software\"), to deal\n *\tin the Software without restriction, including without limitation the rights\n *\tto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n *\tcopies of the Software, and to permit persons to whom the Software is\n *\tfurnished to do so, subject to the following conditions:\n\n * \tThe above copyright notice and this permission notice shall be included in all\n * \tcopies or substantial portions of the Software.\n *\n * \tTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n *\tIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n *\tFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * \tAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n *\tLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n *\tOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * \tSOFTWARE.\n *\n */\n\nimport {Config} from './config';\nimport {EventEmitter} from 'events';\nimport {Log} from '@toreda/log';\nimport {dirDelete} from './dir/delete';\n\n/**\n * Rrecursively clean files and dirs in output folder and intermediate\n * build folders.\n *\n * @category Clean\n */\nexport class Clean {\n\tpublic readonly events: EventEmitter;\n\tpublic readonly cfg: Config;\n\tpublic readonly log: Log;\n\n\tconstructor(cfg: Config, events: EventEmitter, log: Log) {\n\t\tthis.events = events;\n\t\tthis.cfg = cfg;\n\t\tthis.log = log.makeLog('Clean');\n\t}\n\n\t/**\n\t * Clean target directory, recursively removing all files\n\t * and directories.\n\t * @param path\n\t * @param force\n\t * @returns\n\t */\n\tpublic dir(path: string, force?: boolean): Promise<boolean> {\n\t\treturn new Promise(async (resolve, reject) => {\n\t\t\tif (typeof path !== 'string') {\n\t\t\t\treturn reject(new Error('cleanDir failure - path is not a valid string.'));\n\t\t\t}\n\n\t\t\tconst cleanPath = path.trim();\n\t\t\tif (cleanPath === '') {\n\t\t\t\treturn reject(new Error('cleanDir failure - path cannot be an empty string.'));\n\t\t\t}\n\n\t\t\tif (!force) {\n\t\t\t\tif (cleanPath === '.' || cleanPath === '/' || cleanPath === './' || cleanPath === '../') {\n\t\t\t\t\treturn reject(\n\t\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\t`cleanDir - '${cleanPath}' is a protected path. Set the 'force' argument true to override this safety.`\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tawait dirDelete(this.cfg, cleanPath);\n\t\t\t} catch (e) {\n\t\t\t\treturn reject(e);\n\t\t\t}\n\n\t\t\treturn resolve(true);\n\t\t});\n\t}\n\n\t/**\n\t * Alias for clean dir.\n\t * @param path\n\t * @param force\n\t * @returns\n\t */\n\tpublic folder(path: string, force?: boolean): Promise<boolean> {\n\t\treturn this.dir(path, force);\n\t}\n}\n"]}