shipthis
Version:
ShipThis manages building and uploading your Godot games to the App Store and Google Play.
118 lines (114 loc) • 3.93 kB
JavaScript
import { Flags } from '@oclif/core';
import axios from 'axios';
import { W as WEB_URL, B as BaseCommand, Z as acceptTerms, o as API_URL, _ as setAuthToken } from '../baseCommand-CTn3KGH3.js';
import 'react/jsx-runtime';
import 'ink';
import 'ink-spinner';
import { b as getInput } from '../baseGameCommand-8VL7xe-O.js';
import 'react';
import '@tanstack/react-query';
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 'open';
import '@inkjs/ui';
import 'node:path';
import 'marked';
import 'marked-terminal';
import 'qrcode';
import 'chalk';
import 'crypto-js';
import '@expo/apple-utils/build/index.js';
import 'node:crypto';
import 'node:readline';
import 'node:url';
import 'readline-sync';
import 'isomorphic-git';
import 'deepmerge';
import 'ini';
import 'fs';
import 'path';
const TERMS_URL = new URL("/terms", WEB_URL).href;
const PRIVACY_URL = new URL("/privacy", WEB_URL).href;
class Login extends BaseCommand {
static args = {};
static description = "Authenticate - will create a new account if one does not exist.";
static examples = [
"<%= config.bin %> <%= command.id %>",
"<%= config.bin %> <%= command.id %> --force --email me@email.nowhere",
"<%= config.bin %> <%= command.id %> --acceptAgreements"
];
static flags = {
email: Flags.string({
char: "e",
description: "Your email address"
}),
force: Flags.boolean({ char: "f" }),
acceptAgreements: Flags.boolean({
description: "Accept the current version of the agreements (terms & privacy).",
default: false
})
};
async run() {
const { flags } = this;
const authConfig = await this.getAuthConfig();
if (flags.acceptAgreements) {
if (authConfig.shipThisUser) {
await acceptTerms();
return this.log("You have accepted the latest terms and privacy policy.");
}
}
if (authConfig.shipThisUser && !flags.force) {
throw new Error(
`You are already logged in as ${authConfig.shipThisUser.email} use --force to login as a different user or remove the auth file`
);
}
const getEmail = async () => {
if (flags.email) return flags.email;
const email2 = await getInput("Please enter your email address: ");
if (!email2) throw new Error("Email address is required");
return email2;
};
const email = await getEmail();
await axios.post(`${API_URL}/auth/email/send`, { email });
this.log("Please check your email for an email with an OTP.");
const getOTP = async () => {
const otp2 = await getInput("Please enter the OTP: ");
if (!otp2) throw new Error("OTP is required");
return otp2;
};
const otp = await getOTP();
const source = `shipthis-cli-${this.config.version}`;
const { data: shipThisUser } = await axios.post(`${API_URL}/auth/email/verify`, { email, otp, source });
const getAcceptedTermsResponse = async () => {
if (flags.acceptAgreements) return true;
console.log(
`Please review the following documents:
${[
`- Privacy Policy: ${PRIVACY_URL}`,
`- Terms and Conditions: ${TERMS_URL}`
].join("\n")}
`
);
const accepted = await getInput("Do you accept the terms of these documents? (yes/no): ");
const answer = accepted.toLowerCase().trim().slice(0, 1);
return answer === "y";
};
await this.setAuthConfig({ shipThisUser });
setAuthToken(shipThisUser.jwt);
this.log("You are now logged in as", shipThisUser.email);
if (!shipThisUser.details?.hasAcceptedTerms) {
const didAccept = await getAcceptedTermsResponse();
if (!didAccept) throw new Error("You must accept the terms to continue");
await acceptTerms();
}
await this.config.runCommand("status");
}
}
export { Login as default };