skip to the page

@jam-overture/loom/cli

Scaffolding and inspection from a terminal.

Everything below is exported from that import. The names, the signatures and the sentences are read from the package itself rather than written here, so this page says what the copy of Loom in your node_modules says — and it changes in the same pull request the code does.

29 exports, in 6 modules. Generated from ./dist/cli/index.d.ts, which is the declaration file this package publishes for @jam-overture/loom/cli. Each comment inside a declaration is shown as its first paragraph. The whole of it is in that file.

Nothing to install first. Everything this import loads arrives with @jam-overture/loom itself.

No import here has everything behind it. @jam-overture/loom/cli publishes 29 of the 2,237 names this package publishes. The other 2,208 are behind one of the 19 other imports, and not one of those imports publishes a single name this one does. The imports do not nest: a name that is not on this page is not a name that does not exist, and the search at the top of the page says which import it comes from.

Reading the arguments

cli/args

Argument parsing, by hand rather than by dependency.

DEFAULT_DIRECTORYvalue

const DEFAULT_DIRECTORY = "loom"

parseArgumentsfunction

Shown in use on Scaffolding from your own code — Seeing what would be written

const parseArguments: (argv: readonly string[]) => Result<CliCommand, CliError>

Filesystem

cli/filesystem

The CLI's only impure seam.

FileSysteminterface

Shown in use on Scaffolding from your own code — The disk is the part you replace

interface FileSystem {
    readonly list: (directory: string) => Promise<Result<readonly string[], string>>;
    readonly write: (path: string, contents: string) => Promise<Result<void, string>>;
}

nodeFileSystemvalue

Shown in use on Scaffolding from your own code — The disk is the part you replace

const nodeFileSystem: FileSystem

Namespace

cli/namespace

The one namespace the CLI will not write into, and the one it writes instead.

FRAMEWORK_NAMESPACEvalue

Reserved in full: loom itself, and everything beneath it.

const FRAMEWORK_NAMESPACE = "loom"

HOST_NAMESPACEvalue

What the CLI names things instead — app.page, app.card.

const HOST_NAMESPACE = "app"

isFrameworkNamespacedfunction

Shown in use on Scaffolding from your own code — One name the tool will not write

const isFrameworkNamespaced: (type: string) => boolean

hostAlternativeForfunction

The same name under the host's namespace, offered in the refusal.

Shown in use on Scaffolding from your own code — One name the tool will not write

const hostAlternativeFor: (type: string) => string

What a command will do

cli/plan

What a command would write, decided before anything is written.

CliCommandtype

Shown in use on Scaffolding from your own code — Seeing what would be written

type CliCommand = {
    readonly kind: "init";
    readonly directory: string;
} | {
    readonly kind: "add-primitive";
    readonly directory: string;
    readonly type: string;
} | {
    readonly kind: "help";
};

CliErrortype

type CliError = {
    readonly code: "unknown-command";
    readonly given: string;
} | {
    readonly code: "missing-argument";
    readonly argument: string;
} | {
    readonly code: "unexpected-argument";
    readonly given: string;
} | {
    readonly code: "invalid-primitive-type";
    readonly type: string;
} | {
    readonly code: "reserved-primitive-type";
    readonly type: string;
} | {
    readonly code: "framework-namespace";
    readonly type: string;
} | {
    readonly code: "already-registered";
    readonly type: string;
} | {
    readonly code: "file-exists";
    readonly path: string;
} | {
    readonly code: "filesystem-failed";
    readonly path: string;
    readonly detail: string;
};

CliErrorCodetype

type CliErrorCode = CliError["code"];

CLI_ERROR_CODESvalue

Every way a command can refuse, in the order a user meets them.

Shown in use on Scaffolding from your own code — A refusal is the same call, with no disk involved

const CLI_ERROR_CODES: readonly CliErrorCode[]

PlannedFiletype

type PlannedFile = {
    readonly path: string;
    readonly contents: string;
};

WritePlantype

type WritePlan = {
    readonly files: readonly PlannedFile[];
    /** Lines for the caller to print — what happened, and what to do next. */
    readonly notes: readonly string[];
};

PRIMITIVES_DIRECTORYvalue

const PRIMITIVES_DIRECTORY = "primitives"

existingPrimitivesfunction

The primitive modules already in the directory, recovered from their names.

Shown in use on Scaffolding from your own code — The listing is the registration

const existingPrimitives: (paths: readonly string[]) => readonly PrimitiveNames[]

planCommandfunction

Shown in use on Scaffolding from your own code — Seeing what would be written

const planCommand: (command: CliCommand, existing: readonly string[]) => Result<WritePlan, CliError>

Running a command

cli/run

Parse, plan, write — in that order, and only writing once the whole plan is known to be safe. A command that would clash with an existing file writes nothing at all rather than leaving a directory half-scaffolded.

CLI_USAGEvalue

const CLI_USAGE = "loom \u2014 scaffolding for the Loom primitive registry\n\nUsage:\n  loom init [--dir <directory>]\n  loom add primitive <type> [--dir <directory>]\n  loom --help\n\nOptions:\n  --dir <directory>   Where the Loom source lives (default: loom)\n\ninit writes a starter primitive, a generated registry, and a conformance test\ninto <directory>/primitives. add primitive declares one more and\nregenerates the registry from the directory's contents.\n\nA type is dot-namespaced kebab-case: app.card, commerce.product-card.\nloom.* is the framework's own namespace and is refused \u2014 those\nnames belong to the primitives @jam-overture/loom already registers."

CliReporttype

type CliReport = {
    readonly written: readonly string[];
    readonly notes: readonly string[];
    readonly usage: boolean;
};

describeCliErrorfunction

Shown in use on Scaffolding from your own code — Seeing what would be written

const describeCliError: (error: CliError) => string

runClifunction

Shown in use on Scaffolding from your own code — The disk is the part you replace

const runCli: (argv: readonly string[], filesystem: FileSystem) => Promise<Result<CliReport, CliError>>

Templates

cli/templates

What the CLI writes, as pure functions of a name.

PrimitiveNamestype

type PrimitiveNames = {
    /** The primitive type, exactly as a tree will address it. */
    readonly type: string;
    /**
     * The module basename, which is the type verbatim: `commerce.product-card.ts`.
     */
    readonly module: string;
    /** The exported binding: `commerce.product-card` → `commerceProductCard`. */
    readonly exportName: string;
};

namesForfunction

Shown in use on Scaffolding from your own code — The files, with no disk at all

const namesFor: (type: string) => PrimitiveNames

primitiveModulefunction

Shown in use on Scaffolding from your own code — The files, with no disk at all

const primitiveModule: (names: PrimitiveNames) => string

REGISTRY_MODULEvalue

const REGISTRY_MODULE = "registry.ts"

CONFORMANCE_TEST_MODULEvalue

const CONFORMANCE_TEST_MODULE = "registry.test.ts"

RESERVED_PRIMITIVE_TYPESvalue

Reserved because the registry and its test share the primitives directory, and registry and registry.test are both valid primitive types — so a primitive named either one would be written over the file that registers it.

const RESERVED_PRIMITIVE_TYPES: readonly string[]

registryModulefunction

Shown in use on Scaffolding from your own code — The files, with no disk at all

const registryModule: (primitives: readonly PrimitiveNames[]) => string

conformanceTestfunction

The generated test is the point of the generated scaffold. auditRegistry reports and never enforces, so a deployment only benefits from it if something actually runs it — and a host is far more likely to keep a test that was there from the first commit than to add one later.

const conformanceTest: () => string