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,immediateNodeModuleDir,pkgLock,msg,packagesFolder,buildDirs,answers,_await$inquirer$promp,confirm,_await$inquirer$promp2,confirmBuilds,_await$inquirer$promp3,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=[];
immediateNodeModuleDir=_path.default.join(
c.paths.project.dir,
'node_modules');

pkgLock=_path.default.join(c.paths.project.dir,'package-lock.json');
if(_fs.default.existsSync(immediateNodeModuleDir)){pathsToRemove.push(immediateNodeModuleDir);}
if(_fs.default.existsSync(pkgLock))pathsToRemove.push(pkgLock);
msg=_chalk.default.red(pkgLock+"\n"+immediateNodeModuleDir);
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){_context.next=26;break;}if(
skipQuestion){_context.next=25;break;}_context.next=19;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 19:_await$inquirer$promp=_context.sent;confirm=_await$inquirer$promp.confirm;

answers.modules=confirm;
if(confirm)answers.nothingToClean=false;_context.next=26;break;case 25:

answers.modules=true;case 26:if(!



buildDirs.length){_context.next=37;break;}if(
skipQuestion){_context.next=36;break;}_context.next=30;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 30:_await$inquirer$promp2=_context.sent;confirmBuilds=_await$inquirer$promp2.confirmBuilds;


answers.builds=confirmBuilds;
if(confirmBuilds)answers.nothingToClean=false;_context.next=37;break;case 36:

answers.builds=true;case 37:if(



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

answers.cache=confirmCache;
if(confirmCache)answers.nothingToClean=false;_context.next=47;break;case 46:

answers.cache=true;case 47:if(!


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


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

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

answers.cache){_context.next=67;break;}_context.prev=57;_context.next=60;return _regenerator.default.awrap(

(0,_exec.executeAsync)(c,'watchman watch-del-all'));case 60:_context.next=65;break;case 62:_context.prev=62;_context.t0=_context["catch"](57);

(0,_logger.logDebug)("watchman not installed. skipping");case 65:_context.next=67;return _regenerator.default.awrap(


(0,_exec.executeAsync)(
c,
'rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/react-* && rm -rf $TMPDIR/haste-*'));case 67:case"end":return _context.stop();}}},null,null,[[57,62]],Promise);};exports.rnvClean=rnvClean;
//# sourceMappingURL=cleaner.js.map