UNPKG

shipthis

Version:

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

131 lines (128 loc) 5.26 kB
import { jsx, jsxs } from 'react/jsx-runtime'; import { Text, Box } from 'ink'; import { useState, useEffect, useContext } from 'react'; import { c as getShortDate, P as Platform, k as getProject, E as getProjectPlatformProgress } from './baseCommand-CTn3KGH3.js'; import 'ink-spinner'; import { g as getShortUUID, m as makeHumanReadable, G as GameContext, C as CommandContext } from './baseGameCommand-8VL7xe-O.js'; import '@tanstack/react-query'; import 'axios'; import 'luxon'; import 'node:fs'; import 'fast-glob'; import 'uuid'; import 'yazl'; import 'socket.io-client'; import 'fullscreen-ink'; import 'string-length'; import 'strip-ansi'; import { S as StatusTable } from './StatusTable-DzRWcMr4.js'; import 'open'; import '@inkjs/ui'; import 'node:path'; import 'marked'; import 'marked-terminal'; import { N as NextSteps } from './NextSteps-DbJHmscQ.js'; import 'qrcode'; function isPlatformConfigured(platform, progress) { if (!progress) return false; return progress.platform === platform && progress.hasBundleSet && progress.hasCredentialsForPlatform && progress.hasApiKeyForPlatform; } function getSteps(platform, progress) { if (!progress) return ["shipthis game wizard " + platform.toLowerCase()]; switch (platform) { case Platform.ANDROID: { return [ !progress.hasCredentialsForPlatform && "shipthis game android keyStore create", !progress.hasApiKeyForPlatform && "shipthis game android apiKey create", isPlatformConfigured(platform, progress) && "shipthis game ship" ].filter(Boolean); } case Platform.IOS: { return [ !progress.hasApiKeyForPlatform && "shipthis apple apiKey create", !progress.hasCredentialsForPlatform && "shipthis game ios profile create", isPlatformConfigured(platform, progress) && "shipthis game ship" ].filter(Boolean); } default: { throw new Error("Invalid platform"); } } } async function fetchGameStatus(gameId, platforms) { const game = await getProject(gameId); const isEnabled = {}; const statuses = {}; for (const platform of platforms) { isEnabled[platform] = platform === Platform.IOS ? Boolean(game.details?.iosBundleId) : Boolean(game.details?.androidPackageName); if (isEnabled[platform]) { statuses[platform] = await getProjectPlatformProgress(game.id, platform); } } let steps = []; for (const platform of platforms) { steps = steps.concat(getSteps(platform, statuses[platform])); } let exitCode = 0; for (const platform of platforms) { const platformStatus = statuses[platform]; if (!platformStatus) continue; const hasConfigError = isEnabled[platform] && !isPlatformConfigured(platform, platformStatus); if (hasConfigError) exitCode = exitCode || 1; } if (platforms.length === 1 && !isEnabled[platforms[0]]) { exitCode = exitCode || 1; } else if (platforms.length > 1 && !isEnabled[Platform.IOS] && !isEnabled[Platform.ANDROID]) { exitCode = exitCode || 1; } return { exitCode, game, isEnabled, statuses, steps }; } const GameStatusDetails = ({ children, gameId, onComplete, onError, platforms }) => { const [state, setState] = useState(null); useEffect(() => { fetchGameStatus(gameId, platforms).then((res) => { setState(res); setTimeout(() => onComplete?.(res.exitCode), 0); }).catch((error) => onError?.(error)); }, []); if (!state) return /* @__PURE__ */ jsx(Text, {}); const { game, statuses, steps } = state; const gameDetails = {}; gameDetails["Game ID"] = getShortUUID(game.id); gameDetails.Name = game.name; gameDetails.Version = game.details?.semanticVersion || "0.0.1"; gameDetails["Build Number"] = `${game.details?.buildNumber || 1}`; gameDetails["Created At"] = getShortDate(game.createdAt); gameDetails["Game Engine"] = `${game.details?.gameEngine || "godot"} ${game.details?.gameEngineVersion || "4.3"}`; return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", children: [ /* @__PURE__ */ jsx(StatusTable, { statuses: gameDetails, title: "Game Details" }), platforms.map((platform) => { const status = statuses[platform]; const label = platform === Platform.IOS ? "iOS" : "Android"; const color = platforms.length === 1 ? "red" : "yellow"; const { platform: _, ...statusValues } = status || {}; return /* @__PURE__ */ jsx(Box, { marginTop: 1, children: status ? /* @__PURE__ */ jsx(StatusTable, { statuses: makeHumanReadable(statusValues), title: `${label} Status` }) : /* @__PURE__ */ jsxs(Text, { color, children: [ "The ", label, " platform is not enabled for this game." ] }) }, platform); }), children, /* @__PURE__ */ jsx(NextSteps, { steps }) ] }); }; const GameStatus$1 = ({ children, onComplete }) => { const { gameId } = useContext(GameContext); const { command } = useContext(CommandContext); const flags = command && command.getFlags() || {}; const platforms = flags.platform ? [flags.platform.toUpperCase()] : [Platform.IOS, Platform.ANDROID]; if (!gameId) return null; return /* @__PURE__ */ jsx(GameStatusDetails, { gameId, onComplete, platforms, children }); }; export { GameStatusDetails as G, GameStatus$1 as a };