var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.rnvClean=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _fs=_interopRequireDefault(require("fs"));
var _path=_interopRequireDefault(require("path"));
var _chalk=_interopRequireDefault(require("chalk"));
var _inquirer=_interopRequireDefault(require("inquirer"));

var _fileutils=require("./fileutils");
var _logger=require("./logger");
var _exec=require("./exec");

var rnvClean=function rnvClean(c){var skipQuestion,pathsToRemove,pkgLock,msg,packagesFolder,buildDirs,answers,_ref,confirm,_ref2,confirmBuilds,_ref3,confirmCache,_args=arguments;return _regenerator.default.async(function rnvClean$(_context){while(1){switch(_context.prev=_context.next){case 0:skipQuestion=_args.length>1&&_args[1]!==undefined?_args[1]:false;
(0,_logger.logTask)('rnvClean');
if(c.program.ci)skipQuestion=true;
pathsToRemove=[];
if(_fs.default.existsSync(c.paths.project.nodeModulesDir))pathsToRemove.push(c.paths.project.nodeModulesDir);
pkgLock=_path.default.join(c.paths.project.dir,'package-lock.json');
if(_fs.default.existsSync(pkgLock))pathsToRemove.push(pkgLock);
msg=_chalk.default.red(c.paths.project.nodeModulesDir+"\n"+pkgLock+"\n");
packagesFolder=_path.default.join(c.paths.project.dir,'packages');
if(_fs.default.existsSync(packagesFolder)){
_fs.default.readdirSync(packagesFolder).forEach(function(dir){
if(dir==='.DS_Store'){
var pth=_path.default.join(packagesFolder,dir);

if(_fs.default.existsSync(pth)){
pathsToRemove.push(pth);
msg+=_chalk.default.red(pth+"\n");
}
}else{
var pth2=_path.default.join(packagesFolder,dir,'node_modules');
if(_fs.default.existsSync(pth2)){
pathsToRemove.push(pth2);
msg+=_chalk.default.red(pth2+"\n");
}

var pth3=_path.default.join(packagesFolder,dir,'package-lock.json');
if(_fs.default.existsSync(pth3)){
pathsToRemove.push(pth3);
msg+=_chalk.default.red(pth3+"\n");
}
}
});
}

buildDirs=[];
if(_fs.default.existsSync(c.paths.project.builds.dir))buildDirs.push(c.paths.project.builds.dir);
if(_fs.default.existsSync(c.paths.project.assets.dir))buildDirs.push(c.paths.project.assets.dir);

answers={
modules:false,
builds:false,
cache:false,
nothingToClean:!skipQuestion};if(!(


pathsToRemove.length&&!skipQuestion)){_context.next=21;break;}_context.next=17;return _regenerator.default.awrap(
_inquirer.default.prompt({
name:'confirm',
type:'confirm',
message:"Do you want to remove node_module related files/folders? \n"+msg}));case 17:_ref=_context.sent;confirm=_ref.confirm;

answers.modules=confirm;
if(confirm)answers.nothingToClean=false;case 21:if(!(


buildDirs.length&&!skipQuestion)){_context.next=28;break;}_context.next=24;return _regenerator.default.awrap(
_inquirer.default.prompt({
name:'confirmBuilds',
type:'confirm',
message:"Do you want to clean your platformBuilds and platformAssets? \n"+_chalk.default.red(buildDirs.join('\n'))}));case 24:_ref2=_context.sent;confirmBuilds=_ref2.confirmBuilds;

answers.builds=confirmBuilds;
if(confirmBuilds)answers.nothingToClean=false;case 28:if(


skipQuestion){_context.next=35;break;}_context.next=31;return _regenerator.default.awrap(
_inquirer.default.prompt({
name:'confirmCache',
type:'confirm',
message:'Do you want to clean your npm/bundler cache?'}));case 31:_ref3=_context.sent;confirmCache=_ref3.confirmCache;

answers.cache=confirmCache;
if(confirmCache)answers.nothingToClean=false;case 35:if(!


answers.nothingToClean){_context.next=38;break;}
(0,_logger.logToSummary)('Nothing to clean');return _context.abrupt("return",
Promise.resolve());case 38:if(!


answers.modules){_context.next=41;break;}_context.next=41;return _regenerator.default.awrap(
(0,_fileutils.removeDirs)(pathsToRemove));case 41:if(!

answers.builds){_context.next=44;break;}_context.next=44;return _regenerator.default.awrap(
(0,_fileutils.removeDirs)(buildDirs));case 44:if(!

answers.cache){_context.next=49;break;}_context.next=47;return _regenerator.default.awrap(
(0,_exec.executeAsync)(c,'watchman watch-del-all'));case 47:_context.next=49;return _regenerator.default.awrap(
(0,_exec.executeAsync)(c,'rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/react-* && rm -rf $TMPDIR/haste-*'));case 49:case"end":return _context.stop();}}});};exports.rnvClean=rnvClean;