var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.buildHooks=exports.executePipe=void 0;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _inquirer=_interopRequireDefault(require("inquirer"));
var _path=_interopRequireDefault(require("path"));
var _esbuild=require("esbuild");
var _logger=require("../systemManager/logger");
var _fileutils=require("../systemManager/fileutils");
var _common=require("../common");

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 _c$files$project$conf;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)&&c.program.ci||c.runtime.skipBuildHooks)){_context2.next=6;break;}
(0,_logger.logInfo)('No buld hooks found and in --ci mode. SKIPPING');return _context2.abrupt("return",
true);case 6:if(



(0,_fileutils.fsExistsSync)(c.paths.buildHooks.index)){_context2.next=20;break;}if(!
c.program.ci){_context2.next=10;break;}
c.runtime.skipBuildHooks=true;return _context2.abrupt("return");case 10:_context2.next=12;return _regenerator.default.awrap(


_inquirer.default.prompt({
type:'confirm',
name:'confirm',
message:'Build hooks not configured in this project. Configure?'}));case 12:_await$inquirer$promp=_context2.sent;confirm=_await$inquirer$promp.confirm;if(!

confirm){_context2.next=18;break;}
(0,_fileutils.copyFolderContentsRecursiveSync)(
_path.default.join(c.paths.rnv.dir,'coreTemplateFiles/buildHooks/src'),
c.paths.buildHooks.dir);_context2.next=20;break;case 18:


c.runtime.skipBuildHooks=true;return _context2.abrupt("return");case 20:if(!(




!c.runtime.isFirstRunAfterNew&&!((_c$files$project$conf=c.files.project.config)==null?void 0:_c$files$project$conf.isNew))){_context2.next=36;break;}if(!(
shouldBuildHook&&!c.isBuildHooksReady)){_context2.next=32;break;}_context2.prev=22;

(0,_logger.logHook)('buildHooks','Build hooks not complied. BUILDING...');_context2.next=26;return _regenerator.default.awrap(
(0,_esbuild.build)({
entryPoints:[c.paths.buildHooks.dir+"/index.js"],
bundle:true,
platform:'node',
external:[].concat((0,_toConsumableArray2.default)(Object.keys(c.files.project.package.dependencies||{})),(0,_toConsumableArray2.default)(
Object.keys(c.files.project.package.devDependencies||{}))),
outfile:c.paths.buildHooks.dist.dir+"/index.js"}));case 26:_context2.next=31;break;case 28:_context2.prev=28;_context2.t0=_context2["catch"](22);return _context2.abrupt("return",



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

c.isBuildHooksReady=true;case 32:


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

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


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