var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.taskRnvProjectUpgrade=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _path=_interopRequireDefault(require("path"));
var _fs=_interopRequireDefault(require("fs"));
var _constants=require("../../core/constants");
var _logger=require("../../core/systemManager/logger");
var _projectManager=require("../../core/projectManager");
var _taskManager=require("../../core/taskManager");
var _npmUtils=require("../../core/systemManager/npmUtils");
var _pluginManager=require("../../core/pluginManager");
var _fileutils=require("../../core/systemManager/fileutils");

var taskRnvProjectUpgrade=function taskRnvProjectUpgrade(c,parentTask,originTask){var upgradedPaths,selectedVersion,packagesPath,_selectedVersion,dirs;return _regenerator.default.async(function taskRnvProjectUpgrade$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_logger.logTask)('taskRnvProjectUpgrade');
upgradedPaths=[];if(!
(0,_fileutils.fsExistsSync)(c.paths.project.config)){_context.next=13;break;}_context.next=5;return _regenerator.default.awrap(
(0,_taskManager.executeTask)(c,_constants.TASK_PROJECT_CONFIGURE,_constants.TASK_PROJECT_UPGRADE,originTask));case 5:_context.next=7;return _regenerator.default.awrap(
(0,_npmUtils.listAndSelectNpmVersion)(c,'rnv'));case 7:selectedVersion=_context.sent;

upgradedPaths.push.apply(upgradedPaths,(0,_toConsumableArray2.default)((0,_projectManager.upgradeProjectDependencies)(c,selectedVersion)));_context.next=11;return _regenerator.default.awrap(

(0,_pluginManager.installPackageDependenciesAndPlugins)(c));case 11:_context.next=22;break;case 13:

(0,_logger.logInfo)('Your are running rnv upgrade outside of renative project');
packagesPath=_path.default.join(c.paths.project.dir,'packages');if(!(
(0,_fileutils.fsExistsSync)(c.paths.project.package)&&(0,_fileutils.fsExistsSync)(packagesPath))){_context.next=22;break;}_context.next=18;return _regenerator.default.awrap(
(0,_npmUtils.listAndSelectNpmVersion)(c,'rnv'));case 18:_selectedVersion=_context.sent;

upgradedPaths.push.apply(upgradedPaths,(0,_toConsumableArray2.default)((0,_projectManager.upgradeDependencies)(
c.files.project.package,
c.paths.project.package,
null,null,
_selectedVersion)));


dirs=_fs.default.readdirSync(packagesPath);

dirs.forEach(function(dir){
var dirPath=_path.default.join(packagesPath,dir);
if(_fs.default.statSync(dirPath).isDirectory()){
var pkgPath=_path.default.join(dirPath,'package.json');
var rnvPath=_path.default.join(dirPath,'renative.json');
var pkgFile;
var rnvFile;
if((0,_fileutils.fsExistsSync)(pkgPath)){
pkgFile=(0,_fileutils.readObjectSync)(pkgPath);
}

if((0,_fileutils.fsExistsSync)(rnvPath)){
rnvFile=(0,_fileutils.readObjectSync)(rnvPath);
}
upgradedPaths.push.apply(upgradedPaths,(0,_toConsumableArray2.default)((0,_projectManager.upgradeDependencies)(
pkgFile,
pkgPath,
rnvFile,
rnvPath,
_selectedVersion)));

}
});case 22:



(0,_logger.logToSummary)("Upgraded following files:\n"+upgradedPaths.join('\n'),true);return _context.abrupt("return",


true);case 24:case"end":return _context.stop();}}},null,null,null,Promise);};exports.taskRnvProjectUpgrade=taskRnvProjectUpgrade;var _default=


{
description:'Upgrade or downgrade RNV dependencies in your ReNative project',
fn:taskRnvProjectUpgrade,
task:_constants.TASK_PROJECT_UPGRADE,
params:_constants.PARAMS.withBase(),
platforms:[],
skipAppConfig:true,
skipPlatforms:true,
isGlobalScope:true};exports.default=_default;
//# sourceMappingURL=task.rnv.project.upgrade.js.map