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

var _config=_interopRequireDefault(require("../configManager/config"));
var _exec=require("../systemManager/exec");
var _fileutils=require("../systemManager/fileutils");







var _logger=require("../systemManager/logger");

var bumpVersions=function bumpVersions(version){
var _Config$getConfig$pat=


_config.default.getConfig().paths,dir=_Config$getConfig$pat.project.dir,pluginTemplates=_Config$getConfig$pat.rnv.pluginTemplates;

var packagesDir=_path.default.join(dir,'packages');
if((0,_fileutils.fsExistsSync)(packagesDir)){
var packages=(0,_fileutils.fsReaddirSync)(packagesDir);
packages.forEach(function(name){
var pkgPath=_path.default.join(packagesDir,name);
var pkgJsonPath=_path.default.join(pkgPath,'package.json');
if(
(0,_fileutils.fsLstatSync)(pkgPath).isDirectory()&&
(0,_fileutils.fsExistsSync)(pkgJsonPath))
{

var existingPkgJson=require(pkgJsonPath);
existingPkgJson.version=version;
(0,_fileutils.writeFileSync)(pkgJsonPath,existingPkgJson);
}
});

var renativePkgPath=_path.default.join(packagesDir,'renative');
if((0,_fileutils.fsExistsSync)(renativePkgPath)){
(0,_fileutils.copyFileSync)(
_path.default.join(dir,'README.md'),
_path.default.join(renativePkgPath,'README.md'));

(0,_fileutils.updateObjectSync)(pluginTemplates.config,{
pluginTemplates:{
renative:{
version:version}}});



}
}
};

var publishAll=function publishAll(){
var
dir=
_config.default.getConfig().paths.project.dir;
var packagesDir=_path.default.join(dir,'packages');
if((0,_fileutils.fsExistsSync)(packagesDir)){
var packages=(0,_fileutils.fsReaddirSync)(packagesDir);
return Promise.all(
packages.map(function(name){
var pkgPath=_path.default.join(packagesDir,name);
return(0,_exec.executeAsync)('npm i',{cwd:pkgPath});
}));

}
return true;
};

var taskRnvPkg=function taskRnvPkg(){var args,firstArg,secondArg;return _regenerator.default.async(function taskRnvPkg$(_context){while(1){switch(_context.prev=_context.next){case 0:
args=(0,_toConsumableArray2.default)(_config.default.getConfig().program.rawArgs);
args=args.slice(3);

firstArg=args[0];
secondArg=args[1];_context.t0=

firstArg;_context.next=_context.t0===
'version'?7:_context.t0===










'publish'?12:13;break;case 7:if(secondArg){_context.next=9;break;}return _context.abrupt("return",(0,_logger.logError)('No version specified',false,true));case 9:if(_semver.default.valid(secondArg)){_context.next=11;break;}return _context.abrupt("return",(0,_logger.logError)("Invalid version specified "+secondArg,false,true));case 11:return _context.abrupt("return",bumpVersions(secondArg));case 12:return _context.abrupt("return",
publishAll());case 13:

(0,_logger.logError)("Unknown argument "+firstArg,false,true);return _context.abrupt("break",15);case 15:case"end":return _context.stop();}}},null,null,null,Promise);};var _default=




taskRnvPkg;exports.default=_default;
//# sourceMappingURL=package.js.map