UNPKG

shipthis

Version:

ShipThis manages building and uploading your Godot games to the App Store and Google Play.

126 lines (121 loc) 5.19 kB
import { jsxs, Fragment, jsx } from 'react/jsx-runtime'; import { Flags } from '@oclif/core'; import { Box, Text, render } from 'ink'; import { b as getShortDate, A as ApiKey, C as CredentialsType, P as Platform, B as BaseAuthenticatedCommand } from '../../../index-BwnzoldS.js'; import Spinner from 'ink-spinner'; import 'node:crypto'; import 'node:fs'; import 'node:path'; import 'node:readline'; import 'node:url'; import 'readline-sync'; import { DateTime } from 'luxon'; import 'axios'; import 'isomorphic-git'; import { useQuery } from '@tanstack/react-query'; import 'react'; import 'crypto-js'; import 'uuid'; import 'fast-glob'; import 'yazl'; import 'socket.io-client'; import 'fullscreen-ink'; import 'string-length'; import 'strip-ansi'; import 'open'; import { u as useUserCredentials, U as UserCredentialsTable } from '../../../UserCredentialsTable-CUrTDzTK.js'; import '@inkjs/ui'; import '../../../ejs-DirFZbza.js'; import 'marked'; import 'marked-terminal'; import 'qrcode'; import '../../../index-hoHfGrjg.js'; import { T as Table } from '../../../Table-FaNgpyeq.js'; import { T as Title } from '../../../Title-BCQtayg6.js'; import { N as NextSteps } from '../../../NextSteps-DbJHmscQ.js'; import { C as Command } from '../../../Command-DN1j3tjt.js'; import '@expo/apple-utils/build/index.js'; import 'deepmerge'; import 'ini'; import '../../../useAndroidServiceAccountTestResult-CwKeW0ED.js'; import '../../../index-CJWMt1s-.js'; import 'fs'; import 'path'; async function queryAppleApiKeys({ ctx }) { const keys = await ApiKey.getAsync(ctx); const activeKeys = keys.filter((key) => key.attributes.isActive); return activeKeys; } const canAppleApiKeyBeUsed = (key, userCredentials) => { if (!key.attributes.isActive) return false; return userCredentials.some((cred) => cred.isActive && cred.serialNumber === key.id); }; function getAppleApiKeySummary(key, userCredentials) { const summary = {}; summary.keyID = key.id; summary.name = key.attributes.nickname; summary.roles = key.attributes.roles?.join(", "); summary.lastUsed = getShortDate(DateTime.fromISO(key.attributes.lastUsed)); summary.canBeUsed = canAppleApiKeyBeUsed(key, userCredentials); return summary; } const useAppleApiKeys = (props) => { const queryResult = useQuery({ queryFn: () => queryAppleApiKeys(props), queryKey: ["appleApiKeys"] }); return queryResult; }; const AppleApiKeysTable = ({ ctx, ...boxProps }) => { const { data: userCredentialsResponse } = useUserCredentials({ platform: Platform.IOS, type: CredentialsType.KEY }); const { data: keys, isLoading } = useAppleApiKeys({ ctx }); const hasUsable = keys && userCredentialsResponse && keys.some((key) => canAppleApiKeyBeUsed(key, userCredentialsResponse.data)); return /* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginBottom: 1, ...boxProps, children: [ /* @__PURE__ */ jsx(Title, { children: "App Store Connect API Keys in your Apple account" }), isLoading && /* @__PURE__ */ jsx(Spinner, { type: "dots" }), keys && userCredentialsResponse && /* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsxs(Box, { flexDirection: "column", marginBottom: 1, marginLeft: 2, children: [ /* @__PURE__ */ jsx(Text, { children: `You have ${keys.length} App Store Connect API Keys in your Apple account` }), /* @__PURE__ */ jsx(Text, { children: `${hasUsable ? "One" : "None"} of these can be used by ShipThis` }) ] }), keys.length > 0 && /* @__PURE__ */ jsx(Table, { data: keys.map((key) => getAppleApiKeySummary(key, userCredentialsResponse.data)) }), !hasUsable && /* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsx(Text, { bold: true, children: "You do not have a usable App Store Connect API Key. To ship an iOS game, you will need a usable App Store Connect API Key." }) }) ] }) ] }), keys && !hasUsable && /* @__PURE__ */ jsx(NextSteps, { steps: ["shipthis apple apiKey create"] }) ] }); }; class AppleApiKeyStatus extends BaseAuthenticatedCommand { static args = {}; static description = "Displays the status of App Store Connect API Keys in your Apple and ShipThis accounts.\nThis API key is used to automatically publish your games to the App Store."; static examples = [ "<%= config.bin %> <%= command.id %>", "<%= config.bin %> <%= command.id %> --noAppleAuth" ]; static flags = { noAppleAuth: Flags.boolean({ char: "f" }) }; async run() { const { flags } = this; const showApple = !flags.noAppleAuth; let ctx = null; if (showApple) { const authState = await this.refreshAppleAuthState(); ctx = authState.context; } render( /* @__PURE__ */ jsxs(Command, { command: this, children: [ /* @__PURE__ */ jsx( UserCredentialsTable, { credentialTypeName: "App Store Connect API Key", queryProps: { platform: Platform.IOS, type: CredentialsType.KEY } } ), showApple && /* @__PURE__ */ jsx(AppleApiKeysTable, { ctx }) ] }) ); } } export { AppleApiKeyStatus as default };