Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/excaliburjs/create-excalibur. A repo bootstrapping tool to get you started making your first games!
Something went wrong. Try again.
3.5 kB · 103 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104import { parseArgs } from "node:util";
export const GENERATE_OPTIONS = { help: { type: "boolean", short: "h" }, scene: { type: "string", short: "s" }, actor: { type: "string", short: "a" }, "dry-run": { type: "boolean" }, force: { type: "boolean" },} as const;
export type GenerateKind = | "actor" | "label" | "scene" | "resource" | "engine" | "material" | "update-actor" | "spritesheet" | "animation";
const KIND_ALIASES: Record<string, GenerateKind> = { a: "actor", actor: "actor", l: "label", label: "label", s: "scene", scene: "scene", r: "resource", resource: "resource", resources: "resource", e: "engine", engine: "engine", m: "material", material: "material", ua: "update-actor", "update-actor": "update-actor", ss: "spritesheet", spritesheet: "spritesheet", "sprite-sheet": "spritesheet", an: "animation", anim: "animation", animation: "animation",};
export const GENERATE_KINDS: readonly GenerateKind[] = ["actor", "label", "scene", "resource", "engine", "material", "update-actor", "spritesheet", "animation"];
export interface GenerateArgs { help: boolean; dryRun: boolean; force: boolean; scene: string | null; actor: string | null; rawKind: string | null; kind: GenerateKind | null; name: string | null;}
/** Parse the arguments that follow `ex generate` / `ex g`. */export function parseGenerateArgs(argv: string[]): GenerateArgs { const { values, positionals } = parseArgs({ args: argv, options: GENERATE_OPTIONS, allowPositionals: true, strict: false, }); const rawKind = positionals[0] ? String(positionals[0]) : null; const kind = rawKind ? (KIND_ALIASES[rawKind.toLowerCase()] ?? null) : null; return { help: Boolean(values.help), dryRun: Boolean(values["dry-run"]), force: Boolean(values.force), scene: values.scene ? String(values.scene) : null, actor: values.actor ? String(values.actor) : null, rawKind, kind, name: positionals[1] ? String(positionals[1]) : null, };}
export const GENERATE_USAGE = `Usage: ex generate <actor|label|scene|resource|engine|material|update-actor|spritesheet|animation> [name] [options] ex g <a|l|s|r|e|m|ua|ss|an> [name]
Generate Excalibur code into the current project and wire it up.
ex generate actor Player new actor class + add it to a scene's onInitialize ex generate label ScoreText new label class + add it to a scene ex generate scene Level2 new scene class + register it in the engine's scenes map ex generate resource add an image/sound/font to resources.ts (with file picker) ex generate engine configure EngineOptions (creates main.ts if no engine exists) ex generate material Ripple new custom-shader material + assign it to an actor's graphics ex generate update-actor Player change an existing actor's constructor options (ActorArgs) ex generate spritesheet Run slice a sheet image into a SpriteSheet in resources.ts (with preview) ex generate animation Idle build an Animation from a SpriteSheet's frames + wire it to an actor
Options: -s, --scene <name> target scene for actor/label wiring (skips the picker) -a, --actor <name> target actor for material wiring (skips the picker) --dry-run show what would be created/modified without writing --force overwrite an existing generated file -h, --help show this help`.trimStart();