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 _inquirer=_interopRequireDefault(require("inquirer"));
var _path=_interopRequireDefault(require("path"));
var _logger=require("../systemManager/logger");
var _exec=require("../systemManager/exec");
var _fileutils=require("../systemManager/fileutils");
var _common=require("../common");
var _resolve=require("../systemManager/resolve");

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

buildHooks(c));case 3:

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

Array.isArray(pipe)){_context.next=9;break;}_context.next=7;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 7:_context.next=13;break;case 9:if(!

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




var buildHooks=function buildHooks(c){var enableHookRebuild,shouldBuildHook,_await$inquirer$promp,confirm,h;return _regenerator.default.async(function buildHooks$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
(0,_logger.logDebug)('buildHooks');

enableHookRebuild=(0,_common.getConfigProp)(c,c.platform,'enableHookRebuild');

shouldBuildHook=c.program.reset||c.program.resetHard||c.program.resetAssets||
c.program.hooks||!(0,_fileutils.fsExistsSync)(c.paths.buildHooks.dist.dir)||enableHookRebuild===true||
c.runtime.forceBuildHookRebuild;if(


(0,_fileutils.fsExistsSync)(c.paths.buildHooks.index)){_context2.next=9;break;}_context2.next=6;return _regenerator.default.awrap(
_inquirer.default.prompt({
type:'confirm',
name:'confirm',
message:'Build hooks not configured in this project. Configure?'}));case 6:_await$inquirer$promp=_context2.sent;confirm=_await$inquirer$promp.confirm;

if(confirm){
(0,_fileutils.copyFolderContentsRecursiveSync)(
_path.default.join(c.paths.rnv.dir,'coreTemplateFiles/buildHooks/src'),
c.paths.buildHooks.dir);

}case 9:if(!(



!c.files.project.config.isNew&&(0,_resolve.doResolve)('@babel/cli'))){_context2.next=25;break;}if(!(
shouldBuildHook&&!c.isBuildHooksReady)){_context2.next=21;break;}_context2.prev=11;

(0,_logger.logHook)('buildHooks','Build hooks not complied. BUILDING...');_context2.next=15;return _regenerator.default.awrap(

(0,_exec.executeAsync)(
c,"babel "+
c.paths.buildHooks.dir+" -d "+c.paths.buildHooks.dist.dir,
{cwd:c.paths.project.dir,silent:true}));case 15:_context2.next=20;break;case 17:_context2.prev=17;_context2.t0=_context2["catch"](11);return _context2.abrupt("return",



Promise.reject("BUILD_HOOK Failed with error: "+_context2.t0));case 20:

c.isBuildHooksReady=true;case 21:


h=require(c.paths.buildHooks.dist.index);

c.buildHooks=h.hooks;
c.buildPipes=h.pipes;
h=require(c.paths.buildHooks.dist.index);case 25:return _context2.abrupt("return",


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