UNPKG

nativescript

Version:

Command-line interface for building NativeScript projects

68 lines 3.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IOSEntitlementsService = void 0; const path = require("path"); const plist_merge_patch_1 = require("plist-merge-patch"); const yok_1 = require("../common/yok"); class IOSEntitlementsService { constructor($options, $fs, $logger, $devicePlatformsConstants, $mobileHelper, $pluginsService) { this.$options = $options; this.$fs = $fs; this.$logger = $logger; this.$devicePlatformsConstants = $devicePlatformsConstants; this.$mobileHelper = $mobileHelper; this.$pluginsService = $pluginsService; } getDefaultAppEntitlementsPath(projectData) { var _a; const entitlementsName = IOSEntitlementsService.DefaultEntitlementsName; const entitlementsPath = path.join(projectData.appResourcesDirectoryPath, this.$mobileHelper.normalizePlatformName((_a = this.$options.platformOverride) !== null && _a !== void 0 ? _a : this.$devicePlatformsConstants.iOS), entitlementsName); return entitlementsPath; } getPlatformsEntitlementsPath(projectData) { var _a; return path.join(projectData.platformsDir, (_a = this.$options.platformOverride) !== null && _a !== void 0 ? _a : this.$devicePlatformsConstants.iOS.toLowerCase(), projectData.projectName, projectData.projectName + ".entitlements"); } getPlatformsEntitlementsRelativePath(projectData) { return path.join(projectData.projectName, projectData.projectName + ".entitlements"); } async merge(projectData) { const session = new plist_merge_patch_1.PlistSession({ log: (txt) => this.$logger.trace("App.entitlements: " + txt), }); const projectDir = projectData.projectDir; const makePatch = (plistPath) => { if (!this.$fs.exists(plistPath)) { this.$logger.trace("No plist found at: " + plistPath); return; } this.$logger.trace("Schedule merge plist at: " + plistPath); session.patch({ name: path.relative(projectDir, plistPath), read: () => this.$fs.readText(plistPath), }); }; const allPlugins = await this.getAllInstalledPlugins(projectData); for (const plugin of allPlugins) { const pluginInfoPlistPath = path.join(plugin.pluginPlatformsFolderPath(this.$devicePlatformsConstants.iOS), IOSEntitlementsService.DefaultEntitlementsName); makePatch(pluginInfoPlistPath); } const appEntitlementsPath = this.getDefaultAppEntitlementsPath(projectData); if (this.$fs.exists(appEntitlementsPath)) { makePatch(appEntitlementsPath); } if (session.patches && session.patches.length > 0) { const plistContent = session.build(); this.$logger.trace("App.entitlements: Write to: " + this.getPlatformsEntitlementsPath(projectData)); this.$fs.writeFile(this.getPlatformsEntitlementsPath(projectData), plistContent); } } getAllInstalledPlugins(projectData) { return this.$pluginsService.getAllInstalledPlugins(projectData); } } exports.IOSEntitlementsService = IOSEntitlementsService; IOSEntitlementsService.DefaultEntitlementsName = "app.entitlements"; yok_1.injector.register("iOSEntitlementsService", IOSEntitlementsService); //# sourceMappingURL=ios-entitlements-service.js.map