UNPKG

shipthis

Version:

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

145 lines (139 loc) 5.11 kB
import { jsx, Fragment, jsxs } from 'react/jsx-runtime'; import { Text, Box } from 'ink'; import open from 'open'; import { useState, useEffect, useContext } from 'react'; import 'ink-spinner'; import 'node:crypto'; import 'node:fs'; import 'node:path'; import 'node:readline'; import 'node:url'; import 'readline-sync'; import 'luxon'; import 'axios'; import 'isomorphic-git'; import { a3 as getShortAuthRequiredUrl, a5 as getGoogleAuthUrl, W as WEB_URL } from './baseCommand-CTn3KGH3.js'; import '@oclif/core'; import '@tanstack/react-query'; import 'crypto-js'; import 'uuid'; import 'fast-glob'; import 'yazl'; import 'socket.io-client'; import { u as useGoogleStatus } from './useGoogleStatus-WqPgHteE.js'; import { u as useWebSocket } from './useWebSocket-MXDbQHcu.js'; import 'fullscreen-ink'; import { G as GameContext, w as useSafeInput, M as Markdown } from './baseGameCommand-8VL7xe-O.js'; import 'string-length'; import 'strip-ansi'; import '@inkjs/ui'; import 'marked'; import 'marked-terminal'; import qrcode from 'qrcode'; function useGoogleStatusWatching({ isWatching, onGoogleStatusUpdate, projectId }) { const [wsGoogleStatus, setWsGoogleStatus] = useState(null); const listener = { async eventHandler(pattern, data2) { setWsGoogleStatus(data2); if (onGoogleStatusUpdate) onGoogleStatusUpdate(data2); }, getPattern: () => `project.${projectId}:google-status` }; useWebSocket([listener] ); const { data: googleStatus, isLoading } = useGoogleStatus(); useEffect(() => { setWsGoogleStatus(null); }, [projectId, isWatching, googleStatus]); const fetchedGoogleStatus = googleStatus ? googleStatus : null; const data = wsGoogleStatus ? wsGoogleStatus : fetchedGoogleStatus; return { data, isLoading }; } const QRCodeTerminal = ({ url }) => { const [code, setCode] = useState(null); const handleLoad = async () => { const codeString = await qrcode.toString(url, { errorCorrectionLevel: "L", small: true, type: "terminal" }); setCode(codeString); }; useEffect(() => { handleLoad(); }, []); return /* @__PURE__ */ jsx(Fragment, { children: code && /* @__PURE__ */ jsx(Text, { children: code }) }); }; async function getConnectUrl(gameId, helpPage) { const helpPagePath = `/docs/android?gameId=${gameId}#2-connect-shipthis-with-google`; const url = helpPage ? await getShortAuthRequiredUrl(helpPagePath) : await getGoogleAuthUrl(gameId); return url; } const GoogleAuthQRCode = ({ gameId, helpPage }) => { const [url, setUrl] = useState(null); const handleLoad = async () => { const url2 = await getConnectUrl(gameId, helpPage); setUrl(url2); }; useEffect(() => { handleLoad(); }, []); return /* @__PURE__ */ jsx(Fragment, { children: url && /* @__PURE__ */ jsx(QRCodeTerminal, { url }) }); }; const ConnectGoogle = (props) => { const { gameId } = useContext(GameContext); return /* @__PURE__ */ jsx(Fragment, { children: gameId && /* @__PURE__ */ jsx(ConnectForGame, { gameId, ...props }) }); }; const ConnectForGame = ({ gameId, helpPage, onComplete, onError, ...boxProps }) => { const [showQRCode, setShowQRCode] = useState(false); const [connectUrl, setConnectUrl] = useState(null); useEffect(() => { const fetchConnectUrl = async () => { const url = await getConnectUrl(gameId, Boolean(helpPage)); setConnectUrl(url); }; if (!connectUrl) fetchConnectUrl(); }, []); useGoogleStatusWatching({ isWatching: true, onGoogleStatusUpdate(status) { if (status.isAuthenticated) return onComplete(); }, projectId: gameId }); useSafeInput(async (input) => { switch (input) { case "q": { setShowQRCode(true); return; } case "x": { setShowQRCode(false); return; } case "b": { if (!gameId) return; if (!connectUrl) return; await open(connectUrl); } } }); const templateVars = { privacyURL: new URL("/privacy", WEB_URL).toString() }; return /* @__PURE__ */ jsxs(Box, { flexDirection: "column", gap: 1, ...boxProps, children: [ !showQRCode && /* @__PURE__ */ jsxs(Box, { flexDirection: "column", gap: 1, children: [ /* @__PURE__ */ jsx(Markdown, { filename: "privacy-notification.md.ejs", templateVars }), connectUrl && /* @__PURE__ */ jsx(Text, { bold: true, color: "#4CE64C", children: `Press B to open ${connectUrl} in your browser and connect your Google account to ShipThis` }), /* @__PURE__ */ jsx(Text, { bold: true, color: "#4CE64C", children: "Press Q to show a QR-code to connect using your mobile phone" }) ] }), showQRCode && /* @__PURE__ */ jsxs(Box, { flexDirection: "column", gap: 1, children: [ /* @__PURE__ */ jsx(Text, { children: "Scan the QR code below to connect your Google account to ShipThis:" }), gameId && /* @__PURE__ */ jsx(GoogleAuthQRCode, { gameId, helpPage: Boolean(helpPage) }), /* @__PURE__ */ jsx(Text, { bold: true, color: "#4CE64C", children: "Press X to hide the QR code" }) ] }) ] }); }; export { ConnectGoogle as C };