var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.cleanProjectModules=void 0;var _fs=_interopRequireDefault(require("fs"));
var _path=_interopRequireDefault(require("path"));
var _chalk=_interopRequireDefault(require("chalk"));
var _fileutils=require("./fileutils");
var _common=require("../common");
var _prompt=require("./prompt");

var cleanProjectModules=function cleanProjectModules(c){var skipQuestion=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return new Promise(function(resolve,reject){
(0,_common.logTask)('cleanProjectModules');
var pathsToRemove=[
c.paths.project.nodeModulesDir,
_path.default.join(c.paths.project.dir,'package-lock.json')];

var msg=_chalk.default.red('./node_modules\n./package-lock.json\n');
var 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'){
pathsToRemove.push(_path.default.join(packagesFolder,dir));
msg+=_chalk.default.red("./packages/"+dir+"\n");
}else{
pathsToRemove.push(_path.default.join(packagesFolder,dir,'node_modules'));
pathsToRemove.push(_path.default.join(packagesFolder,dir,'package-lock.json'));
msg+=_chalk.default.red("./packages/"+dir+"/node_modules\n./packages/"+dir+"/package-lock.json\n");
}
});
}


if(skipQuestion){
(0,_fileutils.removeDirs)(pathsToRemove).then(function(){return resolve();}).catch(function(e){return reject(e);});
}else{
(0,_prompt.askQuestion)("Following files/folders will be removed:\n\n"+msg+"\npress (ENTER) to confirm").
then(function(){
(0,_prompt.finishQuestion)();
(0,_fileutils.removeDirs)(pathsToRemove).then(function(){return resolve();}).
catch(function(e){return reject(e);});
}).
catch(function(e){return reject(e);});
}
});};exports.cleanProjectModules=cleanProjectModules;