UNPKG

@rnv/sdk-tizen

Version:
679 lines 38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.runTizenSimOrDevice = exports.addDevelopTizenCertificate = exports.createDevelopTizenCertificate = exports.listTizenTargets = exports.launchTizenTarget = exports.DEFAULT_CERTIFICATE_NAME = void 0; var tslib_1 = require("tslib"); var net_1 = tslib_1.__importDefault(require("net")); var path_1 = tslib_1.__importDefault(require("path")); var core_1 = require("@rnv/core"); var constants_1 = require("./constants"); var sdk_utils_1 = require("@rnv/sdk-utils"); var xml2js = require('xml2js'); var parser = new xml2js.Parser(); exports.DEFAULT_CERTIFICATE_NAME = 'tizen_author'; var ERROR_MSG = { UNKNOWN_VM: 'does not match any VM', ALREADY_RUNNING: 'is running now', NO_SUPPORT: 'Your system cannot support HW virtualization', }; var formatXMLObject = function (obj) { var _a, _b; var platArr = (_a = obj['model-config']) === null || _a === void 0 ? void 0 : _a.platform; var platKeyArr = Array.isArray(platArr) ? (_b = platArr === null || platArr === void 0 ? void 0 : platArr[0]) === null || _b === void 0 ? void 0 : _b.key : platArr === null || platArr === void 0 ? void 0 : platArr.key; if (platKeyArr) { return tslib_1.__assign({}, platKeyArr.reduce(function (acc, cur) { acc[cur.$.name] = cur._; return acc; }, {})); } (0, core_1.logWarning)('Invalid object received from shell cat /etc/config/model-config.xml'); return {}; }; var launchTizenTarget = function (name, hideDevices, updateDefault) { if (updateDefault === void 0) { updateDefault = false; } return tslib_1.__awaiter(void 0, void 0, void 0, function () { var c, emulators, devices, devices_lines, devicesArr, allDownloadedEmulators, specificEmulators, specificDevices, lines, targetsArray, choices, chosenEmulator, ipRegex, e_1; var _a, _b, _c, _d, _e; return tslib_1.__generator(this, function (_f) { switch (_f.label) { case 0: c = (0, core_1.getContext)(); (0, core_1.logDefault)("launchTizenTarget:".concat(name)); if (!(name === true)) return [3 /*break*/, 8]; return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_TIZEN_EMULATOR, 'list-vm')]; case 1: emulators = _f.sent(); return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_SDB_TIZEN, 'devices')]; case 2: devices = _f.sent(); devices_lines = devices.split('\n'); devicesArr = devices_lines.slice(1).map(function (line) { return line.split(' ')[0]; }); allDownloadedEmulators = emulators.split('\n').map(function (em) { return em.trim(); }); return [4 /*yield*/, getEmulatorType(allDownloadedEmulators, c.platform)]; case 3: specificEmulators = _f.sent(); return [4 /*yield*/, getDeviceType(devicesArr, c.platform)]; case 4: specificDevices = _f.sent(); lines = specificEmulators.concat(specificDevices); targetsArray = hideDevices ? specificEmulators.map(function (line) { return ({ id: line, name: line }); }) : lines.map(function (line) { return ({ id: line, name: line }); }); choices = _composeDevicesString(targetsArray); if (!choices.length) { (0, core_1.logError)("No devices found for platform ".concat(c.platform)); return [2 /*return*/, Promise.reject('No devices found')]; } return [4 /*yield*/, (0, core_1.inquirerPrompt)({ name: 'chosenEmulator', type: 'list', message: hideDevices ? 'which emulator would you like to launch?' : 'which emulator or device would you like to launch?', choices: choices, default: ((_a = choices.find(function (it) { return it.key.includes('samsung'); })) === null || _a === void 0 ? void 0 : _a.key) || choices[0].key, })]; case 5: chosenEmulator = (_f.sent()).chosenEmulator; if (!(chosenEmulator && (((_c = (_b = c.files.project.configLocal) === null || _b === void 0 ? void 0 : _b.defaultTargets) === null || _c === void 0 ? void 0 : _c[c.platform]) || ((_e = (_d = c.files.workspace.config) === null || _d === void 0 ? void 0 : _d.defaultTargets) === null || _e === void 0 ? void 0 : _e[c.platform]) !== chosenEmulator))) return [3 /*break*/, 7]; // update defaultTarget in .rnv/renative.json return [4 /*yield*/, (0, sdk_utils_1.updateDefaultTargets)(c, chosenEmulator)]; case 6: // update defaultTarget in .rnv/renative.json _f.sent(); _f.label = 7; case 7: name = chosenEmulator; c.runtime.target = chosenEmulator; _f.label = 8; case 8: if (!(name && typeof name === 'string')) return [3 /*break*/, 16]; ipRegex = /^(?:\d{1,3}\.){3}\d{1,3}:\d{1,5}$/; if (!ipRegex.test(name)) return [3 /*break*/, 10]; // if ip is chosen, real device boot should start (0, core_1.logInfo)('Connecting to device'); c.runtime.target = name.split(':')[0]; return [4 /*yield*/, (0, exports.runTizenSimOrDevice)()]; case 9: _f.sent(); return [2 /*return*/, new Promise(function () { return (0, core_1.logInfo)('Device is launched.'); })]; case 10: _f.trys.push([10, 15, , 16]); if (!updateDefault) return [3 /*break*/, 12]; return [4 /*yield*/, (0, exports.runTizenSimOrDevice)()]; case 11: _f.sent(); return [2 /*return*/, true]; case 12: return [4 /*yield*/, (0, core_1.executeAsync)("".concat(c.cli[constants_1.CLI_TIZEN_EMULATOR], " launch --name ").concat(name), core_1.ExecOptionsPresets.SPINNER_FULL_ERROR_SUMMARY)]; case 13: _f.sent(); return [2 /*return*/, true]; case 14: return [3 /*break*/, 16]; case 15: e_1 = _f.sent(); if (typeof e_1 === 'string') { if (e_1.includes(ERROR_MSG.UNKNOWN_VM)) { (0, core_1.logError)("The VM/device \"".concat(name, "\" does not exist.")); return [2 /*return*/, (0, exports.launchTizenTarget)(true, hideDevices)]; } if (e_1.includes(ERROR_MSG.ALREADY_RUNNING)) { (0, core_1.logError)("The VM/device \"".concat(name, "\" is already running.")); return [2 /*return*/, true]; } if (e_1.includes(ERROR_MSG.NO_SUPPORT)) { (0, core_1.logError)("Your system cannot support HW virtualization."); return [2 /*return*/, true]; } } return [3 /*break*/, 16]; case 16: return [2 /*return*/, Promise.reject('No emulator -t target name specified!')]; } }); }); }; exports.launchTizenTarget = launchTizenTarget; var getEmulatorType = function (allTizenEmulators, neededPlatform) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var specificEmulators, i, detailString, detailLines, detailObj, TizenEmulatorTemplate, err_1; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: specificEmulators = []; i = 0; _a.label = 1; case 1: if (!(i < allTizenEmulators.length)) return [3 /*break*/, 6]; _a.label = 2; case 2: _a.trys.push([2, 4, , 5]); return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_TIZEN_EMULATOR, 'detail -n ' + allTizenEmulators[i])]; case 3: detailString = _a.sent(); if (detailString === undefined) return [3 /*break*/, 5]; detailLines = detailString // turn the command return into array .split('\n') .map(function (line) { return line.trim(); }) .filter(function (line) { return line !== ''; }); detailObj = detailLines.reduce(function (acc, line) { // make it into a readable object var _a = line.split(':'), key = _a[0], value = _a.slice(1); if (key && value) { acc[key.trim()] = value.join(':').trim(); } return acc; }, {}); TizenEmulatorTemplate = detailObj.Template.toLowerCase(); if ((neededPlatform === 'tizen' && (TizenEmulatorTemplate.includes('tizen') || TizenEmulatorTemplate.includes('tv'))) || (neededPlatform === 'tizenwatch' && TizenEmulatorTemplate.includes('wearable')) || (neededPlatform === 'tizenmobile' && TizenEmulatorTemplate.includes('mobile'))) { specificEmulators.push(allTizenEmulators[i]); } return [3 /*break*/, 5]; case 4: err_1 = _a.sent(); console.log(err_1); return [3 /*break*/, 5]; case 5: i++; return [3 /*break*/, 1]; case 6: return [2 /*return*/, specificEmulators]; } }); }); }; var getDeviceType = function (ipArr, neededPlatform) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var returnArr, i, capabilityString, err_2; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: returnArr = []; i = 0; _a.label = 1; case 1: if (!(i < ipArr.length)) return [3 /*break*/, 6]; _a.label = 2; case 2: _a.trys.push([2, 4, , 5]); return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_SDB_TIZEN, "-s ".concat(ipArr[i], " capability"))]; case 3: capabilityString = _a.sent(); if (capabilityString.includes('profile_name:tv') && (neededPlatform === 'tizen' || neededPlatform === 'tv')) { returnArr.push(ipArr[i]); } if (capabilityString.includes('profile_name:wearable') && neededPlatform === 'tizenwatch') { returnArr.push(ipArr[i]); } if (capabilityString.includes('profile_name:mobile') && neededPlatform === 'tizenmobile') { returnArr.push(ipArr[i]); } return [3 /*break*/, 5]; case 4: err_2 = _a.sent(); (0, core_1.logError)("Couldn't connect to ".concat(ipArr[i], " device.")); return [3 /*break*/, 5]; case 5: i++; return [3 /*break*/, 1]; case 6: return [2 /*return*/, returnArr]; } }); }); }; var listTizenTargets = function (platform) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var emulatorsString, devicesString, devicesArr, allDownloadedEmulators, specificEmulators, specificDevices, targetStr, finalTargetList; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_TIZEN_EMULATOR, 'list-vm')]; case 1: emulatorsString = _a.sent(); return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_SDB_TIZEN, 'devices')]; case 2: devicesString = _a.sent(); devicesArr = devicesString .split('\n') .slice(1) .map(function (line) { return line.split(' ')[0]; }); allDownloadedEmulators = emulatorsString.split('\n'); return [4 /*yield*/, getEmulatorType(allDownloadedEmulators, platform)]; case 3: specificEmulators = _a.sent(); return [4 /*yield*/, getDeviceType(devicesArr, platform)]; case 4: specificDevices = _a.sent(); targetStr = ''; finalTargetList = specificEmulators.concat(specificDevices); finalTargetList.forEach(function (_, i) { targetStr += "[".concat(i, "]> ").concat(finalTargetList[i], "\n"); }); if (!targetStr) { (0, core_1.logToSummary)("No targets for ".concat(platform, " found.")); } else { (0, core_1.logToSummary)("Tizen targets:\n".concat(targetStr)); } return [2 /*return*/]; } }); }); }; exports.listTizenTargets = listTizenTargets; var createDevelopTizenCertificate = function (c) { return new Promise(function (resolve) { (0, core_1.logDefault)('createDevelopTizenCertificate'); var certDirPath = c.paths.workspace.dir; var certFilename = exports.DEFAULT_CERTIFICATE_NAME; var certPassword = '1234'; (0, core_1.execCLI)(constants_1.CLI_TIZEN, "certificate -- ".concat(certDirPath, " -a rnv -f ").concat(certFilename, " -p ").concat(certPassword) // { privateParams: [certPassword] }, ) .then(function () { return (0, exports.addDevelopTizenCertificate)(c, { profileName: (0, core_1.getConfigProp)('certificateProfile') || core_1.DEFAULTS.certificateProfile, certPath: path_1.default.join(certDirPath, "".concat(certFilename, ".p12")), certPassword: certPassword, }); }) .then(function () { return resolve(); }) .catch(function (e) { (0, core_1.logError)(e); resolve(); }); }); }; exports.createDevelopTizenCertificate = createDevelopTizenCertificate; var addDevelopTizenCertificate = function (c, secureProfileConfig) { return new Promise(function (resolve) { (0, core_1.logDefault)('addDevelopTizenCertificate'); var _a = secureProfileConfig || {}, profileName = _a.profileName, certPath = _a.certPath, certPassword = _a.certPassword; (0, core_1.execCLI)(constants_1.CLI_TIZEN, "security-profiles add -n ".concat(profileName, " -a ").concat(certPath, " -p ").concat(certPassword), { privateParams: [certPassword], }) .then(function () { return resolve(); }) .catch(function (e) { (0, core_1.logError)(e); resolve(); }); }); }; exports.addDevelopTizenCertificate = addDevelopTizenCertificate; var _getDeviceID = function (target) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var c, device, connectResponse, e_2, devicesList, lines, devices, deviceID; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: c = (0, core_1.getContext)(); device = c.program.opts().device; if (!device) return [3 /*break*/, 5]; connectResponse = void 0; _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_SDB_TIZEN, "connect ".concat(target))]; case 2: connectResponse = _a.sent(); return [3 /*break*/, 4]; case 3: e_2 = _a.sent(); if (typeof e_2 === 'string') { connectResponse = e_2; } else if (e_2 instanceof Error) { connectResponse = e_2.message; } else { connectResponse = 'Unknown error'; } return [3 /*break*/, 4]; case 4: if (connectResponse.includes('EPERM')) { throw new Error("We can't connect to this device even though it is reachable. Please make sure you have enabled Developer Mode and you have added your IP in the Host PC IP section. For more information consult https://developer.samsung.com/tv/develop/getting-started/using-sdk/tv-device"); } if (connectResponse.includes('failed to connect to remote target')) { throw new Error("Failed to connect to ".concat(target, ". Make sure the IP is correct and you are connected on the same network.")); } if (connectResponse.includes('error')) throw new Error(connectResponse); _a.label = 5; case 5: return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_SDB_TIZEN, 'devices')]; case 6: devicesList = _a.sent(); if (devicesList.includes(target)) { lines = devicesList.trim().split(/\r?\n/); devices = lines.filter(function (line) { return line.includes(target); }); if (devices.length > 1) { // @todo handle more than one } deviceID = devices[0].split('device')[1].trim(); return [2 /*return*/, deviceID]; } return [2 /*return*/, Promise.reject("No device matching ".concat(target, " could be found."))]; } }); }); }; var _getRunningDevices = function (c) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var platform, devicesList, lines, devices; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: platform = c.program.opts().platform; return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_SDB_TIZEN, 'devices')]; case 1: devicesList = _a.sent(); lines = devicesList .trim() .split(/\r?\n/) .filter(function (line) { return !line.includes('List of devices'); }); devices = []; return [4 /*yield*/, Promise.all(lines.map(function (line) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var words, name_1, deviceInfoXML, deviceInfo, deviceType, parseObj; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: words = line.replace(/\t/g, '').split(' '); if (!(words.length >= 3)) return [3 /*break*/, 4]; name_1 = words[0].trim(); return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_SDB_TIZEN, "-s ".concat(name_1, " shell cat /etc/config/model-config.xml"), { ignoreErrors: true })]; case 1: deviceInfoXML = _a.sent(); deviceInfo = void 0; deviceType = 'tv'; if (!(deviceInfoXML !== '')) return [3 /*break*/, 3]; return [4 /*yield*/, parser.parseStringPromise(deviceInfoXML)]; case 2: parseObj = _a.sent(); deviceInfo = formatXMLObject(parseObj); deviceType = deviceInfo['tizen.org/feature/profile']; _a.label = 3; case 3: if ((platform === 'tizenmobile' && deviceType === 'mobile') || (platform === 'tizenwatch' && deviceType === 'wearable') || (platform === 'tizen' && (!deviceType || deviceType === 'tv'))) { devices.push({ name: name_1, type: words[1].trim(), id: words[2].trim(), deviceType: deviceType, }); } _a.label = 4; case 4: return [2 /*return*/]; } }); }); }))]; case 2: _a.sent(); return [2 /*return*/, devices]; } }); }); }; var _waitForEmulatorToBeReady = function (target) { return (0, core_1.waitForExecCLI)(constants_1.CLI_SDB_TIZEN, 'devices', function (res) { if (typeof res === 'string') { var lines = res.trim().split(/\r?\n/); var devices = lines.filter(function (line) { return line.includes(target) && line.includes('device'); }); return devices.length > 0; } return res; }); }; var _composeDevicesString = function (devices) { return devices.map(function (device) { return ({ key: device.id, name: device.name, value: device.id, }); }); }; // const startHostedServerIfRequired = (c) => { // if (Context.isWebHostEnabled) { // return rnvStart(c); // } // }; var runTizenSimOrDevice = function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var c, target, platform, isRunningEmulator, appName, bundleAssets, tDir, tBuild, intermediate, tOut, tId, certProfile, wgt, wgtClean, deviceID, askForEmulator, continueLaunching, isTargetSpecified, devices, targetDevice, currentTarget, e_3, choices, chosenEmulator; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: c = (0, core_1.getContext)(); target = c.runtime.target; platform = c.platform; isRunningEmulator = false; if (!platform) return [2 /*return*/]; appName = (0, core_1.getConfigProp)('appName'); if (!appName) { throw new Error("runTizen: ".concat((0, core_1.chalk)().grey(platform), ".appName not defined in your ").concat((0, core_1.chalk)().bold.white(c.paths.appConfig.config))); } bundleAssets = (0, core_1.getConfigProp)('bundleAssets') === true; tDir = (0, core_1.getPlatformProjectDir)(); tBuild = bundleAssets ? path_1.default.join(tDir, 'build') : tDir; intermediate = path_1.default.join(tDir, 'intermediate'); tOut = path_1.default.join(tDir, 'output'); tId = (0, core_1.getConfigProp)('id'); certProfile = (0, core_1.getConfigProp)('certificateProfile') || core_1.DEFAULTS.certificateProfile; wgt = "".concat(appName, ".wgt"); wgtClean = "".concat(appName.replace(/[^a-z0-9]/gi, '_'), ".wgt"); if (!tId) return [2 /*return*/, Promise.reject("Tizen platform requires \"id\" filed in platforms.tizen")]; askForEmulator = function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var startEmulator, defaultTarget, e_4, err_3; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: if (!target) { (0, exports.launchTizenTarget)(true, undefined, true); return [2 /*return*/]; } return [4 /*yield*/, (0, core_1.inquirerPrompt)({ name: 'startEmulator', type: 'confirm', message: "Could not find or connect to the specified target (".concat(target, "). Would you like to start an emulator?"), })]; case 1: startEmulator = (_a.sent()).startEmulator; if (!startEmulator) return [3 /*break*/, 12]; isRunningEmulator = true; defaultTarget = c.runtime.target; if (!defaultTarget) { (0, core_1.logError)('No default target found for tizen. please provide one using -t option'); return [2 /*return*/]; } _a.label = 2; case 2: _a.trys.push([2, 5, , 12]); return [4 /*yield*/, (0, exports.launchTizenTarget)(defaultTarget)]; case 3: _a.sent(); deviceID = defaultTarget; return [4 /*yield*/, _waitForEmulatorToBeReady(defaultTarget)]; case 4: _a.sent(); return [2 /*return*/, continueLaunching()]; case 5: e_4 = _a.sent(); (0, core_1.logDebug)("askForEmulator:ERRROR: ".concat(e_4)); _a.label = 6; case 6: _a.trys.push([6, 10, , 11]); return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_TIZEN_EMULATOR, "create -n ".concat(defaultTarget, " -p tv-samsung-5.0-x86"))]; case 7: _a.sent(); return [4 /*yield*/, (0, exports.launchTizenTarget)(defaultTarget)]; case 8: _a.sent(); deviceID = defaultTarget; return [4 /*yield*/, _waitForEmulatorToBeReady(defaultTarget)]; case 9: _a.sent(); return [2 /*return*/, continueLaunching()]; case 10: err_3 = _a.sent(); (0, core_1.logDebug)(err_3); (0, core_1.logError)("Could not find the specified target and could not create the emulator automatically.\nPlease create one and then edit the default target from ".concat(c.paths.workspace.dir, "/").concat(core_1.RnvFileName.renative)); return [3 /*break*/, 11]; case 11: return [3 /*break*/, 12]; case 12: return [2 /*return*/]; } }); }); }; continueLaunching = function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var hasDevice, packageID, e_5, err_4, toReturn, packageID; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: hasDevice = false; return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_TIZEN, "build-web -- \"".concat(tBuild, "\" -out \"").concat(intermediate, "\""))]; case 1: _a.sent(); return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_TIZEN, "package -- \"".concat(intermediate, "\" -s ").concat(certProfile, " -t wgt -o \"").concat(tOut, "\""))]; case 2: _a.sent(); _a.label = 3; case 3: _a.trys.push([3, 5, , 10]); packageID = platform === 'tizenwatch' || platform === 'tizenmobile' ? tId.split('.')[0] : tId; return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_TIZEN, "uninstall -p ".concat(packageID, " -t ").concat(deviceID), { ignoreErrors: true, })]; case 4: _a.sent(); hasDevice = true; return [3 /*break*/, 10]; case 5: e_5 = _a.sent(); if (!(typeof e_5 === 'string' && e_5.includes('No device matching'))) return [3 /*break*/, 9]; if (!c.runtime.target) return [3 /*break*/, 8]; isRunningEmulator = true; return [4 /*yield*/, (0, exports.launchTizenTarget)(c.runtime.target)]; case 6: _a.sent(); return [4 /*yield*/, _waitForEmulatorToBeReady(c.runtime.target)]; case 7: hasDevice = _a.sent(); return [3 /*break*/, 9]; case 8: return [2 /*return*/, Promise.reject('Not target specified. (-t)')]; case 9: return [3 /*break*/, 10]; case 10: try { if (wgtClean !== wgt) { (0, core_1.logInfo)("Your app name contains characters like spaces, changing output from \"".concat(wgt, "\" to \"").concat(wgtClean, "\"")); (0, core_1.fsRenameSync)(path_1.default.join(tOut, wgt), path_1.default.join(tOut, wgtClean)); } } catch (err) { (0, core_1.logError)(err); } _a.label = 11; case 11: _a.trys.push([11, 13, , 19]); return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_TIZEN, "install -- \"".concat(tOut, "\" -n ").concat(wgtClean, " -t ").concat(deviceID))]; case 12: _a.sent(); hasDevice = true; return [3 /*break*/, 19]; case 13: err_4 = _a.sent(); if (String(err_4).includes('Non trusted certificate is used')) { (0, core_1.logError)('Non trusted certificate is used. Register valid certificate.'); (0, core_1.logWarning)("You can update the Tizen certificate by using the rnv command: \"rnv tizen certificate\"."); } else { (0, core_1.logError)(err_4); } if (!c.runtime.target) { return [2 /*return*/, Promise.reject('Not target specified. (-t)')]; } if (!hasDevice) return [3 /*break*/, 15]; return [4 /*yield*/, (0, exports.launchTizenTarget)(true)]; case 14: _a.sent(); return [3 /*break*/, 18]; case 15: isRunningEmulator = true; return [4 /*yield*/, (0, exports.launchTizenTarget)(c.runtime.target)]; case 16: _a.sent(); return [4 /*yield*/, _waitForEmulatorToBeReady(c.runtime.target)]; case 17: hasDevice = _a.sent(); _a.label = 18; case 18: return [3 /*break*/, 19]; case 19: toReturn = true; if (!(platform !== 'tizenwatch' && platform !== 'tizenmobile' && hasDevice)) return [3 /*break*/, 21]; // change id for for emulator because tizen 8+ fails to run app with return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_TIZEN, "run -p ".concat(isRunningEmulator && !deviceID.includes('samsung') ? tId.split('.')[0] : tId, " -t ").concat(deviceID))]; case 20: // change id for for emulator because tizen 8+ fails to run app with _a.sent(); return [3 /*break*/, 23]; case 21: if (!((platform === 'tizenwatch' || platform === 'tizenmobile') && hasDevice)) return [3 /*break*/, 23]; packageID = tId.split('.'); return [4 /*yield*/, (0, core_1.execCLI)(constants_1.CLI_TIZEN, "run -p ".concat(packageID[0], " -t ").concat(deviceID))]; case 22: _a.sent(); _a.label = 23; case 23: return [2 /*return*/, toReturn]; } }); }); }; isTargetSpecified = !!target; return [4 /*yield*/, _getRunningDevices(c)]; case 1: devices = _a.sent(); if (!isTargetSpecified) return [3 /*break*/, 9]; if (!net_1.default.isIP(target)) return [3 /*break*/, 3]; return [4 /*yield*/, _getDeviceID(target)]; case 2: deviceID = _a.sent(); return [2 /*return*/, continueLaunching()]; case 3: if (devices.length > 0) { targetDevice = devices.find(function (device) { return device.id === target || device.name === target; }); if (targetDevice) { deviceID = targetDevice.id; return [2 /*return*/, continueLaunching()]; } } _a.label = 4; case 4: _a.trys.push([4, 7, , 8]); // try to launch it, see if it's a emulator that's not started yet isRunningEmulator = true; return [4 /*yield*/, (0, exports.launchTizenTarget)(target)]; case 5: _a.sent(); currentTarget = c.runtime.target || target; return [4 /*yield*/, _waitForEmulatorToBeReady(currentTarget)]; case 6: _a.sent(); deviceID = currentTarget; return [2 /*return*/, continueLaunching()]; case 7: e_3 = _a.sent(); return [2 /*return*/, askForEmulator()]; case 8: return [3 /*break*/, 12]; case 9: if (devices.length === 1) { deviceID = devices[0].id; return [2 /*return*/, continueLaunching()]; } if (!(devices.length > 1)) return [3 /*break*/, 11]; choices = _composeDevicesString(devices); return [4 /*yield*/, (0, core_1.inquirerPrompt)({ name: 'chosenEmulator', type: 'list', message: 'On what target would you like to run the app?', choices: choices, })]; case 10: chosenEmulator = (_a.sent()).chosenEmulator; deviceID = chosenEmulator; return [2 /*return*/, continueLaunching()]; case 11: return [2 /*return*/, askForEmulator()]; case 12: return [2 /*return*/]; } }); }); }; exports.runTizenSimOrDevice = runTizenSimOrDevice; //# sourceMappingURL=deviceManager.js.map