@lunora/cli 1.0.0-alpha.7 → 1.0.0-alpha.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/LICENSE.md +6 -0
  2. package/__assets__/package-og.svg +1 -1
  3. package/dist/bin.mjs +1 -1
  4. package/dist/index.d.mts +248 -115
  5. package/dist/index.d.ts +248 -115
  6. package/dist/index.mjs +8 -8
  7. package/dist/packem_chunks/handler.mjs +87 -6
  8. package/dist/packem_chunks/handler10.mjs +8 -14
  9. package/dist/packem_chunks/handler11.mjs +19 -189
  10. package/dist/packem_chunks/handler12.mjs +176 -115
  11. package/dist/packem_chunks/handler13.mjs +118 -52
  12. package/dist/packem_chunks/handler14.mjs +50 -43
  13. package/dist/packem_chunks/handler15.mjs +48 -67
  14. package/dist/packem_chunks/handler16.mjs +74 -37
  15. package/dist/packem_chunks/handler17.mjs +39 -100
  16. package/dist/packem_chunks/handler18.mjs +87 -152
  17. package/dist/packem_chunks/handler19.mjs +148 -67
  18. package/dist/packem_chunks/handler2.mjs +6 -4
  19. package/dist/packem_chunks/handler20.mjs +77 -75
  20. package/dist/packem_chunks/handler21.mjs +71 -288
  21. package/dist/packem_chunks/handler3.mjs +6 -3
  22. package/dist/packem_chunks/handler4.mjs +2 -2
  23. package/dist/packem_chunks/handler5.mjs +7 -4
  24. package/dist/packem_chunks/handler6.mjs +10 -7
  25. package/dist/packem_chunks/handler7.mjs +2 -2
  26. package/dist/packem_chunks/handler8.mjs +1 -1
  27. package/dist/packem_chunks/handler9.mjs +315 -12
  28. package/dist/packem_chunks/planDevCommand.mjs +653 -37
  29. package/dist/packem_chunks/runCodegenCommand.mjs +5 -4
  30. package/dist/packem_chunks/runDeployCommand.mjs +115 -20
  31. package/dist/packem_chunks/runInitCommand.mjs +1602 -172
  32. package/dist/packem_chunks/runMigrateGenerateCommand.mjs +5 -4
  33. package/dist/packem_chunks/runResetCommand.mjs +2 -2
  34. package/dist/packem_chunks/runRpcCommand.mjs +3 -2
  35. package/dist/packem_shared/{COMMANDS-Bn8luojF.mjs → COMMANDS-0BD3K1pb.mjs} +79 -21
  36. package/dist/packem_shared/{DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs → DEFAULT_IMPORT_BATCH_SIZE-CRQmmBZM.mjs} +3 -2
  37. package/dist/packem_shared/{api-spec-CtA6ilu4.mjs → api-spec-Bx0iKbxA.mjs} +3 -1
  38. package/dist/packem_shared/{buildRegistryIndex-BcYe607_.mjs → buildRegistryIndex-CqM5FwGI.mjs} +1 -1
  39. package/dist/packem_shared/codegen-error-DJG-ghs_.mjs +31 -0
  40. package/dist/packem_shared/{command-BDXcJCCJ.mjs → command-lYnl4QyF.mjs} +6 -1
  41. package/dist/packem_shared/{commands-DqsEzojt.mjs → commands-vnRRkhNE.mjs} +123 -15
  42. package/dist/packem_shared/{createLogger-CHPNjFw2.mjs → createLogger-CIWSHrTL.mjs} +40 -8
  43. package/dist/packem_shared/{createRecordingSpawner-DxI3mebw.mjs → createRecordingSpawner-Cw5Iu73G.mjs} +12 -2
  44. package/dist/packem_shared/{detect-package-manager-DYp7n3mJ.mjs → detect-package-manager-DvEthdCw.mjs} +26 -30
  45. package/dist/packem_shared/{insertSchemaExtension-BuzF6-t2.mjs → insertSchemaExtension-DAqbfr9Z.mjs} +15 -10
  46. package/dist/packem_shared/{open-url-Dfq6fAyT.mjs → open-url-4PBLY9X0.mjs} +3 -2
  47. package/dist/packem_shared/{output-format-7gyGR3h8.mjs → output-format-B4642rjE.mjs} +1 -1
  48. package/dist/packem_shared/{parseManifest--vZf2FY1.mjs → parseManifest-BBrXCg9V.mjs} +16 -9
  49. package/dist/packem_shared/prompt-cancelled-APzX1Im-.mjs +9 -0
  50. package/dist/packem_shared/runAddCommand-BCcJzs_k.mjs +4 -0
  51. package/dist/packem_shared/storage-bGfgwOgF.mjs +84 -0
  52. package/dist/packem_shared/tui-prompts-BjEN8XgP.mjs +658 -0
  53. package/dist/packem_shared/wrangler-secrets-Dq_Fkbm-.mjs +49 -0
  54. package/package.json +10 -7
  55. package/skills/lunora-quickstart/SKILL.md +25 -5
  56. package/skills/lunora-setup-storage/SKILL.md +7 -3
  57. package/dist/packem_shared/features-ocSSpZtS.mjs +0 -24
  58. package/dist/packem_shared/runAddCommand-G544_v6e.mjs +0 -4
  59. package/dist/packem_shared/tui-prompts-XHFxlOg5.mjs +0 -269
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { CodegenOptions, SchemaIR } from '@lunora/codegen';
2
2
  import '@visulima/cerebro';
