UNPKG

eas-cli

Version:
153 lines (152 loc) 7.29 kB
import { Command } from '@oclif/core'; import AnalyticsContextField from './context/AnalyticsContextField'; import ContextField from './context/ContextField'; import DynamicLoggedInContextField from './context/DynamicLoggedInContextField'; import { DynamicPrivateProjectConfigContextField, DynamicPublicProjectConfigContextField } from './context/DynamicProjectConfigContextField'; import LoggedInContextField from './context/LoggedInContextField'; import MaybeLoggedInContextField from './context/MaybeLoggedInContextField'; import { OptionalPrivateProjectConfigContextField } from './context/OptionalPrivateProjectConfigContextField'; import { PrivateProjectConfigContextField } from './context/PrivateProjectConfigContextField'; import ProjectDirContextField from './context/ProjectDirContextField'; import { ProjectIdContextField } from './context/ProjectIdContextField'; import { ServerSideEnvironmentVariablesContextField } from './context/ServerSideEnvironmentVariablesContextField'; import SessionManagementContextField from './context/SessionManagementContextField'; import VcsClientContextField from './context/VcsClientContextField'; import { EnvironmentVariableEnvironment } from '../graphql/generated'; import { Client } from '../vcs/vcs'; export type ContextInput<T extends { [name: string]: any; } = object> = { [P in keyof T]: ContextField<T[P]>; }; export type ContextOutput<T extends { [name: string]: any; } = object> = { [P in keyof T]: T[P]; }; type GetContextType<Type> = { [Property in keyof Type]: any; }; interface BaseGetContextAsyncArgs { nonInteractive: boolean; vcsClientOverride?: Client; } interface GetContextAsyncArgsWithRequiredServerSideEnvironmentArgument extends BaseGetContextAsyncArgs { withServerSideEnvironment: EnvironmentVariableEnvironment | null; } interface GetContextAsyncArgsWithoutServerSideEnvironmentArgument extends BaseGetContextAsyncArgs { withServerSideEnvironment?: never; } export default abstract class EasCommand extends Command { protected static readonly ContextOptions: { /** * Require this command to be run when logged-in. Returns the logged-in actor and a logged-in * graphql client in the context. */ LoggedIn: { loggedIn: LoggedInContextField; }; /** * Do not require this command to be run when logged-in, but if it is get the logged-in actor and a * maybe-logged-in graphql client. */ MaybeLoggedIn: { maybeLoggedIn: MaybeLoggedInContextField; }; /** * Specify this context if the logged-in requirement is only necessary in a particular execution of the command. */ DynamicLoggedIn: { getDynamicLoggedInAsync: DynamicLoggedInContextField; }; /** * Specify this context requirement if the command needs to mutate the user session. * @deprecated Should not be used outside of session management commands, which currently only includes `login` and `logout`. */ SessionManagment: { sessionManager: SessionManagementContextField; }; /** * Require the project to be identified and registered on server if this command is being * run within a project directory, null otherwise. */ OptionalProjectConfig: { optionalPrivateProjectConfig: OptionalPrivateProjectConfigContextField; }; /** * Require this command to be run in a project directory. Return the project directory in the context. */ ProjectDir: { projectDir: ProjectDirContextField; }; /** * Provides functions to load the project config when dynamic config options are needed (custom Env for example). */ DynamicProjectConfig: { getDynamicPublicProjectConfigAsync: DynamicPublicProjectConfigContextField; getDynamicPrivateProjectConfigAsync: DynamicPrivateProjectConfigContextField; }; /** * Require the project to be identified and registered on server. Returns the project config in the context. * This also requires the user to be logged in (getProjectIdAsync requires logged in), so also expose that context. * Exposing the loggedIn context here helps us guarantee user identification for logging purposes. */ ProjectConfig: { loggedIn: LoggedInContextField; privateProjectConfig: PrivateProjectConfigContextField; }; /** * Analytics manager. Returns the analytics manager in the context for use by the command. */ Analytics: { analytics: AnalyticsContextField; }; Vcs: { vcsClient: VcsClientContextField; }; ServerSideEnvironmentVariables: { getServerSideEnvironmentVariablesAsync: ServerSideEnvironmentVariablesContextField; }; /** * Require the project to be identified and registered on server. Returns the project ID evaluated from the app config. */ ProjectId: { projectId: ProjectIdContextField; }; }; /** * Context allows for subclasses (commands) to declare their prerequisites in a type-safe manner. * These declarative definitions each output a context property that is the result of the prerequisite being * satisfied. These allow a unified common interface to be shared amongst commands in order to provide a more * consistent CLI experience. * * For example, let's say a command needs the EAS project ID to make a GraphQL mutation. It should declare that * it requires the `ProjectConfig` context, and then call `getContextAsync` to get the project ID. */ static contextDefinition: ContextInput; /** * The user session manager. Responsible for coordinating all user session related state. * If needed in a subclass, use the SessionManager ContextOption. */ private sessionManagerInternal?; /** * The analytics manager. Used for logging analytics. * It is set up here to ensure a consistent setup. */ private analyticsInternal?; /** * Execute the context in the contextDefinition to satisfy command prerequisites. */ protected getContextAsync<C extends { [name: string]: any; } = object>(commandClass: { contextDefinition: ContextInput<C>; }, { nonInteractive, vcsClientOverride, withServerSideEnvironment, }: C extends GetContextType<typeof EasCommand.ContextOptions.ProjectConfig> | GetContextType<typeof EasCommand.ContextOptions.DynamicProjectConfig> | GetContextType<typeof EasCommand.ContextOptions.OptionalProjectConfig> | GetContextType<typeof EasCommand.ContextOptions.ServerSideEnvironmentVariables> ? GetContextAsyncArgsWithRequiredServerSideEnvironmentArgument : GetContextAsyncArgsWithoutServerSideEnvironmentArgument): Promise<ContextOutput<C>>; private get sessionManager(); private get analytics(); protected abstract runAsync(): Promise<any>; run(): Promise<any>; finally(err: Error): Promise<any>; protected catch(err: Error): Promise<any>; } export {};