var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.buildFirefoxProject=exports.runFirefoxProject=exports.configureKaiOSProject=exports.launchKaiOSSimulator=void 0;var _path=_interopRequireDefault(require("path"));
var _fs=_interopRequireDefault(require("fs"));
var _chalk=_interopRequireDefault(require("chalk"));
var _exec=require("../../systemTools/exec");
var _common=require("../../common");





















var _projectParser=require("../../projectTools/projectParser");
var _constants=require("../../constants");











var _fileutils=require("../../systemTools/fileutils");
var _web=require("../web");

var launchKaiOSSimulator=function launchKaiOSSimulator(c,name){return new Promise(function(resolve,reject){
(0,_common.logTask)('launchKaiOSSimulator');

if(!c.files.private.config.sdks.KAIOS_SDK){
reject(
_constants.KAIOS_SDK+" is not configured in your "+c.paths.private.config+" file. Make sure you add location to your Kaiosrt App path similar to: "+_chalk.default.white.bold(
'"KAIOS_SDK": "/Applications/Kaiosrt.app"'));


return;
}

var ePath=_path.default.join(c.files.private.config.sdks.KAIOS_SDK);

if(!_fs.default.existsSync(ePath)){
reject("Can't find emulator at path: "+ePath);
return;
}

var childProcess=require('child_process');
childProcess.exec("open "+ePath,function(err,stdout,stderr){
if(err){
reject(err);
return;
}
resolve();
});
});};exports.launchKaiOSSimulator=launchKaiOSSimulator;

var configureKaiOSProject=function configureKaiOSProject(c,platform){return new Promise(function(resolve,reject){
(0,_common.logTask)('configureKaiOSProject');

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

(0,_projectParser.copyAssetsFolder)(c,platform).
then(function(){return(0,_projectParser.copyBuildsFolder)(c,platform);}).
then(function(){return configureProject(c,platform);}).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
});};exports.configureKaiOSProject=configureKaiOSProject;

var configureProject=function configureProject(c,platform){return new Promise(function(resolve,reject){
(0,_common.logTask)("configureProject:"+platform);

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

var appFolder=(0,_common.getAppFolder)(c,platform);
var templateFolder=(0,_common.getAppTemplateFolder)(c,platform);
var bundleIsDev=(0,_common.getConfigProp)(c,platform,'bundleIsDev')===true;
var bundleAssets=(0,_common.getConfigProp)(c,platform,'bundleAssets')===true;

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

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

_fs.default.writeFileSync(manifestFilePath2,JSON.stringify(manifestFile,null,2));

if(bundleAssets){
if(bundleIsDev){
(0,_fileutils.copyFileSync)(
_path.default.join(templateFolder,'_privateConfig','webpack.config.dev.js'),
_path.default.join(appFolder,'webpack.config.js'));

}else{
(0,_fileutils.copyFileSync)(
_path.default.join(templateFolder,'_privateConfig','webpack.config.js'),
_path.default.join(appFolder,'webpack.config.js'));

}
}else{
(0,_fileutils.copyFileSync)(
_path.default.join(templateFolder,'_privateConfig','webpack.config.dev.js'),
_path.default.join(appFolder,'webpack.config.js'));

}

resolve();
});};

var runFirefoxProject=function runFirefoxProject(c,platform){return new Promise(function(resolve,reject){
(0,_common.logTask)("runFirefoxProject:"+platform);

(0,_web.buildWeb)(c,platform).
then(function(){return launchKaiOSSimulator(c,platform);}).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
});};exports.runFirefoxProject=runFirefoxProject;

var buildFirefoxProject=function buildFirefoxProject(c,platform){return new Promise(function(resolve,reject){
(0,_common.logTask)("buildFirefoxProject:"+platform);

(0,_web.buildWeb)(c,platform).
then(function(){return resolve();}).
catch(function(e){return reject(e);});
});};exports.buildFirefoxProject=buildFirefoxProject;