3
- import { ensureDevVariables, ensureDevVarsExample, materializeRemoteWranglerConfig } from '@lunora/config';
3
+ import { ensureDevVariables, ensureDevVarsExample, fillDevSecrets, materializeRemoteWranglerConfig } from '@lunora/config';
4
4
  export { REQUIRED_COMPATIBILITY_DATE, REQUIRED_FLAG, type WranglerProjectValidationOptions as WranglerValidationOptions, type WranglerValidationReport, type WranglerProjectValidationResult as WranglerValidationResult, validateWranglerProject as validateWrangler, validateWranglerConfig } from '@lunora/config';
5
5
  /** Every command name the CLI registers (drives the `CommandName` type + tests). */
6
6
  declare const COMMANDS: readonly ["init", "add", "dev", "codegen", "build", "deploy", "containers", "prepare", "link", "deployments", "logs", "run", "insights", "reset", "migrate", "export", "import", "seed", "backup", "verify", "info", "doctor", "env", "analyze", "view", "docs", "registry", "rules"];
@@ -49,6 +49,15 @@ interface PailLogger {
49
49
  success: (message: string) => void;
50
50
  warn: (message: string) => void;
51
51
  }
52
+ /**
53
+ * Minimal reporter shape consumed by `createPail`. We re-declare it locally
54
+ * because `@visulima/pail`'s `reporter/*` entrypoints ship a packaging bug:
55
+ * their `index.d.ts` re-exports `./json-reporter.d.ts` / `./pretty-reporter.d.ts`,
56
+ * but the real declaration files are suffixed (`*.server.d.ts`). `tsc` tolerates
57
+ * the dangling re-export, but the type-aware linter resolves `JsonReporter` /
58
+ * `PrettyReporter` to an unresolved type. Constructing them through this typed
59
+ * factory keeps every call site safe.
60
+ */
52
61
  declare const createLogger: () => Logger;
53
62
  /**
54
63
  * Logger whose every channel writes to `process.stderr`. Used by commands in
@@ -64,6 +73,12 @@ declare const createLogger: () => Logger;
64
73
  * the package barrel) stays side-effect-free.
65
74
  */
66
75
  declare const pail: PailLogger;
