var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.taskRnvWorkspaceConfigure=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _path=_interopRequireDefault(require("path"));
var _constants=require("../../core/constants");
var _fileutils=require("../../core/systemManager/fileutils");






var _logger=require("../../core/systemManager/logger");function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly)symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}







var taskRnvWorkspaceConfigure=function taskRnvWorkspaceConfigure(c){var oldGlobalConfigPath,_c$files$workspace$co,defaultConfig,newConfig;return _regenerator.default.async(function taskRnvWorkspaceConfigure$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_logger.logTask)('taskRnvWorkspaceConfigure');


if((0,_fileutils.fsExistsSync)(c.paths.workspace.dir)){
(0,_logger.logDebug)(c.paths.workspace.dir+" folder exists!");
}else{
(0,_logger.logInfo)(
c.paths.workspace.dir+" folder missing! Creating one for you...");

(0,_fileutils.mkdirSync)(c.paths.workspace.dir);
}


if((0,_fileutils.fsExistsSync)(c.paths.workspace.config)){
(0,_logger.logDebug)(
c.paths.workspace.dir+"/"+_constants.RENATIVE_CONFIG_NAME+" file exists!");

}else{
oldGlobalConfigPath=_path.default.join(
c.paths.workspace.dir,
'config.json');

if((0,_fileutils.fsExistsSync)(oldGlobalConfigPath)){
(0,_logger.logWarning)(
'Found old version of your config. will copy it to new renative.json config');

(0,_fileutils.copyFileSync)(oldGlobalConfigPath,c.paths.workspace.config);
}else{
(0,_logger.logInfo)(

c.paths.workspace.dir+"/"+
_constants.RENATIVE_CONFIG_NAME+" file missing! Creating one for you...");

(0,_fileutils.copyFileSync)(
_path.default.join(
c.paths.rnv.dir,
'coreTemplateFiles',
'global-config-template.json'),

c.paths.workspace.config);

}
}

if((0,_fileutils.fsExistsSync)(c.paths.workspace.config)){
c.files.workspace.config=JSON.parse(
(0,_fileutils.fsReadFileSync)(c.paths.workspace.config).toString());


if((_c$files$workspace$co=c.files.workspace.config)==null?void 0:_c$files$workspace$co.appConfigsPath){
if(!(0,_fileutils.fsExistsSync)(c.files.workspace.config.appConfigsPath)){
(0,_logger.logWarning)("Your custom global appConfig is pointing to "+
(0,_logger.chalk)().white(
c.files.workspace.config.appConfigsPath)+" which doesn't exist! Make sure you create one in that location");


}else{
(0,_logger.logInfo)("Found custom appConfing location pointing to "+
(0,_logger.chalk)().white(
c.files.workspace.config.appConfigsPath)+". ReNativewill now swith to that location!");


c.paths.project.appConfigsDir=c.files.workspace.config.appConfigsPath;
}
}


if(c.files.workspace.config.defaultTargets===undefined){
(0,_logger.logWarning)("You're missing defaultTargets in your config "+
(0,_logger.chalk)().white(
c.paths.workspace.config)+". Let's add them!");


defaultConfig=JSON.parse(
(0,_fileutils.fsReadFileSync)(
_path.default.join(
c.paths.rnv.dir,
'coreTemplateFiles',
'global-config-template.json')).

toString());

newConfig=_objectSpread(_objectSpread({},
c.files.workspace.config),{},{
defaultTargets:defaultConfig.defaultTargets});

(0,_fileutils.fsWriteFileSync)(
c.paths.workspace.config,
JSON.stringify(newConfig,null,2));

}
}return _context.abrupt("return",

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


{
description:'',
fn:taskRnvWorkspaceConfigure,
task:'workspace configure',
params:_constants.PARAMS.withBase(),
platforms:[],
skipPlatforms:true,
isGlobalScope:true};exports.default=_default;
//# sourceMappingURL=task.rnv.workspace.configure.js.map