FullStackedapi/contexts.mdEdit

contexts

ts
import contexts from "fullstacked/contexts";

The running projects (contexts) of this context's root and below: list them, find a project, focus, reload or close it. The shell's ps, focus, reload and kill use it, see Running projects.

ts
list(): Promise<ContextInfo[]>
find(directory: string): Promise<ContextInfo[]>
get(context: Context): Promise<ContextInfo>
focus(context: Context): Promise<void>
reload(context: Context): Promise<{ Errors: Message[]; Warnings: Message[] }>
close(context: Context, options?: { recursive?: boolean }): Promise<void>
exit(options?: { all?: boolean }): void
ts
type Context = number | { id: number; serial: number }; // an id, or a ContextInfo

type ContextInfo = {
    id: number;
    serial: number; // never reused, unlike id
    directory: string; // relative to this context's root: "/", "/demo"
    parent: number | null; // the context that ran it, when this one sees it
    children: number[];
    window: boolean; // a page is open for it
    safe: boolean;
    transform: boolean;
    self: boolean; // this context
};
  • find(directory): the running contexts of a project, directory relative to the working directory like run. Released contexts count, contexts in safe mode and this one don't. How a context checks a project isn't running before it runs it again.
  • focus: brings the context's window to the front, and opens one for a context without a window. Rejects where the host can't focus windows (the Node CLI).
  • reload: builds the project again (a bundle, or prepare in transform mode) and reloads its page in place, same id and window. With build errors, nothing is reloaded.
  • close: asks the context's page to exit, which closes its window; it ends after 3 seconds if it didn't. With recursive, the contexts it ran close first, otherwise they keep running without a parent.
  • exit: ends this context, like process.exit(). With all, the contexts it ran (and theirs) close too.

Pass a ContextInfo of list() (its id and serial) to focus, reload and close to be sure to reach that context and not one that took its id since. A number reaches the context holding that id now.

A context sees and acts on the contexts of its root and below only.