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










var _exec=require("../../systemTools/exec");
var _constants=require("../../constants");
var _configParser=require("../../configTools/configParser");

var updateProfile=function updateProfile(c,appConfigId){return new Promise(function(resolve,reject){var _getConfigProp;
(0,_common.logTask)("updateProfile:"+appConfigId,_chalk.default.grey);








if(appConfigId)(0,_configParser.setAppConfig)(c,appConfigId);

if(c.platform!==_constants.IOS&&c.platform!==_constants.TVOS){
reject("updateProfile:platform "+c.platform+" not supported");
return;
}var
scheme=c.program.scheme;var


platform=c.platform;var

appId=c.runtime.appId;

var id=(0,_common.getAppId)(c,platform);
var teamID=(0,_common.getConfigProp)(c,platform,'teamID');
var pMethod=(_getConfigProp=(0,_common.getConfigProp)(c,platform,'exportOptions'))==null?void 0:_getConfigProp.method;
var runScheme=(0,_common.getConfigProp)(c,platform,'runScheme');
var provisioning;
if(pMethod==='ad-hoc')provisioning='adhoc';
if(pMethod==='development'||runScheme==='Debug')provisioning='development';

var certsPath=_path.default.join(c.paths.workspace.appConfig.dir,'certs');

var args=[
'sigh',
'--app_identifier',
id,
'--team_id',
teamID,
'--output_path',
certsPath,
'--force'];

if(process.env.APPLE_DEVELOPER_USERNAME){
args=args.concat([
'--username',
process.env.APPLE_DEVELOPER_USERNAME]);

}
if(provisioning){
args.push("--"+provisioning);
}

(0,_exec.executeAsync)(c,"fastlane "+args.join(' '),{shell:true,stdio:'inherit',silent:true}).
then(function(){
(0,_common.logSuccess)("Succesfully updated provisioning profile for "+appId+":"+scheme+":"+id);

resolve();
}).
catch(function(e){
(0,_common.logWarning)(e);
resolve();
});
});};exports.updateProfile=updateProfile;