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 _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _fileutils=require("./systemTools/fileutils");
var _exec=require("./systemTools/exec");
var _prompt=require("./systemTools/prompt");var

Config=function(){
function Config(){(0,_classCallCheck2.default)(this,Config);
this.config={};
}(0,_createClass2.default)(Config,[{key:"initializeConfig",value:function initializeConfig(





c){
this.config=c;
return c;
}},{key:"getConfig",value:function getConfig()

{
return this.config;
}},{key:"injectProjectDependency",value:function injectProjectDependency(


















dependency,version,type){var skipInstall,currentPackage,existingPath,_args=arguments;return _regenerator.default.async(function injectProjectDependency$(_context){while(1){switch(_context.prev=_context.next){case 0:skipInstall=_args.length>3&&_args[3]!==undefined?_args[3]:false;
currentPackage=this.config.files.project.package;
existingPath=this.config.paths.project.package;
if(!currentPackage[type])currentPackage[type]={};
currentPackage[type][dependency]=version;
(0,_fileutils.writeObjectSync)(existingPath,currentPackage);if(
skipInstall){_context.next=9;break;}_context.next=9;return _regenerator.default.awrap((0,_exec.npmInstall)());case 9:return _context.abrupt("return",
true);case 10:case"end":return _context.stop();}}},null,this);}},{key:"getProjectConfig",value:function getProjectConfig()


{
return this.config.files.project;
}},{key:"checkRequiredPackage",value:function checkRequiredPackage(

pkg){var _projectConfig$packag;var version,type,skipAsking,skipInstall,projectConfig,confirm,resp,_args2=arguments;return _regenerator.default.async(function checkRequiredPackage$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:version=_args2.length>1&&_args2[1]!==undefined?_args2[1]:false;type=_args2.length>2?_args2[2]:undefined;skipAsking=_args2.length>3&&_args2[3]!==undefined?_args2[3]:false;skipInstall=_args2.length>4&&_args2[4]!==undefined?_args2[4]:false;if(
pkg){_context2.next=6;break;}return _context2.abrupt("return",false);case 6:
projectConfig=this.getProjectConfig();if((_projectConfig$packag=

projectConfig.package[type])==null?void 0:_projectConfig$packag[pkg]){_context2.next=16;break;}
confirm=skipAsking;if(
confirm){_context2.next=14;break;}_context2.next=12;return _regenerator.default.awrap(
(0,_prompt.inquirerPrompt)({
type:'confirm',
message:"You do not have "+pkg+" installed. Do you want to add it now?"}));case 12:resp=_context2.sent;

confirm=resp.confirm;case 14:if(!


confirm){_context2.next=16;break;}return _context2.abrupt("return",
this.injectProjectDependency(pkg,version||'latest',type,skipInstall));case 16:return _context2.abrupt("return",


false);case 17:case"end":return _context2.stop();}}},null,this);}},{key:"injectPlatformDependencies",value:function injectPlatformDependencies(


platform){var _this$config$files,_this$config$files$rn,_this$config$files$rn2,_this$config$files$rn3,_this$config$files$rn4,_this$config$files$rn5,_this=this;var npmDeps,promises,installed;return _regenerator.default.async(function injectPlatformDependencies$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:
npmDeps=(_this$config$files=this.config.files)==null?void 0:(_this$config$files$rn=_this$config$files.rnv)==null?void 0:(_this$config$files$rn2=_this$config$files$rn.platformTemplates)==null?void 0:(_this$config$files$rn3=_this$config$files$rn2.config)==null?void 0:(_this$config$files$rn4=_this$config$files$rn3.platforms)==null?void 0:(_this$config$files$rn5=_this$config$files$rn4[platform])==null?void 0:_this$config$files$rn5.npm;if(!

npmDeps){_context3.next=9;break;}
promises=Object.keys(npmDeps).reduce(function(acc,type){
Object.keys(npmDeps[type]).forEach(function(dep){
acc.push(_this.checkRequiredPackage(dep,npmDeps[type][dep],type,true,true));
});
return acc;
},[]);_context3.next=5;return _regenerator.default.awrap(

Promise.all(promises));case 5:installed=_context3.sent;if(!

installed.some(function(i){return i===true;})){_context3.next=9;break;}_context3.next=9;return _regenerator.default.awrap(
(0,_exec.npmInstall)());case 9:case"end":return _context3.stop();}}},null,this);}},{key:"command",get:function get(){return this.config.command;}},{key:"subCommand",get:function get(){return this.config.subCommand;}},{key:"rnvArguments",get:function get(){var _this$config$program=this.config.program,args=_this$config$program.args,rawArgs=_this$config$program.rawArgs;var cleanedArgs=args.filter(function(arg){return typeof arg==='string';});var missingArg=rawArgs[rawArgs.indexOf(cleanedArgs[1])+1];cleanedArgs.splice(2,0,missingArg);return cleanedArgs;}},{key:"platform",get:function get()






{
return this.config.platform;
}},{key:"currentPlatformDefaultPort",get:function get()

{var
platform=this.config.platform;
return this.config.platformDefaults[platform].defaultPort;
}}]);return Config;}();var _default=












































new Config();exports.default=_default;