nativescript
Version:
Command-line interface for building NativeScript projects
155 lines • 5.91 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.IOSProvisionService = void 0;
const mobileprovision = require("ios-mobileprovision-finder");
const helpers_1 = require("../common/helpers");
const _ = require("lodash");
const yok_1 = require("../common/yok");
const months = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
function formatDate(date) {
return `${date.getDay()} ${months[date.getMonth()]} ${date.getFullYear()}`;
}
class IOSProvisionService {
constructor($logger, $options, $devicesService, $mobileHelper) {
this.$logger = $logger;
this.$options = $options;
this.$devicesService = $devicesService;
this.$mobileHelper = $mobileHelper;
}
async pick(uuidOrName, projectId) {
const match = (await this.queryProvisioningProfilesAndDevices(projectId))
.match;
return (match.eligible.find((prov) => prov.UUID === uuidOrName) ||
match.eligible.find((prov) => prov.Name === uuidOrName) ||
match.nonEligible.find((prov) => prov.UUID === uuidOrName) ||
match.nonEligible.find((prov) => prov.Name === uuidOrName));
}
async listProvisions(projectId) {
const data = await this.queryProvisioningProfilesAndDevices(projectId);
const devices = data.devices;
const match = data.match;
function formatSupportedDeviceCount(prov) {
if (devices.length > 0 && prov.Type === "Development") {
return (prov.ProvisionedDevices.filter((device) => devices.indexOf(device) >= 0).length +
"/" +
devices.length +
" targets");
}
else {
return "";
}
}
function formatTotalDeviceCount(prov) {
if (prov.Type === "Development" && prov.ProvisionedDevices) {
return prov.ProvisionedDevices.length + " total";
}
else if (prov.Type === "AdHoc") {
return "all";
}
else {
return "";
}
}
const table = (0, helpers_1.createTable)([
"Provision Name / Provision UUID / App Id",
"Team",
"Type / Due",
"Devices",
], []);
function pushProvision(prov) {
table.push(["", "", "", ""]);
table.push([
(0, helpers_1.quoteString)(prov.Name),
prov.TeamName,
prov.Type,
formatTotalDeviceCount(prov),
]);
table.push([
prov.UUID,
prov.TeamIdentifier && prov.TeamIdentifier.length > 0
? "(" + prov.TeamIdentifier[0] + ")"
: "",
formatDate(prov.ExpirationDate),
formatSupportedDeviceCount(prov),
]);
table.push([prov.Entitlements["application-identifier"], "", "", ""]);
}
match.eligible.forEach((prov) => pushProvision(prov));
this.$logger.info(table.toString());
this.$logger.info();
this.$logger.info("There are also " +
match.nonEligible.length +
" non-eligible provisioning profiles.");
this.$logger.info();
}
async listTeams() {
const teams = await this.getDevelopmentTeams();
const table = (0, helpers_1.createTable)(["Team Name", "Team ID"], teams.map((team) => [(0, helpers_1.quoteString)(team.name), team.id]));
this.$logger.info(table.toString());
}
async queryProvisioningProfilesAndDevices(projectId) {
const certificates = mobileprovision.cert.read();
const provisions = mobileprovision.provision.read();
const query = {
Certificates: certificates.valid,
Unique: true,
AppId: projectId,
};
let devices = [];
if (this.$options.device) {
devices = [this.$options.device];
}
else {
await this.$devicesService.initialize({
platform: "ios",
skipEmulatorStart: true,
});
devices = _(this.$devicesService.getDeviceInstances())
.filter((d) => this.$mobileHelper.isiOSPlatform(d.deviceInfo.platform))
.map((d) => d.deviceInfo.identifier)
.toJSON();
}
const match = mobileprovision.provision.select(provisions, query);
return { devices, match };
}
async getDevelopmentTeams() {
const teams = {};
// NOTE: We are reading all provisioning profiles and collect team information from them.
// It would be better if we can check the Apple ID registered in Xcode and read the teams associated with it.
mobileprovision.provision.read().forEach((provision) => provision.TeamIdentifier &&
provision.TeamIdentifier.forEach((id) => {
if (!teams[provision.TeamName]) {
teams[provision.TeamName] = new Set();
}
teams[provision.TeamName].add(id);
}));
const teamsArray = Object.keys(teams).reduce((arr, name) => {
teams[name].forEach((id) => arr.push({ id, name }));
return arr;
}, []);
return teamsArray;
}
async getTeamIdsWithName(teamName) {
const allTeams = await this.getDevelopmentTeams();
const matchingTeamIds = allTeams
.filter((team) => team.name === teamName)
.map((team) => team.id);
return matchingTeamIds;
}
}
exports.IOSProvisionService = IOSProvisionService;
yok_1.injector.register("iOSProvisionService", IOSProvisionService);
//# sourceMappingURL=ios-provision-service.js.map
;