create-gluon


create-gluon / packages/create-gluon/src / ParsedAddComponentArguments

Interface: ParsedAddComponentArguments

Properties

confirmOverwrite

readonly confirmOverwrite: boolean


dryRun

readonly dryRun: boolean


help

readonly help: boolean


kind?

readonly optional kind?: "atom" | "molecule" | "organism" | "element" | "headless"


name?

readonly optional name?: string


overwrite

readonly overwrite: boolean


path?

readonly optional path?: string


root?

readonly optional root?: string


tagName?

readonly optional tagName?: string


yes

readonly yes: boolean

Example

Inspect immutable add-component CLI values before interactive defaults or filesystem validation are applied:

ts
import { PassThrough } from 'node:stream';
import {
  AddComponentError,
  addComponent,
  addComponentHelpText,
  componentKindHelpText,
  componentKinds,
  parseAddComponentArguments,
  planComponent,
  runAddComponentCli,
  type AddComponentAction,
  type AddComponentErrorCode,
  type AddComponentOperation,
  type AddComponentOptions,
  type AddComponentResult,
  type ComponentKind,
  type ParsedAddComponentArguments,
} from 'create-gluon';

const parsed: ParsedAddComponentArguments = parseAddComponentArguments([
  'PurchaseAction', '--kind', 'molecule', '--root', '/tmp/shop', '--dry-run', '--yes',
]);
const kind: ComponentKind = parsed.kind ?? componentKinds[0];
const options = {
  kind,
  name: parsed.name!,
  root: parsed.root,
  dryRun: true,
} satisfies AddComponentOptions;
const planned: Promise<AddComponentResult> = planComponent(options);
const generated: Promise<AddComponentResult> = addComponent(options);
const operation = { path: 'src/components/index.ts', action: 'update', bytes: 80 } satisfies AddComponentOperation;
const action: AddComponentAction = operation.action;
const output = new PassThrough();
await runAddComponentCli(['--help'], { output, cwd: '/tmp/shop' });
console.log(planned, generated, action, addComponentHelpText, componentKindHelpText);
try { throw new AddComponentError('FILE_COLLISION', 'existing component'); } catch (error) {
  if (error instanceof AddComponentError) {
    const code: AddComponentErrorCode = error.code;
    console.error(code);
  }
}