eas-cli
Version:
EAS command line tool
182 lines (181 loc) • 8.34 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkEASUpdateURLIsSetAsync = exports.getBranchDescription = exports.getUpdateGroupDescriptionsWithBranch = exports.getUpdateGroupDescriptions = exports.getUpdateJsonInfosForUpdates = exports.formatUpdateTitle = exports.ensureValidVersions = exports.formatUpdateMessage = exports.truncateString = exports.formatPlatformForUpdateGroup = exports.getPlatformsForGroup = exports.formatBranch = exports.formatUpdateGroup = exports.UPDATE_COLUMNS_WITH_BRANCH = exports.UPDATE_COLUMNS = void 0;
const tslib_1 = require("tslib");
const timeago_js_1 = require("@expo/timeago.js");
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const dateformat_1 = tslib_1.__importDefault(require("dateformat"));
const api_1 = require("../api");
const log_1 = require("../log");
const platform_1 = require("../platform");
const User_1 = require("../user/User");
const groupBy_1 = tslib_1.__importDefault(require("../utils/expodash/groupBy"));
const formatFields_1 = tslib_1.__importDefault(require("../utils/formatFields"));
exports.UPDATE_COLUMNS = [
'Update message',
'Update runtime version',
'Update group ID',
'Update platforms',
];
exports.UPDATE_COLUMNS_WITH_BRANCH = ['Branch', ...exports.UPDATE_COLUMNS];
function formatUpdateGroup(update) {
return (0, formatFields_1.default)([
{ label: 'Platforms', value: update.platforms },
{ label: 'Runtime Version', value: update.runtimeVersion },
{ label: 'Message', value: update.message },
{ label: 'Code Signing Key', value: update.codeSigningKey ?? 'N/A' },
{ label: 'Is Roll Back to Embedded', value: update.isRollBackToEmbedded ? 'Yes' : 'No' },
{
label: 'Rollout Percentage',
value: update.rolloutPercentage !== undefined ? `${update.rolloutPercentage}%` : 'N/A',
},
{ label: 'Group ID', value: update.group },
]);
}
exports.formatUpdateGroup = formatUpdateGroup;
function formatBranch({ branch, branchRolloutPercentage, update, }) {
const rolloutField = branchRolloutPercentage
? [{ label: 'Rollout', value: `${branchRolloutPercentage}%` }]
: [];
return (0, formatFields_1.default)([
{ label: 'Branch', value: branch },
...rolloutField,
{ label: 'Platforms', value: update?.platforms ?? 'N/A' },
{ label: 'Runtime Version', value: update?.runtimeVersion ?? 'N/A' },
{ label: 'Message', value: update?.message ?? 'N/A' },
{ label: 'Group ID', value: update?.group ?? 'N/A' },
]);
}
exports.formatBranch = formatBranch;
function getPlatformsForGroup({ group, updates = [], }) {
const groupedUpdates = (0, groupBy_1.default)(updates, update => update.group);
return formatPlatformForUpdateGroup(group ? groupedUpdates[group] : undefined);
}
exports.getPlatformsForGroup = getPlatformsForGroup;
function formatPlatformForUpdateGroup(updateGroup) {
return !updateGroup || updateGroup.length === 0
? 'N/A'
: updateGroup
.map(update => update.platform)
.sort()
.join(', ');
}
exports.formatPlatformForUpdateGroup = formatPlatformForUpdateGroup;
function truncateString(originalMessage, length = 512) {
if (originalMessage.length > length) {
return originalMessage.substring(0, length - 3) + '...';
}
return originalMessage;
}
exports.truncateString = truncateString;
function formatUpdateMessage(update) {
if (!update) {
return 'N/A';
}
const message = update.message ? `"${truncateString(update.message)}" ` : '';
return `${message}(${(0, timeago_js_1.format)(update.createdAt, 'en_US')} by ${(0, User_1.getActorDisplayName)(update.actor)})`;
}
exports.formatUpdateMessage = formatUpdateMessage;
function ensureValidVersions(exp, platform) {
const error = new Error(`Couldn't find either ${chalk_1.default.bold('runtimeVersion')} or ${chalk_1.default.bold('sdkVersion')} to configure ${chalk_1.default.bold('expo-updates')}. Specify at least one of these properties under the ${chalk_1.default.bold('expo')} key in ${chalk_1.default.bold('app.json')}. ${(0, log_1.learnMore)('https://docs.expo.dev/eas-update/runtime-versions/')}`);
if ([platform_1.RequestedPlatform.Android, platform_1.RequestedPlatform.All].includes(platform) &&
!(exp.android?.runtimeVersion || exp.runtimeVersion) &&
!exp.sdkVersion) {
throw error;
}
if ([platform_1.RequestedPlatform.Ios, platform_1.RequestedPlatform.All].includes(platform) &&
!(exp.ios?.runtimeVersion || exp.runtimeVersion) &&
!exp.sdkVersion) {
throw error;
}
}
exports.ensureValidVersions = ensureValidVersions;
function formatUpdateTitle(update) {
const { message, createdAt, actor, runtimeVersion } = update;
let actorName;
switch (actor?.__typename) {
case 'User':
case 'SSOUser': {
actorName = actor.username;
break;
}
case 'Robot': {
const { firstName, id } = actor;
actorName = firstName ?? `robot: ${id.slice(0, 4)}...`;
break;
}
case undefined: {
actorName = 'unknown';
}
}
return `[${(0, dateformat_1.default)(createdAt, 'mmm dd HH:MM')} by ${actorName}, runtimeVersion: ${runtimeVersion}] ${message}`;
}
exports.formatUpdateTitle = formatUpdateTitle;
function getUpdateJsonInfosForUpdates(updates) {
return updates.map(update => ({
id: update.id,
createdAt: update.createdAt,
group: update.group,
branch: update.branch.name,
message: update.message,
runtimeVersion: update.runtimeVersion,
platform: update.platform,
manifestPermalink: update.manifestPermalink,
isRollBackToEmbedded: update.isRollBackToEmbedded,
gitCommitHash: update.gitCommitHash,
}));
}
exports.getUpdateJsonInfosForUpdates = getUpdateJsonInfosForUpdates;
function getUpdateGroupDescriptions(updateGroups) {
return updateGroups.map(updateGroup => ({
message: formatUpdateMessage(updateGroup[0]),
runtimeVersion: updateGroup[0].runtimeVersion,
isRollBackToEmbedded: updateGroup[0].isRollBackToEmbedded,
rolloutPercentage: updateGroup[0].rolloutPercentage ?? undefined,
codeSigningKey: updateGroup[0].codeSigningInfo?.keyid,
group: updateGroup[0].group,
platforms: formatPlatformForUpdateGroup(updateGroup),
}));
}
exports.getUpdateGroupDescriptions = getUpdateGroupDescriptions;
function getUpdateGroupDescriptionsWithBranch(updateGroups) {
return updateGroups.map(updateGroup => ({
branch: updateGroup[0].branch.name,
message: formatUpdateMessage(updateGroup[0]),
runtimeVersion: updateGroup[0].runtimeVersion,
isRollBackToEmbedded: updateGroup[0].isRollBackToEmbedded,
rolloutPercentage: updateGroup[0].rolloutPercentage ?? undefined,
codeSigningKey: updateGroup[0].codeSigningInfo?.keyid,
group: updateGroup[0].group,
platforms: formatPlatformForUpdateGroup(updateGroup),
}));
}
exports.getUpdateGroupDescriptionsWithBranch = getUpdateGroupDescriptionsWithBranch;
function getBranchDescription(branch) {
if (branch.updates.length === 0) {
return { branch: branch.name };
}
const latestUpdate = branch.updates[0];
return {
branch: branch.name,
update: {
message: formatUpdateMessage(latestUpdate),
runtimeVersion: latestUpdate.runtimeVersion,
isRollBackToEmbedded: latestUpdate.isRollBackToEmbedded,
rolloutPercentage: latestUpdate.rolloutPercentage ?? undefined,
codeSigningKey: latestUpdate.codeSigningInfo?.keyid,
group: latestUpdate.group,
platforms: getPlatformsForGroup({
group: latestUpdate.group,
updates: branch.updates,
}),
},
};
}
exports.getBranchDescription = getBranchDescription;
async function checkEASUpdateURLIsSetAsync(exp, projectId) {
const configuredURL = exp.updates?.url;
const expectedURL = (0, api_1.getEASUpdateURL)(projectId);
return configuredURL === expectedURL;
}
exports.checkEASUpdateURLIsSetAsync = checkEASUpdateURLIsSetAsync;
;