var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.checkCrypto=exports.getEnvVar=exports.getEnvExportCmd=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _path=_interopRequireDefault(require("path"));
var _logger=require("./logger");





var _utils=require("./utils");
var _fileutils=require("./fileutils");




var _constants=require("../constants");
var _taskManager=require("../taskManager");

var getEnvExportCmd=function getEnvExportCmd(envVar,key){
if(_utils.isSystemWin){
return""+(0,_logger.chalk)().white("setx "+envVar+" \""+key+"\"");
}
return""+(0,_logger.chalk)().white("export "+envVar+"=\""+key+"\"");
};exports.getEnvExportCmd=getEnvExportCmd;

var getEnvVar=function getEnvVar(c){
var p1=c.paths.workspace.dir.
split('/').
pop().
replace('.','');
var p2=c.files.project.package.name.
replace('@','').
replace('/','_').
replace(/-/g,'_');
var envVar=("CRYPTO_"+p1+"_"+p2).toUpperCase();
(0,_logger.logDebug)('encrypt looking for env var:',envVar);
return envVar;
};exports.getEnvVar=getEnvVar;


var checkCrypto=function checkCrypto(c,parentTask,originTask){var _c$files$project$conf,_c$files$project$conf2,_c$files$project$conf3,_c$files$project$conf4,_c$files$project$conf5,_c$files$project$conf6,_c$files$project$conf7,_c$files$project$conf8;var sourceRaw,destRaw,source,tsProjectPath,wsPath,tsWorkspacePath,tsWorkspace,tsProject;return _regenerator.default.async(function checkCrypto$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_logger.logTask)('checkCrypto');if(!(

c.program.ci||((_c$files$project$conf=c.files.project.config)==null?void 0:(_c$files$project$conf2=_c$files$project$conf.crypto)==null?void 0:_c$files$project$conf2.optional))){_context.next=3;break;}return _context.abrupt("return");case 3:

sourceRaw=(_c$files$project$conf3=c.files.project.config)==null?void 0:(_c$files$project$conf4=_c$files$project$conf3.crypto)==null?void 0:(_c$files$project$conf5=_c$files$project$conf4.decrypt)==null?void 0:_c$files$project$conf5.source;
destRaw=(_c$files$project$conf6=c.files.project.config)==null?void 0:(_c$files$project$conf7=_c$files$project$conf6.crypto)==null?void 0:(_c$files$project$conf8=_c$files$project$conf7.encrypt)==null?void 0:_c$files$project$conf8.dest;if(!

destRaw){_context.next=25;break;}if(!(
sourceRaw&&destRaw)){_context.next=25;break;}
source=""+(0,_fileutils.getRealPath)(c,sourceRaw,'decrypt.source');
tsProjectPath=source+".timestamp";
wsPath=_path.default.join(
c.paths.workspace.dir,
c.files.project.package.name);

tsWorkspacePath=_path.default.join(wsPath,'timestamp');if(
(0,_fileutils.fsExistsSync)(source)){_context.next=15;break;}
(0,_logger.logWarning)(
"This project uses encrypted files but you don't have them installed");_context.next=25;break;case 15:


tsWorkspace=0;
tsProject=0;
if((0,_fileutils.fsExistsSync)(tsWorkspacePath)){
tsWorkspace=parseInt(
(0,_fileutils.fsReadFileSync)(tsWorkspacePath).toString(),
10);

}

if((0,_fileutils.fsExistsSync)(tsProjectPath)){
tsProject=parseInt(
(0,_fileutils.fsReadFileSync)(tsProjectPath).toString(),
10);

}if(!(

tsProject>tsWorkspace)){_context.next=24;break;}
(0,_logger.logWarning)("Your "+tsWorkspacePath+" is out of date.\nproject timestamp: "+
(0,_logger.chalk)().grey(tsProject+" - "+new Date(tsProject))+"\nworkspace timestamp: "+
(0,_logger.chalk)().grey(tsWorkspace+" - "+new Date(tsWorkspace))+"\nyou should run decrypt");_context.next=23;return _regenerator.default.awrap(

(0,_taskManager.executeTask)(c,_constants.TASK_CRYPTO_DECRYPT,parentTask,originTask));case 23:return _context.abrupt("return");case 24:



if(tsProject<tsWorkspace){
(0,_logger.logWarning)("Your "+
tsWorkspacePath+" is newer than your project one.");

}case 25:case"end":return _context.stop();}}},null,null,null,Promise);};exports.checkCrypto=checkCrypto;
//# sourceMappingURL=crypto.js.map