var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.buildFirefoxProject=exports.runFirefoxProject=exports.configureKaiOSProject=exports.launchKaiOSSimulator=void 0;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _path=_interopRequireDefault(require("path"));
var _common=require("../core/common");






var _fileutils=require("../core/systemManager/fileutils");
var _logger=require("../core/systemManager/logger");
var _platformManager=require("../core/platformManager");
var _projectManager=require("../core/projectManager");



var _constants=require("../core/constants");

var _sdkWebpack=require("../sdk-webpack");

var childProcess=require('child_process');

var launchKaiOSSimulator=function launchKaiOSSimulator(c){return new Promise(function(resolve,reject){var _c$buildConfig,_c$buildConfig$sdks,_c$buildConfig2,_c$buildConfig2$sdks;
(0,_logger.logTask)('launchKaiOSSimulator');

if(!((_c$buildConfig=c.buildConfig)==null?void 0:(_c$buildConfig$sdks=_c$buildConfig.sdks)==null?void 0:_c$buildConfig$sdks.KAIOS_SDK)){
reject(
_constants.KAIOS_SDK+" is not configured in your "+
c.paths.workspace.config+" file. Make sure you add location to your Kaiosrt App path similar to: "+
(0,_logger.chalk)().white.bold(
'"KAIOS_SDK": "/Applications/Kaiosrt.app"'));


return;
}

var ePath=(0,_fileutils.getRealPath)(
_path.default.join((_c$buildConfig2=c.buildConfig)==null?void 0:(_c$buildConfig2$sdks=_c$buildConfig2.sdks)==null?void 0:_c$buildConfig2$sdks.KAIOS_SDK));


if(!(0,_fileutils.fsExistsSync)(ePath)){
reject("Can't find emulator at path: "+ePath);
return;
}

childProcess.exec("open "+ePath,function(err){
if(err){
reject(err);
return;
}
resolve();
});
});};exports.launchKaiOSSimulator=launchKaiOSSimulator;

var configureKaiOSProject=function configureKaiOSProject(c){var platform;return _regenerator.default.async(function configureKaiOSProject$(_context){while(1){switch(_context.prev=_context.next){case 0:
(0,_logger.logTask)('configureKaiOSProject');

platform=c.platform;

c.runtime.platformBuildsProjectPath=""+(0,_common.getPlatformProjectDir)(c);if(

(0,_platformManager.isPlatformActive)(c,platform)){_context.next=5;break;}return _context.abrupt("return");case 5:_context.next=7;return _regenerator.default.awrap(

(0,_projectManager.copyAssetsFolder)(c,platform));case 7:_context.next=9;return _regenerator.default.awrap(
(0,_sdkWebpack.configureCoreWebProject)(c));case 9:_context.next=11;return _regenerator.default.awrap(
configureProject(c));case 11:return _context.abrupt("return",
(0,_projectManager.copyBuildsFolder)(c,platform));case 12:case"end":return _context.stop();}}},null,null,null,Promise);};exports.configureKaiOSProject=configureKaiOSProject;


var configureProject=function configureProject(c){return new Promise(function(resolve){
(0,_logger.logTask)('configureProject');var
platform=c.platform;

if(!(0,_platformManager.isPlatformActive)(c,platform,resolve))return;

var appFolder=(0,_common.getPlatformProjectDir)(c);
var templateFolder=(0,_common.getTemplateProjectDir)(c,platform);

var manifestFilePath=_path.default.join(templateFolder,'manifest.webapp');
var manifestFilePath2=_path.default.join(appFolder,'manifest.webapp');
var manifestFile=JSON.parse((0,_fileutils.fsReadFileSync)(manifestFilePath));

manifestFile.name=""+(0,_common.getAppTitle)(c,platform);
manifestFile.description=""+(0,_common.getAppDescription)(c,platform);
manifestFile.developer=(0,_common.getAppAuthor)(c,platform);

(0,_fileutils.fsWriteFileSync)(
manifestFilePath2,
JSON.stringify(manifestFile,null,2));


resolve();
});};

var runFirefoxProject=function runFirefoxProject(c){var platform;return _regenerator.default.async(function runFirefoxProject$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:
(0,_logger.logTask)('runFirefoxProject');
platform=c.platform;_context2.next=4;return _regenerator.default.awrap(

(0,_sdkWebpack.buildWeb)(c));case 4:_context2.next=6;return _regenerator.default.awrap(
launchKaiOSSimulator(c,platform));case 6:return _context2.abrupt("return",
true);case 7:case"end":return _context2.stop();}}},null,null,null,Promise);};exports.runFirefoxProject=runFirefoxProject;


var buildFirefoxProject=function buildFirefoxProject(c){return _regenerator.default.async(function buildFirefoxProject$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:
(0,_logger.logTask)('buildFirefoxProject');_context3.next=3;return _regenerator.default.awrap(

(0,_sdkWebpack.buildWeb)(c));case 3:return _context3.abrupt("return",
true);case 4:case"end":return _context3.stop();}}},null,null,null,Promise);};exports.buildFirefoxProject=buildFirefoxProject;
//# sourceMappingURL=index.js.map