UNPKG

shipthis

Version:

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

135 lines (131 loc) 4.73 kB
import { jsx } from 'react/jsx-runtime'; import { Flags } from '@oclif/core'; import { render } from 'ink'; import { g as getUserCredentials } from '../../../index-BW7z-5sB.js'; import forge from 'node-forge'; import { l as CertificateType, b as Certificate, P as Platform, C as CredentialsType } from '../../../baseCommand-CTn3KGH3.js'; import { B as BaseAppleCommand } from '../../../baseAppleCommand-Aq-Eaw_K.js'; import 'node:fs'; import 'axios'; import 'crypto-js'; import 'uuid'; import 'luxon'; import 'node:path'; import 'chalk'; import 'node:crypto'; import 'node:readline'; import 'node:url'; import 'readline-sync'; import 'isomorphic-git'; import '@tanstack/react-query'; import 'react'; import 'fast-glob'; import 'yazl'; import 'socket.io-client'; import 'fullscreen-ink'; import 'ink-spinner'; import 'string-length'; import 'strip-ansi'; import 'open'; import '@inkjs/ui'; import '../../../baseGameCommand-8VL7xe-O.js'; import 'marked'; import 'marked-terminal'; import 'qrcode'; import { R as RunWithSpinner } from '../../../RunWithSpinner-DucRnFp6.js'; import { C as Command } from '../../../Command-Cj6F5B5a.js'; import { u as uploadUserCredentials } from '../../../upload-CHaDSvvi.js'; import '@expo/apple-utils/build/index.js'; import 'deepmerge'; import 'ini'; import 'fs'; import 'path'; function decodeCertificate(certificateContent) { const decodedContent = forge.util.decode64(certificateContent); const asn1 = forge.asn1.fromDer(decodedContent); return forge.pki.certificateFromAsn1(asn1); } function encodePkcs12(pkcs12Asn1) { const derBytes = forge.asn1.toDer(pkcs12Asn1).getBytes(); return forge.util.encode64(derBytes); } async function createCertificate(ctx, certificateType = CertificateType.IOS_DISTRIBUTION) { const { keyPair: { privateKey }, pem: csrPem } = await Certificate.createCertificateSigningRequestAsync(); const certificate = await Certificate.createAsync(ctx, { certificateType, csrContent: csrPem }); return { certificate, privateKey, privateKeyPem: forge.pki.privateKeyToPem(privateKey) }; } function exportCertificate(certificate, privateKey) { const decodedCertificate = decodeCertificate(certificate.attributes.certificateContent); const password = forge.util.encode64(forge.random.getBytesSync(16)); const pkcs12Asn1 = forge.pkcs12.toPkcs12Asn1(privateKey, [decodedCertificate], password, { algorithm: "3des", friendlyName: "key" }); const encodedPkcs12 = encodePkcs12(pkcs12Asn1); return { certificateBase64: encodedPkcs12, certificatePassword: password }; } class AppleCertificateCreate extends BaseAppleCommand { static args = {}; static description = "Creates an iOS Distribution Certificate in your Apple Developer account.\nSaves the certificate with the private key to your ShipThis account"; static examples = ["<%= config.bin %> <%= command.id %>", "<%= config.bin %> <%= command.id %> --force"]; static flags = { force: Flags.boolean({ char: "f" }), quiet: Flags.boolean({ char: "q", description: "Avoid output except for interactions and errors" }) }; async run() { const { flags } = this; const { force } = flags; const userCredentials = await getUserCredentials(); const userAppleDistCredentials = userCredentials.filter( (cred) => cred.platform === Platform.IOS && cred.type === CredentialsType.CERTIFICATE && cred.isActive ); if (userAppleDistCredentials.length > 0 && !force) { this.error("An Apple Distribution Certificate already exists. Use --force to overwrite it."); } const authState = await this.refreshAppleAuthState(); const ctx = authState.context; const createCert = async () => { const { certificate, privateKey } = await createCertificate(ctx); const exported = exportCertificate(certificate, privateKey); const { serialNumber } = certificate.attributes; await uploadUserCredentials({ contents: { serialNumber, ...exported }, platform: Platform.IOS, serialNumber, type: CredentialsType.CERTIFICATE }); }; const handleComplete = async () => { await this.config.runCommand(`apple:certificate:status`); }; if (this.flags.quiet) return await createCert(); render( /* @__PURE__ */ jsx(Command, { command: this, children: /* @__PURE__ */ jsx( RunWithSpinner, { executeMethod: createCert, msgComplete: `Certificate created and saved to ShipThis`, msgInProgress: `Creating certificate in the Apple Developer Portal...`, onComplete: handleComplete } ) }) ); } } export { AppleCertificateCreate as default };