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

var _fileutils=require("../../core/systemManager/fileutils");
var _logger=require("../../core/systemManager/logger");
var _exec=require("../../core/systemManager/exec");
var _constants=require("../../core/constants");
var _utils=require("../../core/systemManager/utils");

function clearWindowsCacheFiles(){
var opts={
detached:false,
stdio:'ignore'};





var child_process_1=require('child_process');


child_process_1.spawn('cmd.exe',['/C','del /q/f/s %TEMP%\\*'],opts);


child_process_1.spawn('cmd.exe',['/C','dotnet nuget locals all --clear'],opts);


child_process_1.spawn('cmd.exe',['/C','npm cache clean --force & yarn cache clean --all'],opts);


child_process_1.spawn('cmd.exe',['/C','watchman watch-del-all'],opts);
}

var taskRnvClean=function taskRnvClean(c){var skipQuestionParam,skipQuestion,pathsToRemove,localFiles,immediateNodeModuleDir,pkgLock,yarnLock,packagesFolder,buildDirs,local1,local2,local3,answers,_await$inquirer$promp,confirm,_await$inquirer$promp2,confirmBuilds,_await$inquirer$promp3,confirmLocals,_await$inquirer$promp4,confirmCache,_args=arguments;return _regenerator.default.async(function taskRnvClean$(_context){while(1){switch(_context.prev=_context.next){case 0:skipQuestionParam=_args.length>1&&_args[1]!==undefined?_args[1]:false;
(0,_logger.logTask)('taskRnvClean');
skipQuestion=c.program.ci?true:skipQuestionParam;
pathsToRemove=[];
localFiles=[];
immediateNodeModuleDir=_path.default.join(
c.paths.project.dir,
'node_modules');



pkgLock=_path.default.join(c.paths.project.dir,'package-lock.json');


if((0,_fileutils.fsExistsSync)(immediateNodeModuleDir)){pathsToRemove.push(immediateNodeModuleDir);}
if((0,_fileutils.fsExistsSync)(pkgLock))pathsToRemove.push(pkgLock);

yarnLock=_path.default.join(c.paths.project.dir,'yarn.lock');
if((0,_fileutils.fsExistsSync)(yarnLock)){
pathsToRemove.push(yarnLock);
}

packagesFolder=_path.default.join(c.paths.project.dir,'packages');
if((0,_fileutils.fsExistsSync)(packagesFolder)){
(0,_fileutils.fsReaddirSync)(packagesFolder).forEach(function(dir){
if(dir==='.DS_Store'){
var pth=_path.default.join(packagesFolder,dir);

if((0,_fileutils.fsExistsSync)(pth)){
pathsToRemove.push(pth);
}
}else{
var pth2=_path.default.join(packagesFolder,dir,'node_modules');
if((0,_fileutils.fsExistsSync)(pth2)){
pathsToRemove.push(pth2);
}

var pth3=_path.default.join(packagesFolder,dir,'package-lock.json');
if((0,_fileutils.fsExistsSync)(pth3)){
pathsToRemove.push(pth3);
}

var pth4=_path.default.join(packagesFolder,dir,'yarn.lock');
if((0,_fileutils.fsExistsSync)(pth4)){
pathsToRemove.push(pth4);
}

var pth5=_path.default.join(packagesFolder,dir,'dist');
if((0,_fileutils.fsExistsSync)(pth5)){
pathsToRemove.push(pth5);
}
}
});
}

buildDirs=[];
if((0,_fileutils.fsExistsSync)(c.paths.project.builds.dir)){buildDirs.push(c.paths.project.builds.dir);}
if((0,_fileutils.fsExistsSync)(c.paths.project.assets.dir)){buildDirs.push(c.paths.project.assets.dir);}


local1=_path.default.join(c.paths.project.dir,'.DS_Store');
if((0,_fileutils.fsExistsSync)(local1))localFiles.push(local1);
local2=_path.default.join(c.paths.project.dir,'renative.local.json');
if((0,_fileutils.fsExistsSync)(local2))localFiles.push(local2);
local3=_path.default.join(c.paths.project.dir,'metro.config.local.js');
if((0,_fileutils.fsExistsSync)(local3))localFiles.push(local3);

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



pathsToRemove.length){_context.next=34;break;}if(
skipQuestion){_context.next=33;break;}_context.next=27;return _regenerator.default.awrap(
_inquirer.default.prompt({
name:'confirm',
type:'confirm',
message:"Do you want to remove node_module related files/folders? \n"+(0,_logger.chalk)().red(
pathsToRemove.join('\n'))}));case 27:_await$inquirer$promp=_context.sent;confirm=_await$inquirer$promp.confirm;


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

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



buildDirs.length){_context.next=45;break;}if(
skipQuestion){_context.next=44;break;}_context.next=38;return _regenerator.default.awrap(
_inquirer.default.prompt({
name:'confirmBuilds',
type:'confirm',
message:"Do you want to clean your platformBuilds and platformAssets? \n"+(0,_logger.chalk)().red(
buildDirs.join('\n'))}));case 38:_await$inquirer$promp2=_context.sent;confirmBuilds=_await$inquirer$promp2.confirmBuilds;


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

answers.builds=true;case 45:if(!



localFiles.length){_context.next=56;break;}if(
skipQuestion){_context.next=55;break;}_context.next=49;return _regenerator.default.awrap(
_inquirer.default.prompt({
name:'confirmLocals',
type:'confirm',
message:"Do you want to clean local files? \n"+(0,_logger.chalk)().red(
localFiles.join('\n'))}));case 49:_await$inquirer$promp3=_context.sent;confirmLocals=_await$inquirer$promp3.confirmLocals;


answers.locals=confirmLocals;
if(confirmLocals)answers.nothingToClean=false;_context.next=56;break;case 55:

answers.locals=true;case 56:if(



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

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

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


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


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

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

answers.locals){_context.next=78;break;}_context.next=78;return _regenerator.default.awrap(
(0,_fileutils.removeDirs)(localFiles));case 78:if(!

answers.cache){_context.next=93;break;}if(!
_utils.isSystemWin){_context.next=83;break;}
clearWindowsCacheFiles();_context.next=93;break;case 83:_context.prev=83;_context.next=86;return _regenerator.default.awrap(


(0,_exec.executeAsync)(c,'watchman watch-del-all'));case 86:_context.next=91;break;case 88:_context.prev=88;_context.t0=_context["catch"](83);

(0,_logger.logDebug)('watchman not installed. skipping');case 91:_context.next=93;return _regenerator.default.awrap(


(0,_exec.executeAsync)(
c,
'rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/react-* && rm -rf $TMPDIR/haste-*'));case 93:return _context.abrupt("return",



true);case 94:case"end":return _context.stop();}}},null,null,[[83,88]],Promise);};exports.taskRnvClean=taskRnvClean;var _default=


{
description:'Automatically removes all node_modules and lock in your project and its dependencies',
fn:taskRnvClean,
task:'clean',
params:_constants.PARAMS.withBase(),
platforms:[],
isGlobalScope:true};exports.default=_default;
//# sourceMappingURL=task.rnv.clean.js.map