76
+ /**
77
+ * Emit a badged step line through the shared pail (the `init` flow's off-TTY
78
+ * fallback for the create-astro-style transcript). The `message` may contain
79
+ * newlines — `LunoraReporter` indents continuation lines under the badge so a
80
+ * dimmed answer sits below its question.
81
+ */
67
82
  interface CodegenCommandOptions {
68
83
  /** Which API spec(s) to emit. Defaults to codegen's `"openapi"` when omitted. */
69
84
  apiSpec?: ApiSpec;
@@ -220,6 +235,35 @@ declare const createRecordingSpawner: (exitCode?: number) => {
220
235
  calls: RecordedSpawn[];
221
236
  spawner: Spawner;
222
237
  };
238
+ interface SecretListRunnerResult {
239
+ code: number;
240
+ stderr: string;
241
+ stdout: string;
242
+ }
243
+ /** Runs an argv and resolves its captured output. Injected in tests. */
244
+ type SecretListRunner = (command: string, args: ReadonlyArray<string>, cwd: string) => Promise<SecretListRunnerResult>;
245
+ interface ListRemoteSecretsInputs {
246
+ cwd: string;
247
+ /** Cloudflare environment name (`--env`). */
248
+ env?: string;
249
+ /** Injected command runner; defaults to a real `wrangler secret list`. */
250
+ runner?: SecretListRunner;
251
+ /** Target a temporary-account deployment (`--temporary`). */
252
+ temporary?: boolean;
253
+ }
254
+ interface ListRemoteSecretsResult {
255
+ /** Diagnostic message when `ok` is false. */
256
+ error?: string;
257
+ /** Remote secret names (sorted), empty when none or on failure. */
258
+ names: ReadonlyArray<string>;
259
+ /** False when wrangler failed or its output could not be parsed. */
260
+ ok: boolean;
261
+ }
262
+ /**
263
+ * Parse `wrangler secret list --format json` output into a sorted name list.
264
+ * The payload is an array of `{ name, type }`; anything else yields `undefined`
265
+ * so the caller can report a parse failure rather than silently returning [].
266
+ */
223
267
  type FetchLike = (input: string, init?: {
224
268
  body?: string;
225
269
  headers?: Record<string, string>;
@@ -312,6 +356,10 @@ interface DeployCommandOptions {
312
356
  preview?: boolean;
313
357
  /** Railpack-availability probe injected in tests. Defaults to a real `railpack --version` + `BUILDKIT_HOST` check. */
314
358
  railpackAvailable?: DockerProbe;
359
+ /** Confirm prompt for the missing-secret offer; injected in tests. Defaults to the TTY prompt. */
360
+ secretConfirm?: (message: string) => Promise<boolean>;
361
+ /** Remote-secret lister for the missing-secret offer; injected in tests. Defaults to `wrangler secret list`. */
362
+ secretLister?: (inputs: ListRemoteSecretsInputs) => Promise<ListRemoteSecretsResult>;
315
363
  skipCodegen?: boolean;
316
364
  spawner?: Spawner;
317
365
  /**
@@ -403,6 +451,16 @@ interface StudioServerHandle {
403
451
  /** The URL to open in a browser. */
404
452
  url: string;
405
453
  }
454
+ /**
455
+ * How the dev child runs. `wrangler` is the classic `lunora dev` stack
456
+ * (wrangler worker + embedded studio + codegen watch). `vite` is a project on
457
+ * `@lunora/vite`: the Vite plugin already runs the worker, studio, and codegen
458
+ * inside the Vite dev server, so `lunora dev` runs the project's own dev
459
+ * script and gets out of the way — that's what makes `--background` / `stop` /
460
+ * `status` / `logs` work uniformly for Vite projects too.
461
+ */
462
+ type DevFlavor = "vite" | "wrangler";
463
+ /** Detect the dev flavor: a declared `@lunora/vite` dependency means Vite owns the dev server. */
406
464
  /** A running worker child the orchestrator controls: send signals, await its exit. */
407
465
  interface WorkerProcess {
408
466
  /** Resolves with the worker's exit code (1 if it failed to start). */
@@ -423,6 +481,14 @@ interface DevCommandOptions {
423
481
  ensureEnv?: typeof ensureDevVariables;
424
482
  /** Injection seam for tests — defaults to the real `.dev.vars.example` package-aware scaffolder. */
425
483
  ensureExample?: typeof ensureDevVarsExample;
484
+ /** Injection seam for tests — defaults to the real empty-secret/admin-token filler. */
485
+ fillSecrets?: typeof fillDevSecrets;
486
+ /** Injection seam for tests — defaults to the real free-port probe ({@link findAvailablePort}). */
487
+ findFreePort?: (preferred: number) => Promise<number>;
488
+ /** Dev flavor override (tests / callers that already detected it) — defaults to {@link detectDevFlavor}. */
489
+ flavor?: DevFlavor;
490
+ /** Injection seam for tests — defaults to the real IPv6-loopback probe ({@link hasIpv6Loopback}). */
491
+ hasIpv6Loopback?: () => boolean;
426
492
  logger: Logger;
427
493
  /** Injection seam for tests — defaults to the real remote-config materializer. */
428
494
  materializeRemote?: typeof materializeRemoteWranglerConfig;
@@ -457,13 +523,31 @@ interface DevRemotePlan {
457
523
  }
458
524
  interface DevCommandPlan {
459
525
  codegenEnabled: boolean;
526
+ /** Which stack the child runs — see {@link DevFlavor}. */
527
+ flavor: DevFlavor;
528
+ /**
529
+ * One-line redirect hint printed when a meta-framework is detected on the
530
+ * wrangler flavor: without `@lunora/vite` in the dependencies the worker
531
+ * still runs *inside* the framework's dev server, so the user should run
532
+ * their framework dev script for the full app. `undefined` for the vite
533
+ * flavor (`lunora dev` already runs the project's dev script there) and
534
+ * for a standalone project. Purely informational: the wrangler spawn runs
535
+ * regardless.
536
+ */
537
+ frameworkHint?: string;
538
+ /**
539
+ * True when `wrangler dev` was given `--ip 127.0.0.1` because the host has no
540
+ * IPv6 loopback (`::1`) — surfaced so the dev loop can note the rebind.
541
+ * Always `false` for the vite flavor (the plugin owns its own bind).
542
+ */
543
+ ipv4LoopbackForced: boolean;
460
544
  /** The remote-binding decision: which D1/KV/R2 bindings hit the deployed worker. */
461
545
  remote: DevRemotePlan;
462
546
  studioEnabled: boolean;
463
547
  studioPort: number;
464
548
  workerOrigin: string;
465
549
  workerPort: number;
466
- /** The single child process `lunora dev` spawns: `wrangler dev`. */
550
+ /** The single child process `lunora dev` spawns: `wrangler dev` (or `vite dev` for the vite flavor). */
467
551
  wrangler: SpawnDescriptor & {
468
552
  tag: string;
469
553
  };
@@ -477,10 +561,11 @@ interface DevCommandPlan {
477
561
  * to remote, the args stay empty and dev runs fully local.
478
562
  */
479
563
  /**
480
- * Plan `lunora dev`: it runs the worker via `wrangler dev` and nothing else as a
481
- * child process. Vite is intentionally NOT spawned — a project may not use Vite,
482
- * and when it does, the `@lunora/vite` plugin already runs the worker inside
483
- * Vite, so the user runs `vite` themselves. Pure + synchronous so it's unit-testable.
564
+ * Plan `lunora dev`. Wrangler flavor: the worker runs via `wrangler dev` and
565
+ * nothing else as a child process. Vite flavor (`@lunora/vite` declared): the
566
+ * plugin already runs the worker inside the Vite dev server, so the one child
567
+ * is the project's own dev script (`vite dev`, `astro dev`, …) and every CLI
568
+ * sibling is disabled. Pure + synchronous so it's unit-testable.
484
569
  */
485
570
  declare const planDevCommand: (options: DevCommandOptions) => DevCommandPlan;
486
571
  /**
@@ -508,16 +593,133 @@ type PackageManagerProbe = (manager: PackageManager) => boolean;
508
593
  /** A registry item a feature can install. */
509
594
  type FeatureItem = "auth" | "auth-auth0" | "auth-clerk" | "mail";
510
595
  /** The auth-provider choices offered for `add auth` / the init auth prompt. Each value is a registry item name. */
511
-
596
+ /** A single file the item scaffolds into the project. */
597
+ interface RegistryFile {
598
+ /** Source path inside the item dir (e.g. `schema.ts`). */
599
+ from: string;
600
+ /** Merge strategy. `create-or-skip` writes whole files; `schema-extension` AST-merges schema.ts. */
601
+ merge: "create-or-skip" | "schema-extension";
602
+ /** Destination relative to the project root (e.g. `lunora/ratelimit/index.ts`). */
603
+ to: string;
604
+ }
605
+ /** A wrangler.jsonc binding addition. `path` is the jsonc key path; `value` the value to set. */
606
+ interface RegistryBinding {
607
+ path: ReadonlyArray<string>;
608
+ value: unknown;
609
+ }
610
+ /**
611
+ * An environment variable an item needs. Scaffolded into `.dev.vars` (Workers'
612
+ * local-secrets file) on add — non-secrets get their `value`; secrets get an
613
+ * empty placeholder and a reminder to run `wrangler secret put` for production.
614
+ */
615
+ interface RegistryEnvVariable {
616
+ /** Human note on what the variable is for. */
617
+ description?: string;
618
+ /** The variable name (e.g. `RESEND_API_KEY`). */
619
+ name: string;
620
+ /** Mark as a secret: never write a value, only a placeholder, and remind about prod. Defaults to `true` when no `value` is given. */
621
+ secret?: boolean;
622
+ /** A default/example value for non-secret vars. */
623
+ value?: string;
624
+ }
625
+ /** The `registry.json` manifest shape. */
626
+ interface RegistryManifest {
627
+ /** wrangler.jsonc additions (best-effort structural edits). */
628
+ bindings?: ReadonlyArray<RegistryBinding>;
629
+ /** npm deps to add to the project package.json (name → version range). */
630
+ deps?: Readonly<Record<string, string>>;
631
+ description?: string;
632
+ /** npm devDependencies to add to the project package.json. */
633
+ devDependencies?: Readonly<Record<string, string>>;
634
+ /** Post-install guidance printed after the item is added (per-item next steps). */
635
+ docs?: string;
636
+ /** Environment variables the item needs; scaffolded into `.dev.vars`. */
637
+ envVars?: ReadonlyArray<RegistryEnvVariable>;
638
+ files: ReadonlyArray<RegistryFile>;
639
+ name: string;
640
+ /** Other registry items this one depends on (resolved transitively, deps first). */
641
+ requires?: ReadonlyArray<string>;
642
+ /** Short human-readable label (distinct from the longer `description`). */
643
+ title?: string;
644
+ }
645
+ interface AddCommandOptions {
646
+ /** Bypass the `--source` safety gate (matches init). */
647
+ allowUnsafeSource?: boolean;
648
+ /** `registry build --check`: verify the index is current instead of rewriting it. */
649
+ check?: boolean;
650
+ /** Inject a confirmer for non-interactive callers / tests. */
651
+ confirm?: (prompt: string) => Promise<boolean>;
652
+ cwd?: string;
653
+ /** Preview the file-level changes (a content diff) and write nothing. */
654
+ diff?: boolean;
655
+ /** Print the plan and stop without writing anything. */
656
+ dryRun?: boolean;
657
+ /** Local registry root (offline / tests). Expects per-item subdirs, each with a `registry.json`. */
658
+ from?: string;
659
+ /** Emit a JSON snapshot of the plan/result. */
660
+ json?: boolean;
661
+ /** `--list`: enumerate available items instead of adding. */
662
+ list?: boolean;
663
+ logger: Logger;
664
+ /** Item names to add (positional args). */
665
+ names: ReadonlyArray<string>;
666
+ /** `registry build` output path for the generated catalog (defaults to the root's `index.json`). */
667
+ out?: string;
668
+ /** Force-overwrite existing files (take the incoming copy) instead of skipping/conflicting. */
669
+ overwrite?: boolean;
670
+ /** Override the git ref (branch, tag, or commit) items are fetched from (default: version-derived); appended to the `source` base when that is set. Ignored when `from` is set. */
671
+ ref?: string;
672
+ /** Override the remote registry source base (default gh:anolilab/lunora/registry). */
673
+ source?: string;
674
+ /**
675
+ * Customize each resolved manifest after it is loaded but before the plan is
676
+ * printed / reconciled — used to inject user-chosen values into otherwise
677
+ * static manifests (e.g. the R2 `bucket_name` the init storage prompt asks
678
+ * for). Applied to every item; return the manifest unchanged to leave it as-is.
679
+ */
680
+ transformManifest?: (manifest: RegistryManifest) => RegistryManifest;
681
+ /** Skip the package.json mutation confirmation prompt. */
682
+ yes?: boolean;
683
+ }
684
+ interface AddCommandResult {
685
+ /** Bindings written to wrangler.jsonc. */
686
+ bindings: ReadonlyArray<string>;
687
+ code: number;
688
+ /** Deps added to package.json. */
689
+ deps: ReadonlyArray<string>;
690
+ /** Files skipped because they already existed. */
691
+ skipped: ReadonlyArray<string>;
692
+ /** Files written (absolute paths). */
693
+ written: ReadonlyArray<string>;
694
+ }
695
+ /** One resolved item: its parsed manifest plus the (possibly staged) directory it lives in. */
512
696
  /**
513
697
  * A feature offered in the post-scaffold multi-select. `auth`/`email` carry a
514
698
  * sub-prompt or alias; every other value IS the registry item name applied
515
699
  * directly (`storage` → the `storage` registry item, etc.).
516
700
  */
517
701
  type StackFeature = "auth" | "backup" | "crons" | "email" | "presence" | "ratelimit" | "storage";
702
+ /** Customize a resolved manifest before it is written (e.g. inject the chosen R2 bucket name). */
703
+ type OfferTransformManifest = (manifest: RegistryManifest) => RegistryManifest;
704
+ /**
705
+ * One feature ready to apply: the registry item name(s), an optional manifest
706
+ * transform, and a short `label` (the feature value) shown on the combined
707
+ * progress line. Built up-front by the collectors so every prompt is answered
708
+ * before any apply runs.
709
+ */
710
+ interface FeatureApply {
711
+ label: string;
712
+ names: ReadonlyArray<string>;
713
+ transformManifest?: OfferTransformManifest;
714
+ }
518
715
  interface OfferDeps {
519
- /** Apply one or more registry items into the new project; resolves `true` on success. */
520
- apply: (names: ReadonlyArray<string>) => Promise<boolean>;
716
+ /**
717
+ * Apply the collected features into the new project in one batch — resolves
718
+ * `true` when every item succeeds. The CLI renders this as a single progress
719
+ * line whose label changes per feature; each plan's `transformManifest`
720
+ * customizes that item's manifest before it is written.
721
+ */
722
+ applyAll: (plans: ReadonlyArray<FeatureApply>) => Promise<boolean>;
521
723
  /** When `false`, skip all prompts and print the later-setup hint. */
522
724
  interactive: boolean;
523
725
  logger: Logger;
@@ -529,6 +731,14 @@ interface OfferDeps {
529
731
  }>, settings?: {
530
732
  defaults?: ReadonlyArray<StackFeature>;
531
733
  }) => Promise<StackFeature[]>;
734
+ /**
735
+ * Features chosen non-interactively (the `--add` flag). When set, the
736
+ * multi-select and every sub-prompt are skipped — each feature is applied with
737
+ * its shipped defaults (base registry item, placeholder bindings).
738
+ */
739
+ preselected?: ReadonlyArray<StackFeature>;
740
+ /** The new project's name — seeds smart defaults like the `project-uploads` bucket name. */
741
+ projectName: string;
532
742
  /** Single-select among the auth providers (TTY-backed in production). */
533
743
  select: (message: string, options: ReadonlyArray<{
534
744
  description?: string;
@@ -537,17 +747,32 @@ interface OfferDeps {
537
747
  }>, settings?: {
538
748
  default?: FeatureItem;
539
749
  }) => Promise<FeatureItem | undefined>;
750
+ /** Single-line text input (TTY-backed in production) — used for the storage bucket-name prompt. */
751
+ text: (message: string, settings?: {
752
+ default?: string;
753
+ placeholder?: string;
754
+ }) => Promise<string>;
540
755
  }
541
756
  /**
542
757
  * Offer the stack features (auth, email, storage, rate limiting, crons,
543
- * presence, backups) in ONE multi-select after a successful scaffold. When auth
544
- * is picked, a follow-up single-select chooses the provider (email+password /
545
- * Clerk / Auth0); email maps to the `mail` item; every other feature value is
546
- * applied as its registry item directly. Picked items are applied in selection
547
- * order. Non-interactive: prints how to add them later and changes nothing.
758
+ * presence, backups) in ONE multi-select after a successful scaffold. Auth,
759
+ * email, and storage run a follow-up prompt (provider / destination / bucket
760
+ * name); every other feature value is applied as its registry item directly.
761
+ *
762
+ * Every question is asked FIRST (in selection order), then the picked features
763
+ * are applied together via {@link OfferDeps.applyAll} — the CLI renders that as a
764
+ * single progress line whose label changes per feature, instead of one spinner
765
+ * per item. Non-interactive: prints how to add them later and changes nothing.
548
766
  */
549
767
  type Template = "analog" | "astro" | "next" | "nuxt" | "react-router" | "standalone" | "sveltekit" | "tanstack-start-react" | "tanstack-start-solid";
550
768
  interface InitCommandOptions {
769
+ /**
770
+ * Add features non-interactively after scaffolding (the `--add` flag): a
771
+ * comma-separated list of `auth | email | storage | ratelimit | crons |
772
+ * presence | backup`. Bypasses the interactive multi-select and sub-prompts —
773
+ * each named feature is applied with its shipped defaults.
774
+ */
775
+ add?: string;
551
776
  /**
552
777
  * When true, accept `--source` values that don't start with `gh:` /
553
778
  * `github:` / `https://` or that contain `..`. Defaults to false; the CLI
@@ -559,6 +784,12 @@ interface InitCommandOptions {
559
784
  ci?: CiProvider;
560
785
  cwd?: string;
561
786
  /**
787
+ * Walk the whole flow — prompts, task list, next-steps, mascot — but make no
788
+ * changes: skip the template fetch/copy, the feature applies, the dependency
789
+ * install, and `git init`. Each skipped action logs a `would …` line instead.
790
+ */
791
+ dryRun?: boolean;
792
+ /**
562
793
  * Local directory containing the template subdirs (e.g. `vite/`,
563
794
  * `standalone/`). When provided, skips the network fetch entirely.
564
795
  * Useful for offline runs, the clean-machine smoke test, and unit tests.
@@ -599,10 +830,10 @@ interface InitCommandOptions {
599
830
  packageManagerProbe?: PackageManagerProbe;
600
831
  /**
601
832
  * Inject the offer's prompts (tests). When set, the offer is treated as
602
- * interactive regardless of TTY, and these drive the feature multi-select
603
- * and the auth-provider sub-select.
833
+ * interactive regardless of TTY, and these drive the feature multi-select,
834
+ * the auth-provider sub-select, and the storage bucket-name text input.
604
835
  */
605
- prompt?: Pick<OfferDeps, "multiSelect" | "select">;
836
+ prompt?: Pick<OfferDeps, "multiSelect" | "select" | "text">;
606
837
  /**
607
838
  * Override the git ref (branch, tag, or commit) the default template source
608
839
  * is fetched from. Takes precedence over the version-derived ref. Ignored
@@ -639,11 +870,6 @@ interface InitCommandResult {
639
870
  files: ReadonlyArray<string>;
640
871
  target: string;
641
872
  }
642
- /**
643
- * `lunora init` entry: scaffold (in-place or a new directory), then — on success
644
- * — offer to add auth + email via the registry. The offer never affects the
645
- * scaffold's exit code.
646
- */
647
873
  declare const runInitCommand: (options: InitCommandOptions) => Promise<InitCommandResult>;
648
874
  /** Narrow a raw `--template` value to a known {@link Template}. */
649
875
  interface MigrateGenerateCommandOptions {
@@ -681,99 +907,6 @@ interface IndexItem extends CatalogItem {
681
907
  declare const buildRegistryIndex: (root: string) => {
682
908
  items: IndexItem[];
683
909
  };
684
- /** A single file the item scaffolds into the project. */
685
- interface RegistryFile {
686
- /** Source path inside the item dir (e.g. `schema.ts`). */
687
- from: string;
688
- /** Merge strategy. `create-or-skip` writes whole files; `schema-extension` AST-merges schema.ts. */
689
- merge: "create-or-skip" | "schema-extension";
690
- /** Destination relative to the project root (e.g. `lunora/ratelimit/index.ts`). */
691
- to: string;
692
- }
693
- /** A wrangler.jsonc binding addition. `path` is the jsonc key path; `value` the value to set. */
694
- interface RegistryBinding {
695
- path: ReadonlyArray<string>;
696
- value: unknown;
697
- }
698
- /**
699
- * An environment variable an item needs. Scaffolded into `.dev.vars` (Workers'
700
- * local-secrets file) on add — non-secrets get their `value`; secrets get an
701
- * empty placeholder and a reminder to run `wrangler secret put` for production.
702
- */
703
- interface RegistryEnvVariable {
704
- /** Human note on what the variable is for. */
705
- description?: string;
706
- /** The variable name (e.g. `RESEND_API_KEY`). */
707
- name: string;
708
- /** Mark as a secret: never write a value, only a placeholder, and remind about prod. Defaults to `true` when no `value` is given. */
709
- secret?: boolean;
710
- /** A default/example value for non-secret vars. */
711
- value?: string;
712
- }
713
- /** The `registry.json` manifest shape. */
714
- interface RegistryManifest {
715
- /** wrangler.jsonc additions (best-effort structural edits). */
716
- bindings?: ReadonlyArray<RegistryBinding>;
717
- /** npm deps to add to the project package.json (name → version range). */
718
- deps?: Readonly<Record<string, string>>;
719
- description?: string;
720
- /** npm devDependencies to add to the project package.json. */
721
- devDependencies?: Readonly<Record<string, string>>;
722
- /** Post-install guidance printed after the item is added (per-item next steps). */
723
- docs?: string;
724
- /** Environment variables the item needs; scaffolded into `.dev.vars`. */
725
- envVars?: ReadonlyArray<RegistryEnvVariable>;
726
- files: ReadonlyArray<RegistryFile>;
727
- name: string;
728
- /** Other registry items this one depends on (resolved transitively, deps first). */
729
- requires?: ReadonlyArray<string>;
730
- /** Short human-readable label (distinct from the longer `description`). */
731
- title?: string;
732
- }
733
- interface AddCommandOptions {
734
- /** Bypass the `--source` safety gate (matches init). */
735
- allowUnsafeSource?: boolean;
736
- /** `registry build --check`: verify the index is current instead of rewriting it. */
737
- check?: boolean;
738
- /** Inject a confirmer for non-interactive callers / tests. */
739
- confirm?: (prompt: string) => Promise<boolean>;
740
- cwd?: string;
741
- /** Preview the file-level changes (a content diff) and write nothing. */
742
- diff?: boolean;
743
- /** Print the plan and stop without writing anything. */
744
- dryRun?: boolean;
745
- /** Local registry root (offline / tests). Expects per-item subdirs, each with a `registry.json`. */
746
- from?: string;
747
- /** Emit a JSON snapshot of the plan/result. */
748
- json?: boolean;
749
- /** `--list`: enumerate available items instead of adding. */
750
- list?: boolean;
751
- logger: Logger;
752
- /** Item names to add (positional args). */
753
- names: ReadonlyArray<string>;
754
- /** `registry build` output path for the generated catalog (defaults to the root's `index.json`). */
755
- out?: string;
756
- /** Force-overwrite existing files (take the incoming copy) instead of skipping/conflicting. */
757
- overwrite?: boolean;
758
- /** Override the git ref (branch, tag, or commit) items are fetched from (default: version-derived); appended to the `source` base when that is set. Ignored when `from` is set. */
759
- ref?: string;
760
- /** Override the remote registry source base (default gh:anolilab/lunora/registry). */
761
- source?: string;
762
- /** Skip the package.json mutation confirmation prompt. */
763
- yes?: boolean;
764
- }
765
- interface AddCommandResult {
766
- /** Bindings written to wrangler.jsonc. */
767
- bindings: ReadonlyArray<string>;
768
- code: number;
769
- /** Deps added to package.json. */
770
- deps: ReadonlyArray<string>;
771
- /** Files skipped because they already existed. */
772
- skipped: ReadonlyArray<string>;
773
- /** Files written (absolute paths). */
774
- written: ReadonlyArray<string>;
775
- }
776
- /** One resolved item: its parsed manifest plus the (possibly staged) directory it lives in. */
777
910
  /** `lunora registry add` (one or more item names): scaffold items into the project. */
778
911
  declare const runAddCommand: (options: AddCommandOptions) => Promise<AddCommandResult>;
779
912
  /**
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- export { COMMANDS, VERSION, runCli } from './packem_shared/COMMANDS-Bn8luojF.mjs';
1
+ export { COMMANDS, VERSION, runCli } from './packem_shared/COMMANDS-0BD3K1pb.mjs';
2
2
  export { runCodegenCommand } from './packem_chunks/runCodegenCommand.mjs';
3
- export { DEFAULT_IMPORT_BATCH_SIZE, runExportCommand, runImportCommand } from './packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs';
3
+ export { DEFAULT_IMPORT_BATCH_SIZE, runExportCommand, runImportCommand } from './packem_shared/DEFAULT_IMPORT_BATCH_SIZE-CRQmmBZM.mjs';
4
4
  export { runDeployCommand } from './packem_chunks/runDeployCommand.mjs';
5
5
  export { planDevCommand, runDevCommand } from './packem_chunks/planDevCommand.mjs';
6
6
  export { runInitCommand } from './packem_chunks/runInitCommand.mjs';
@@ -8,12 +8,12 @@ export { runMigrateGenerateCommand } from './packem_chunks/runMigrateGenerateCom
8
8
  export { runResetCommand } from './packem_chunks/runResetCommand.mjs';
9
9
  export { runRpcCommand } from './packem_chunks/runRpcCommand.mjs';
10
10
  export { default as parseArgs } from './packem_shared/parseArgs-YXFuKdEk.mjs';
11
- export { insertSchemaExtension } from './packem_shared/insertSchemaExtension-BuzF6-t2.mjs';
12
- export { createLogger, pail } from './packem_shared/createLogger-CHPNjFw2.mjs';
11
+ export { insertSchemaExtension } from './packem_shared/insertSchemaExtension-DAqbfr9Z.mjs';
12
+ export { createLogger, pail } from './packem_shared/createLogger-CIWSHrTL.mjs';
13
13
  export { diffSnapshots, renderAddColumn, renderCreateIndex, renderCreateTable, renderDropIndex, renderDropTable, renderMigrationFile, validatorKindToSqlType } from './packem_shared/diffSnapshots-BeDvvNiF.mjs';
14
14
  export { default as schemaIrToSnapshot } from './packem_shared/schemaIrToSnapshot-DdsljJT-.mjs';
15
- export { createRecordingSpawner, defaultSpawner } from './packem_shared/createRecordingSpawner-DxI3mebw.mjs';
16
- export { default as parseManifest } from './packem_shared/parseManifest--vZf2FY1.mjs';
15
+ export { createRecordingSpawner, defaultSpawner } from './packem_shared/createRecordingSpawner-Cw5Iu73G.mjs';
16
+ export { default as parseManifest } from './packem_shared/parseManifest-BBrXCg9V.mjs';
17
17
  export { REQUIRED_COMPATIBILITY_DATE, REQUIRED_FLAG, validateWranglerProject as validateWrangler, validateWranglerConfig } from '@lunora/config';
18
- export { buildRegistryIndex } from './packem_shared/buildRegistryIndex-BcYe607_.mjs';
19
- export { r as runAddCommand, a as runBuildIndexCommand, b as runRegistryViewCommand } from './packem_shared/commands-DqsEzojt.mjs';
18
+ export { buildRegistryIndex } from './packem_shared/buildRegistryIndex-CqM5FwGI.mjs';
19
+ export { r as runAddCommand, a as runBuildIndexCommand, b as runRegistryViewCommand } from './packem_shared/commands-vnRRkhNE.mjs';
@@ -1,10 +1,11 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { findWranglerFile } from '@lunora/config';
3
- import { join } from '@visulima/path';
4
- import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
5
- import { t as tuiSelect } from '../packem_shared/tui-prompts-XHFxlOg5.mjs';
6
- import { n as normalizeFeature, E as EMAIL_ITEM, D as DEFAULT_AUTH_ITEM, p as promptAuthProvider, A as AUTH_PROVIDER_OPTIONS } from '../packem_shared/features-ocSSpZtS.mjs';
7
- import { r as runAddCommand } from '../packem_shared/commands-DqsEzojt.mjs';
3
+ import { join, basename } from '@visulima/path';
4
+ import { d as defineHandler } from '../packem_shared/command-lYnl4QyF.mjs';
5
+ import { v as validateOutputFormat, i as isJsonFormat, p as printJson, l as loggerForFormat } from '../packem_shared/output-format-B4642rjE.mjs';
6
+ import { t as tuiText, a as tuiSelect } from '../packem_shared/tui-prompts-BjEN8XgP.mjs';
7
+ import { n as normalizeFeature, E as EMAIL_ITEM, s as sanitizeBucketName, d as deriveBucketName, p as promptBucketName, r as resolveTypedDestination, M as MAIL_DESTINATION_PROMPT, a as sanitizeDatabaseName, b as deriveDatabaseName, c as promptDatabaseName, D as DEFAULT_AUTH_ITEM, e as promptAuthProvider, A as AUTH_PROVIDER_OPTIONS, w as withStorageBucketName, f as withMailDestination, g as withAuthDatabaseName } from '../packem_shared/storage-bGfgwOgF.mjs';
8
+ import { r as runAddCommand } from '../packem_shared/commands-vnRRkhNE.mjs';
8
9
 
9
10
  const providerToItem = (provider) => {
10
11
  const value = provider.trim().toLowerCase();
@@ -28,6 +29,51 @@ const resolveAuthItem = async (options) => {
28
29
  const select = options.promptSelect ?? ((message, choices, settings) => tuiSelect(message, choices, settings));
29
30
  return promptAuthProvider(select);
30
31
  };
32
+ const textPrompt = (options) => options.promptText ?? ((message, settings) => tuiText(message, settings));
33
+ const resolveStorageBucketName = async (options) => {
34
+ const projectName = basename(options.cwd ?? process.cwd());
35
+ if (options.bucket !== void 0 && options.bucket !== "") {
36
+ const sanitized = sanitizeBucketName(options.bucket);
37
+ if (sanitized !== void 0) {
38
+ return sanitized;
39
+ }
40
+ const fallback = deriveBucketName(projectName);
41
+ options.logger.warn(`add: "${options.bucket}" isn't a valid R2 bucket name (lowercase alphanumeric + hyphens, 3–63 chars) — using "${fallback}".`);
42
+ return fallback;
43
+ }
44
+ if (options.yes === true) {
45
+ return deriveBucketName(projectName);
46
+ }
47
+ return promptBucketName(textPrompt(options), projectName);
48
+ };
49
+ const resolveMailDestination = async (options) => {
50
+ const warn = (message) => {
51
+ options.logger.warn(`add: ${message}`);
52
+ };
53
+ if (options.mailTo !== void 0 && options.mailTo !== "") {
54
+ return resolveTypedDestination(options.mailTo, warn);
55
+ }
56
+ if (options.yes === true) {
57
+ return void 0;
58
+ }
59
+ return resolveTypedDestination(await textPrompt(options)(MAIL_DESTINATION_PROMPT, { placeholder: "you@yourdomain.com" }), warn);
60
+ };
61
+ const resolveAuthDatabaseName = async (options) => {
62
+ const projectName = basename(options.cwd ?? process.cwd());
63
+ if (options.db !== void 0 && options.db !== "") {
64
+ const sanitized = sanitizeDatabaseName(options.db);
65
+ if (sanitized !== void 0) {
66
+ return sanitized;
67
+ }
68
+ const fallback = deriveDatabaseName(projectName);
69
+ options.logger.warn(`add: "${options.db}" isn't a usable D1 database name — using "${fallback}".`);
70
+ return fallback;
71
+ }
72
+ if (options.yes === true) {
73
+ return deriveDatabaseName(projectName);
74
+ }
75
+ return promptDatabaseName(textPrompt(options), projectName);
76
+ };
31
77
  const resolveFeatureItems = async (feature, options) => {
32
78
  if (feature.kind === "auth") {
33
79
  return [await resolveAuthItem(options)];
@@ -49,6 +95,28 @@ const runAddFeature = async (options) => {
49
95
  return { code: 1, items: [] };
50
96
  }
51
97
  const items = await resolveFeatureItems(feature, options);
98
+ const transforms = [];
99
+ if (items.includes("storage")) {
100
+ const bucketName = await resolveStorageBucketName(options);
101
+ transforms.push((manifest) => withStorageBucketName(manifest, bucketName));
102
+ }
103
+ if (items.includes("mail")) {
104
+ const destination = await resolveMailDestination(options);
105
+ if (destination !== void 0) {
106
+ transforms.push((manifest) => withMailDestination(manifest, destination));
107
+ }
108
+ }
109
+ if (items.some((name) => name === "auth" || name.startsWith("auth-"))) {
110
+ const databaseName = await resolveAuthDatabaseName(options);
111
+ transforms.push((manifest) => withAuthDatabaseName(manifest, databaseName));
112
+ }
113
+ const transformManifest = transforms.length > 0 ? (manifest) => {
114
+ let result2 = manifest;
115
+ for (const transform of transforms) {
116
+ result2 = transform(result2);
117
+ }
118
+ return result2;
119
+ } : void 0;
52
120
  const result = await runAddCommand({
53
121
  allowUnsafeSource: options.allowUnsafeSource,
54
122
  cwd,
@@ -57,22 +125,35 @@ const runAddFeature = async (options) => {
57
125
  names: [...items],
58
126
  ref: options.ref,
59
127
  source: options.source,
128
+ transformManifest,
60
129
  yes: true
61
130
  });
62
131
  return { code: result.code, items };
63
132
  };
64
133
  const execute = defineHandler(async ({ argument, cwd, logger, options }) => {
134
+ const formatError = validateOutputFormat("add", options.format);
135
+ if (formatError !== void 0) {
136
+ logger.error(formatError);
137
+ return { code: 1 };
138
+ }
139
+ const effectiveLogger = loggerForFormat(options.format, logger);
65
140
  const result = await runAddFeature({
66
141
  allowUnsafeSource: options.allowUnsafeSource === true,
142
+ bucket: options.bucket,
67
143
  cwd,
144
+ db: options.db,
68
145
  feature: argument[0],
69
146
  from: options.from,
70
- logger,
147
+ logger: effectiveLogger,
148
+ mailTo: options.mailTo,
71
149
  provider: options.provider,
72
150
  ref: options.ref,
73
151
  source: options.source,
74
152
  yes: options.yes === true
75
153
  });
154
+ if (isJsonFormat(options.format)) {
155
+ printJson({ code: result.code, items: result.items });
156
+ }
76
157
  return { code: result.code };
77
158
  });
78
159