var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.buildHooks=exports.executePipe=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _logger=require("../systemManager/logger");
var _exec=require("../systemManager/exec");
var _fileutils=require("../systemManager/fileutils");

var executePipe=function executePipe(c,key){var _c$buildConfig;var pipesConfig,pipe;return _regenerator.default.async(function executePipe$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_logger.logHook)('executePipe',"('"+key+"')");

pipesConfig=(_c$buildConfig=c.buildConfig)==null?void 0:_c$buildConfig.pipes;if(!(
!pipesConfig||pipesConfig&&pipesConfig.includes(key))){_context.next=5;break;}_context.next=5;return _regenerator.default.awrap(
buildHooks(c));case 5:


pipe=c.buildPipes?c.buildPipes[key]:null;if(!

Array.isArray(pipe)){_context.next=11;break;}_context.next=9;return _regenerator.default.awrap(
pipe.reduce(
function(accumulatorPromise,next){

(0,_logger.logHook)("buildHook."+(next==null?void 0:next.name),'(EXECUTING)');
return accumulatorPromise.then(function(){return next(c);});
},
Promise.resolve()));case 9:_context.next=15;break;case 11:if(!

pipe){_context.next=15;break;}
(0,_logger.logHook)("buildHook."+(pipe==null?void 0:pipe.name),'(EXECUTING)');_context.next=15;return _regenerator.default.awrap(
pipe(c));case 15:case"end":return _context.stop();}}},null,null,null,Promise);};exports.executePipe=executePipe;




var buildHooks=function buildHooks(c){var cmd,h;return _regenerator.default.async(function buildHooks$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
(0,_logger.logDebug)('buildHooks');if(!

(0,_fileutils.fsExistsSync)(c.paths.buildHooks.index)){_context2.next=19;break;}if(!
c.isBuildHooksReady){_context2.next=4;break;}return _context2.abrupt("return",
true);case 4:


cmd='babel --no-babelrc --plugins @babel/plugin-proposal-optional-chaining,@babel/plugin-proposal-nullish-coalescing-operator';_context2.prev=5;


(0,_logger.logHook)('buildHooks','Build hooks not complied. BUILDING...');_context2.next=9;return _regenerator.default.awrap(
(0,_exec.executeAsync)(
c,
cmd+" "+c.paths.buildHooks.dir+" -d "+c.paths.buildHooks.dist.dir+" --presets=@babel/env",
{cwd:c.paths.buildHooks.dir,silent:true}));case 9:


h=require(c.paths.buildHooks.dist.index);
c.buildHooks=h.hooks;
c.buildPipes=h.pipes;
c.isBuildHooksReady=true;return _context2.abrupt("return",
true);case 16:_context2.prev=16;_context2.t0=_context2["catch"](5);return _context2.abrupt("return",




Promise.reject("BUILD_HOOK Failed with error: "+_context2.t0));case 19:return _context2.abrupt("return",


true);case 20:case"end":return _context2.stop();}}},null,null,[[5,16]],Promise);};exports.buildHooks=buildHooks;
//# sourceMappingURL=buildHooks.js.map