nativescript
Version:
Command-line interface for building NativeScript projects
92 lines • 3.38 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MobileHelper = void 0;
const helpers = require("../helpers");
const shell = require("shelljs");
const _ = require("lodash");
const yok_1 = require("../yok");
class MobileHelper {
constructor($errors, $fs, $devicePlatformsConstants, $tempService) {
this.$errors = $errors;
this.$fs = $fs;
this.$devicePlatformsConstants = $devicePlatformsConstants;
this.$tempService = $tempService;
}
get platformNames() {
return [
this.$devicePlatformsConstants.iOS,
this.$devicePlatformsConstants.Android,
this.$devicePlatformsConstants.visionOS,
];
}
isAndroidPlatform(platform) {
return !!(platform &&
this.$devicePlatformsConstants.Android.toLowerCase() ===
platform.toLowerCase());
}
isiOSPlatform(platform) {
return !!(platform &&
this.$devicePlatformsConstants.iOS.toLowerCase() ===
platform.toLowerCase());
}
isvisionOSPlatform(platform) {
return !!(platform &&
this.$devicePlatformsConstants.visionOS.toLowerCase() ===
platform.toLowerCase());
}
isApplePlatform(platform) {
return this.isiOSPlatform(platform) || this.isvisionOSPlatform(platform);
}
normalizePlatformName(platform) {
if (this.isAndroidPlatform(platform)) {
return "Android";
}
else if (this.isiOSPlatform(platform)) {
return "iOS";
}
else if (this.isvisionOSPlatform(platform)) {
return "visionOS";
}
return undefined;
}
validatePlatformName(platform) {
if (!platform) {
this.$errors.failWithHelp("No device platform specified.");
}
const normalizedPlatform = this.normalizePlatformName(platform);
if (!normalizedPlatform ||
!_.includes(this.platformNames, normalizedPlatform)) {
this.$errors.fail("'%s' is not a valid device platform. Valid platforms are %s.", platform, helpers.formatListOfNames(this.platformNames));
}
return normalizedPlatform;
}
buildDevicePath(...args) {
return this.correctDevicePath(args.join(MobileHelper.DEVICE_PATH_SEPARATOR));
}
correctDevicePath(filePath) {
return helpers.stringReplaceAll(filePath, "\\", "/");
}
isiOSTablet(deviceName) {
return deviceName && deviceName.toLowerCase().indexOf("ipad") !== -1;
}
async getDeviceFileContent(device, deviceFilePath, projectData) {
const uniqueFilePath = await this.$tempService.path({ suffix: ".tmp" });
const platform = device.deviceInfo.platform.toLowerCase();
try {
await device.fileSystem.getFile(deviceFilePath, projectData.projectIdentifiers[platform], uniqueFilePath);
}
catch (e) {
return null;
}
if (this.$fs.exists(uniqueFilePath)) {
const text = this.$fs.readText(uniqueFilePath);
shell.rm(uniqueFilePath);
return text;
}
return null;
}
}
exports.MobileHelper = MobileHelper;
MobileHelper.DEVICE_PATH_SEPARATOR = "/";
yok_1.injector.register("mobileHelper", MobileHelper);
//# sourceMappingURL=mobile-helper.js.map