UNPKG

shipthis

Version:

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

154 lines (151 loc) 4.33 kB
import crypto from 'node:crypto'; import fs__default from 'node:fs'; import path from 'node:path'; import { promises } from 'node:readline'; import { fileURLToPath } from 'node:url'; import readlineSync from 'readline-sync'; import { L as JobStage, P as Platform, M as LogLevel, J as JobStatus } from './index-BwnzoldS.js'; import 'luxon'; import 'axios'; import 'isomorphic-git'; import '@oclif/core'; import '@tanstack/react-query'; import 'react'; import 'crypto-js'; import 'uuid'; import 'fast-glob'; import 'yazl'; import 'socket.io-client'; import 'fullscreen-ink'; import 'ink'; function getShortUUID(originalUuid) { return originalUuid.slice(0, 8); } function getStageColor(stage) { switch (stage) { case JobStage.SETUP: { return "#FFB3B3"; } // pastel red case JobStage.CONFIGURE: { return "#FFD9B3"; } // pastel orange case JobStage.EXPORT: { return "#FFFACD"; } // pastel yellow case JobStage.BUILD: { return "#B3FFB3"; } // pastel green case JobStage.PUBLISH: { return "#B3D9FF"; } } } function getMessageColor(level) { switch (level) { case LogLevel.INFO: { return "white"; } case LogLevel.WARN: { return "yellow"; } case LogLevel.ERROR: { return "red"; } } } function getJobStatusColor(status) { switch (status) { case JobStatus.PENDING: { return "yellow"; } case JobStatus.PROCESSING: { return "blue"; } case JobStatus.COMPLETED: { return "green"; } case JobStatus.FAILED: { return "red"; } } } async function getFileHash(filename) { return new Promise((resolve, reject) => { const hash = crypto.createHash("sha256"); const rs = fs__default.createReadStream(filename); rs.on("error", reject); rs.on("data", (chunk) => hash.update(chunk)); rs.on("end", () => resolve(hash.digest("hex"))); }); } function isValidSemVer(versionString) { const [semVer, major, minor, patch, prerelease, buildmetadata] = versionString.match( /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*))*))?(?:\+([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?$/ ) ?? []; return Boolean(semVer); } function makeHumanReadable(rawObject) { const getLabel = (key) => { const words = key.split(/(?=[A-Z])/); return words.map((word) => word[0].toUpperCase() + word.slice(1)).join(" ").replaceAll(" ", " "); }; const withLabels = Object.entries(rawObject).reduce((acc, [key, value]) => { acc[getLabel(key)] = value; return acc; }, {}); return withLabels; } function getPlatformName(platform) { switch (platform) { case Platform.IOS: { return "iOS"; } case Platform.ANDROID: { return "Android"; } default: { throw new Error(`Unknown platform: ${platform}`); } } } async function getMaskedInput(message) { const password = readlineSync.question(message, { hideEchoBack: true // This will hide the input as the user types }); return password; } async function getInput(message) { const rl = promises.createInterface({ input: process.stdin, output: process.stdout }); const answer = await rl.question(message); rl.close(); return answer; } function generatePackageName(gameName) { let normalizedGameName = gameName.trim().toLowerCase(); normalizedGameName = normalizedGameName.replaceAll(/[\s_\-]+/g, "."); normalizedGameName = normalizedGameName.replaceAll(/[^\d.a-z]/g, ""); normalizedGameName = normalizedGameName.replaceAll(/\.+/g, "."); normalizedGameName = normalizedGameName.replace(/^\./, "").replace(/\.$/, ""); if (/^\d/.test(normalizedGameName)) { normalizedGameName = "app." + normalizedGameName; } const prefix = "com."; if (normalizedGameName === "") { return null; } return prefix + normalizedGameName; } function scriptDir(importMeta) { const filename = fileURLToPath(importMeta.url); const dirname = path.dirname(filename); return dirname; } export { getInput as a, generatePackageName as b, getJobStatusColor as c, getStageColor as d, getMaskedInput as e, getFileHash as f, getShortUUID as g, getPlatformName as h, isValidSemVer as i, getMessageColor as j, makeHumanReadable as m, scriptDir as s };