UNPKG

shipthis

Version:

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

108 lines (104 loc) 3.74 kB
import { jsxs, jsx } from 'react/jsx-runtime'; import { Box, Text } from 'ink'; import Spinner from 'ink-spinner'; import { useContext, useState, useEffect } from 'react'; import 'node:crypto'; import fs__default from 'node:fs'; import 'node:path'; import 'node:readline'; import 'node:url'; import 'readline-sync'; import 'luxon'; import 'axios'; import 'isomorphic-git'; import { H as queryClient, P as Platform, C as CredentialsType } from './baseCommand-CTn3KGH3.js'; import '@oclif/core'; import { useMutation } from '@tanstack/react-query'; import 'crypto-js'; import { v4 } from 'uuid'; import 'fast-glob'; import { ZipFile } from 'yazl'; import 'socket.io-client'; import 'fullscreen-ink'; import 'string-length'; import 'strip-ansi'; import 'open'; import '@inkjs/ui'; import { k as cacheKeys, G as GameContext } from './baseGameCommand-8VL7xe-O.js'; import 'marked'; import 'marked-terminal'; import 'qrcode'; import { i as importCredential } from './import-Dk2ywOVU.js'; async function importKeystore({ log = () => { }, ...opt }) { if (!opt.zipFilePath && !opt.jksFilePath) { throw new Error("You must provide either a zipFilePath or a jksFilePath"); } if (opt.zipFilePath && opt.jksFilePath) { throw new Error("You cannot provide both a zipFilePath and a jksFilePath"); } if (opt.jksFilePath && (!opt.keystorePassword || !opt.keyPassword)) { throw new Error("You must provide both keystorePassword and keyPassword when importing a jks file"); } const toDelete = []; if (opt.jksFilePath) { log("Creating zip file from jks file..."); const outputZipToFile = (zip, fileName) => new Promise((resolve) => { const outputStream = fs__default.createWriteStream(fileName); zip.outputStream.pipe(outputStream).on("close", () => resolve()); zip.end(); }); const zipFile = new ZipFile(); log("Adding keyStore.jks to zip file..."); zipFile.addFile(opt.jksFilePath, "keyStore.jks"); log("Adding password.txt and keyPassword.txt to zip file..."); zipFile.addBuffer(Buffer.from(`${opt.keystorePassword}`), "password.txt"); zipFile.addBuffer(Buffer.from(`${opt.keyPassword}`), "keyPassword.txt"); const tmpZipFile = `${process.cwd()}/shipthis-keyStore-${v4()}.zip`; log(`Writing zip file: ${tmpZipFile}`); await outputZipToFile(zipFile, tmpZipFile); toDelete.push(tmpZipFile); opt.zipFilePath = tmpZipFile; } log("Uploading and importing zip file..."); const keyStore = await importCredential({ platform: Platform.ANDROID, projectId: opt.gameId, type: CredentialsType.CERTIFICATE, zipPath: `${opt.zipFilePath}` }); log("Imported successfully"); for (const file of toDelete) { log(`Deleting temporary file: ${file}`); fs__default.unlinkSync(file); } return keyStore; } const useImportKeystore = () => useMutation({ mutationFn: importKeystore, async onSuccess(data) { const { projectId } = data; queryClient.invalidateQueries({ queryKey: cacheKeys.projectCredentials({ pageNumber: 0, projectId }) }); } }); const ImportKeystore = ({ importKeystoreProps, onComplete, onError }) => { const { gameId } = useContext(GameContext); const importMutation = useImportKeystore(); const [log, setLog] = useState(null); useEffect(() => { if (!gameId) return; const importOpts = { ...importKeystoreProps, gameId, log: setLog }; importMutation.mutateAsync(importOpts).catch(onError).then(onComplete); }, [gameId]); return /* @__PURE__ */ jsxs(Box, { flexDirection: "row", gap: 1, children: [ /* @__PURE__ */ jsx(Spinner, { type: "dots" }), log && /* @__PURE__ */ jsx(Text, { children: log }) ] }); }; export { ImportKeystore as I };