@sdxc/kit 0.0.0-stage → 2026.10.16

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 (248) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +92 -2
  3. package/changelog.jsonl +1040 -0
  4. package/config.schema.json +89 -0
  5. package/dist/bin.d.ts +9 -0
  6. package/dist/bin.js +10 -0
  7. package/dist/cli.d.ts +33 -0
  8. package/dist/cli.js +58 -0
  9. package/dist/commands/create.d.ts +20 -0
  10. package/dist/commands/create.js +164 -0
  11. package/dist/commands/init.d.ts +16 -0
  12. package/dist/commands/init.js +27 -0
  13. package/dist/commands/make.d.ts +335 -0
  14. package/dist/commands/make.js +152 -0
  15. package/dist/commands/run.d.ts +23 -0
  16. package/dist/commands/run.js +51 -0
  17. package/dist/commands/ui/add.d.ts +23 -0
  18. package/dist/commands/ui/add.js +50 -0
  19. package/dist/commands/ui/diff.d.ts +20 -0
  20. package/dist/commands/ui/diff.js +28 -0
  21. package/dist/commands/ui/list.d.ts +24 -0
  22. package/dist/commands/ui/list.js +45 -0
  23. package/dist/commands/ui/remove.d.ts +22 -0
  24. package/dist/commands/ui/remove.js +48 -0
  25. package/dist/commands/ui/update.d.ts +23 -0
  26. package/dist/commands/ui/update.js +37 -0
  27. package/dist/commands/upgrade.d.ts +30 -0
  28. package/dist/commands/upgrade.js +184 -0
  29. package/dist/config.d.ts +81 -0
  30. package/dist/config.js +157 -0
  31. package/dist/contract.d.ts +161 -0
  32. package/dist/contract.js +308 -0
  33. package/dist/create/github.d.ts +63 -0
  34. package/dist/create/github.js +172 -0
  35. package/dist/create/target.d.ts +31 -0
  36. package/dist/create/target.js +56 -0
  37. package/dist/create/templates.d.ts +62 -0
  38. package/dist/create/templates.js +228 -0
  39. package/dist/dependencies.d.ts +34 -0
  40. package/dist/dependencies.js +76 -0
  41. package/dist/diff.d.ts +14 -0
  42. package/dist/diff.js +103 -0
  43. package/dist/format.d.ts +21 -0
  44. package/dist/format.js +40 -0
  45. package/dist/init.d.ts +38 -0
  46. package/dist/init.js +92 -0
  47. package/dist/lock.d.ts +74 -0
  48. package/dist/lock.js +214 -0
  49. package/dist/make/declare.d.ts +54 -0
  50. package/dist/make/declare.js +495 -0
  51. package/dist/make/generate.d.ts +62 -0
  52. package/dist/make/generate.js +154 -0
  53. package/dist/make/imports.d.ts +43 -0
  54. package/dist/make/imports.js +105 -0
  55. package/dist/make/index.d.ts +43 -0
  56. package/dist/make/index.js +136 -0
  57. package/dist/make/kinds.d.ts +39 -0
  58. package/dist/make/kinds.js +95 -0
  59. package/dist/make/migrations.d.ts +41 -0
  60. package/dist/make/migrations.js +116 -0
  61. package/dist/make/names.d.ts +31 -0
  62. package/dist/make/names.js +47 -0
  63. package/dist/make/stubs.d.ts +44 -0
  64. package/dist/make/stubs.js +89 -0
  65. package/dist/middleware.d.ts +44 -0
  66. package/dist/middleware.js +49 -0
  67. package/dist/package-manager.d.ts +41 -0
  68. package/dist/package-manager.js +80 -0
  69. package/dist/project.d.ts +19 -0
  70. package/dist/project.js +42 -0
  71. package/dist/releases.d.ts +40 -0
  72. package/dist/releases.js +110 -0
  73. package/dist/testing.d.ts +50 -0
  74. package/dist/testing.js +129 -0
  75. package/dist/ui/commands.d.ts +114 -0
  76. package/dist/ui/commands.js +432 -0
  77. package/dist/ui/imports.d.ts +46 -0
  78. package/dist/ui/imports.js +160 -0
  79. package/dist/ui/layout.d.ts +48 -0
  80. package/dist/ui/layout.js +138 -0
  81. package/dist/ui/registry.d.ts +58 -0
  82. package/dist/ui/registry.js +82 -0
  83. package/dist/upgrade/changelog.d.ts +50 -0
  84. package/dist/upgrade/changelog.js +69 -0
  85. package/dist/upgrade/project.d.ts +62 -0
  86. package/dist/upgrade/project.js +132 -0
  87. package/dist/upgrade/prompt.d.ts +51 -0
  88. package/dist/upgrade/prompt.js +227 -0
  89. package/dist/upgrade/registry.d.ts +33 -0
  90. package/dist/upgrade/registry.js +50 -0
  91. package/lock.schema.json +60 -0
  92. package/package.json +44 -5
  93. package/registry/ui/accordion.json +15 -0
  94. package/registry/ui/alert-dialog.json +20 -0
  95. package/registry/ui/alert.json +15 -0
  96. package/registry/ui/aspect-ratio.json +13 -0
  97. package/registry/ui/attachment.json +15 -0
  98. package/registry/ui/avatar.json +15 -0
  99. package/registry/ui/badge.json +13 -0
  100. package/registry/ui/breadcrumbs.json +15 -0
  101. package/registry/ui/bubble.json +13 -0
  102. package/registry/ui/button.json +16 -0
  103. package/registry/ui/calendar.json +16 -0
  104. package/registry/ui/card.json +18 -0
  105. package/registry/ui/carousel.json +15 -0
  106. package/registry/ui/chart.json +13 -0
  107. package/registry/ui/checkbox-group.json +13 -0
  108. package/registry/ui/checkbox.json +16 -0
  109. package/registry/ui/color-area.json +13 -0
  110. package/registry/ui/color-field.json +20 -0
  111. package/registry/ui/color-picker.json +17 -0
  112. package/registry/ui/color-slider.json +13 -0
  113. package/registry/ui/color-swatch-picker.json +15 -0
  114. package/registry/ui/color-swatch.json +13 -0
  115. package/registry/ui/color-wheel.json +13 -0
  116. package/registry/ui/combobox.json +15 -0
  117. package/registry/ui/command.json +13 -0
  118. package/registry/ui/confirm.json +19 -0
  119. package/registry/ui/context-menu.json +16 -0
  120. package/registry/ui/date-field.json +19 -0
  121. package/registry/ui/date-picker.json +15 -0
  122. package/registry/ui/date-range-picker.json +16 -0
  123. package/registry/ui/description.json +13 -0
  124. package/registry/ui/dialog.json +19 -0
  125. package/registry/ui/disclosure.json +18 -0
  126. package/registry/ui/drawer.json +18 -0
  127. package/registry/ui/drop-indicator.json +13 -0
  128. package/registry/ui/drop-zone.json +13 -0
  129. package/registry/ui/empty.json +15 -0
  130. package/registry/ui/field-error.json +13 -0
  131. package/registry/ui/file-trigger.json +13 -0
  132. package/registry/ui/form.json +21 -0
  133. package/registry/ui/grid-list.json +18 -0
  134. package/registry/ui/group.json +13 -0
  135. package/registry/ui/header.json +13 -0
  136. package/registry/ui/heading-scope.json +20 -0
  137. package/registry/ui/heading.json +15 -0
  138. package/registry/ui/highlight.json +16 -0
  139. package/registry/ui/hover-card.json +13 -0
  140. package/registry/ui/image-placeholder.json +16 -0
  141. package/registry/ui/input.json +13 -0
  142. package/registry/ui/item.json +13 -0
  143. package/registry/ui/keyboard.json +13 -0
  144. package/registry/ui/label.json +13 -0
  145. package/registry/ui/link-button.json +16 -0
  146. package/registry/ui/link.json +13 -0
  147. package/registry/ui/listbox.json +15 -0
  148. package/registry/ui/logo.json +15 -0
  149. package/registry/ui/marker.json +13 -0
  150. package/registry/ui/menu.json +19 -0
  151. package/registry/ui/menubar.json +13 -0
  152. package/registry/ui/message-scroller.json +16 -0
  153. package/registry/ui/message.json +13 -0
  154. package/registry/ui/meter.json +13 -0
  155. package/registry/ui/modal.json +15 -0
  156. package/registry/ui/nav-link.json +13 -0
  157. package/registry/ui/navigation-menu.json +15 -0
  158. package/registry/ui/number-field.json +15 -0
  159. package/registry/ui/otp-field.json +15 -0
  160. package/registry/ui/overlay-arrow.json +13 -0
  161. package/registry/ui/pagination.json +16 -0
  162. package/registry/ui/popover.json +13 -0
  163. package/registry/ui/progress-bar.json +13 -0
  164. package/registry/ui/radio-group.json +13 -0
  165. package/registry/ui/range-calendar.json +16 -0
  166. package/registry/ui/resizable.json +13 -0
  167. package/registry/ui/scroll-area.json +13 -0
  168. package/registry/ui/search-field.json +16 -0
  169. package/registry/ui/section.json +13 -0
  170. package/registry/ui/select.json +13 -0
  171. package/registry/ui/selection-indicator.json +13 -0
  172. package/registry/ui/sentinel-row.json +16 -0
  173. package/registry/ui/separator.json +13 -0
  174. package/registry/ui/shared-element.json +13 -0
  175. package/registry/ui/sheet.json +15 -0
  176. package/registry/ui/shortcut-list.json +18 -0
  177. package/registry/ui/sidebar.json +20 -0
  178. package/registry/ui/skeleton.json +13 -0
  179. package/registry/ui/slider.json +16 -0
  180. package/registry/ui/spinner.json +13 -0
  181. package/registry/ui/switch.json +16 -0
  182. package/registry/ui/table.json +16 -0
  183. package/registry/ui/tabs.json +17 -0
  184. package/registry/ui/tag-group.json +18 -0
  185. package/registry/ui/text-field.json +19 -0
  186. package/registry/ui/text.json +13 -0
  187. package/registry/ui/textarea.json +13 -0
  188. package/registry/ui/time-field.json +19 -0
  189. package/registry/ui/toast.json +16 -0
  190. package/registry/ui/toggle-button.json +17 -0
  191. package/registry/ui/toolbar.json +13 -0
  192. package/registry/ui/tooltip.json +16 -0
  193. package/registry/ui/tree.json +18 -0
  194. package/registry/ui/typeset.json +16 -0
  195. package/registry/ui/youtube-embed.json +16 -0
  196. package/stubs/command.stub +12 -0
  197. package/stubs/command.test.stub +18 -0
  198. package/stubs/controller.form.stub +33 -0
  199. package/stubs/controller.stub +17 -0
  200. package/stubs/controller.test.stub +15 -0
  201. package/stubs/email.stub +44 -0
  202. package/stubs/email.test.stub +16 -0
  203. package/stubs/factory.stub +10 -0
  204. package/stubs/initializer.stub +7 -0
  205. package/stubs/initializer.test.stub +13 -0
  206. package/stubs/job.cron.stub +12 -0
  207. package/stubs/job.stub +11 -0
  208. package/stubs/job.test.stub +15 -0
  209. package/stubs/mcp.resource.stub +12 -0
  210. package/stubs/mcp.stub +10 -0
  211. package/stubs/mcp.test.stub +15 -0
  212. package/stubs/middleware.stub +11 -0
  213. package/stubs/middleware.test.stub +13 -0
  214. package/stubs/migration.stub +1 -0
  215. package/stubs/model.stub +24 -0
  216. package/stubs/model.test.stub +15 -0
  217. package/stubs/policy.stub +13 -0
  218. package/stubs/policy.test.stub +17 -0
  219. package/stubs/service.stub +13 -0
  220. package/stubs/service.test.stub +14 -0
  221. package/stubs/validator.stub +14 -0
  222. package/stubs/validator.test.stub +22 -0
  223. package/templates/app/README.md +57 -0
  224. package/templates/app/app/commands/about.test.ts +29 -0
  225. package/templates/app/app/commands/about.ts +34 -0
  226. package/templates/app/app/commands/index.ts +15 -0
  227. package/templates/app/app/http/controllers/home.tsx +22 -0
  228. package/templates/app/app/http/controllers/not-found.tsx +25 -0
  229. package/templates/app/app/initializers/assets.ts +11 -0
  230. package/templates/app/app/initializers/cli.ts +35 -0
  231. package/templates/app/app/initializers/dispatcher.ts +18 -0
  232. package/templates/app/app/initializers/logger.ts +10 -0
  233. package/templates/app/app/initializers/mcp.ts +16 -0
  234. package/templates/app/app/initializers/router.tsx +65 -0
  235. package/templates/app/app/jobs/index.ts +10 -0
  236. package/templates/app/app/mcp/resources/index.ts +9 -0
  237. package/templates/app/app/mcp/tools/index.ts +10 -0
  238. package/templates/app/bootstrap/browser.ts +27 -0
  239. package/templates/app/bootstrap/cli.ts +9 -0
  240. package/templates/app/bootstrap/worker.ts +31 -0
  241. package/templates/app/cloudflare.config.ts +28 -0
  242. package/templates/app/config/router-context.d.ts +20 -0
  243. package/templates/app/gitignore +9 -0
  244. package/templates/app/package.json +38 -0
  245. package/templates/app/resources/layouts/document.tsx +58 -0
  246. package/templates/app/routes/web.ts +12 -0
  247. package/templates/app/tsconfig.json +40 -0
  248. package/templates/app/vite.config.ts +40 -0
@@ -0,0 +1,89 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "type": "object",
4
+ "properties": {
5
+ "$schema": {
6
+ "type": "string",
7
+ "description": "The JSON Schema editors check this file against"
8
+ },
9
+ "ui": {
10
+ "type": "object",
11
+ "properties": {
12
+ "directory": {
13
+ "type": "string",
14
+ "default": "resources/components/ui",
15
+ "description": "Where `sdxc ui add` writes components"
16
+ },
17
+ "alias": {
18
+ "type": "string",
19
+ "description": "Import prefix for the copies; inferred from tsconfig `paths` when omitted",
20
+ "examples": ["~/components/ui"]
21
+ },
22
+ "tests": {
23
+ "type": "boolean",
24
+ "default": false,
25
+ "description": "Copy a component's tests beside it"
26
+ }
27
+ },
28
+ "additionalProperties": false,
29
+ "default": {
30
+ "directory": "resources/components/ui",
31
+ "tests": false
32
+ }
33
+ },
34
+ "make": {
35
+ "type": "object",
36
+ "properties": {
37
+ "routes": {
38
+ "type": "string",
39
+ "default": "web",
40
+ "description": "Route contract `sdxc make controller` adds to, a module in routes/"
41
+ },
42
+ "migrations": {
43
+ "type": "object",
44
+ "additionalProperties": {
45
+ "type": "string"
46
+ },
47
+ "default": {
48
+ "default": "database/migrations"
49
+ },
50
+ "description": "Migration chains by name; `--chain <name>` picks one"
51
+ },
52
+ "tests": {
53
+ "type": "boolean",
54
+ "default": true,
55
+ "description": "Write a test beside every generated file except migrations and factories"
56
+ },
57
+ "stubs": {
58
+ "type": "string",
59
+ "default": ".config/sdxc/stubs",
60
+ "description": "Stubs here replace the built-in ones; `sdxc make stubs` copies them out"
61
+ }
62
+ },
63
+ "additionalProperties": false,
64
+ "default": {
65
+ "routes": "web",
66
+ "migrations": {
67
+ "default": "database/migrations"
68
+ },
69
+ "tests": true,
70
+ "stubs": ".config/sdxc/stubs"
71
+ }
72
+ },
73
+ "format": {
74
+ "type": "array",
75
+ "items": {
76
+ "type": "string"
77
+ },
78
+ "minItems": 1,
79
+ "description": "Command run on every file the CLI writes or edits, paths appended",
80
+ "examples": [["bunx", "vp", "fmt"]]
81
+ },
82
+ "lock": {
83
+ "type": "string",
84
+ "default": ".config/sdxc.lock.jsonl",
85
+ "description": "Where the CLI keeps its state; commit it with the project"
86
+ }
87
+ },
88
+ "additionalProperties": false
89
+ }
package/dist/bin.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The `sdxc` binary: runs the command line against the process's own working directory and
4
+ * streams, and leaves the exit code for Node or Bun to report once output has flushed.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ export {};
package/dist/bin.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The `sdxc` binary: runs the command line against the process's own working directory and
4
+ * streams, and leaves the exit code for Node or Bun to report once output has flushed.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { createSDXC, kitVersion } from "./cli.js";
10
+ process.exitCode = await createSDXC({ version: kitVersion() }).run(process.argv.slice(2));
package/dist/cli.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The `sdxc` command line: its contract with every handler mapped through `lazy()`, so a run
3
+ * imports only the command it reaches and `--help` imports none. The `sdxc` binary runs it
4
+ * against the process; a test builds its own with a fixture kit.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { CLI } from "@sdxc/cli";
10
+ import { SDXC_COMMANDS } from "./contract.js";
11
+ import { packageRoot } from "./middleware.js";
12
+ /** What the binary and the tests vary between runs. */
13
+ export interface SDXCOptions {
14
+ /** Printed by `--version`; without one the flag does not exist. */
15
+ version?: string;
16
+ /**
17
+ * The kit package commands read templates, stubs, the component registry and the
18
+ * changelog from.
19
+ * @default the package this module runs from
20
+ */
21
+ packageRoot?: string;
22
+ }
23
+ /**
24
+ * The version in the kit's own `package.json`, which sits one level above both `src/` and
25
+ * `dist/`, so `--version` names the release whichever binary started the run.
26
+ */
27
+ export declare function kitVersion(): string | undefined;
28
+ /**
29
+ * Builds the `sdxc` command line.
30
+ *
31
+ * @example process.exitCode = await createSDXC({ version }).run(process.argv.slice(2));
32
+ */
33
+ export declare function createSDXC(options?: SDXCOptions): CLI<typeof SDXC_COMMANDS, readonly [ReturnType<typeof packageRoot>]>;
package/dist/cli.js ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The `sdxc` command line: its contract with every handler mapped through `lazy()`, so a run
3
+ * imports only the command it reaches and `--help` imports none. The `sdxc` binary runs it
4
+ * against the process; a test builds its own with a fixture kit.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { readFileSync } from "node:fs";
10
+ import { createCLI, lazy } from "@sdxc/cli";
11
+ import { SDXC_COMMANDS } from "./contract.js";
12
+ import { packageRoot } from "./middleware.js";
13
+ /**
14
+ * The version in the kit's own `package.json`, which sits one level above both `src/` and
15
+ * `dist/`, so `--version` names the release whichever binary started the run.
16
+ */
17
+ export function kitVersion() {
18
+ let manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
19
+ return typeof manifest.version === "string" ? manifest.version : undefined;
20
+ }
21
+ /**
22
+ * Builds the `sdxc` command line.
23
+ *
24
+ * @example process.exitCode = await createSDXC({ version }).run(process.argv.slice(2));
25
+ */
26
+ export function createSDXC(options = {}) {
27
+ let cli = createCLI({
28
+ name: "sdxc",
29
+ version: options.version,
30
+ commands: SDXC_COMMANDS,
31
+ middleware: [packageRoot(options.packageRoot)],
32
+ });
33
+ cli.map(SDXC_COMMANDS.create, lazy(() => import("./commands/create.js")));
34
+ cli.map(SDXC_COMMANDS.init, lazy(() => import("./commands/init.js")));
35
+ cli.map(SDXC_COMMANDS.make, lazy(() => import("./commands/make.js").then((module) => ({ default: module.group }))));
36
+ cli.map(SDXC_COMMANDS.make.controller, lazy(() => import("./commands/make.js").then((module) => ({ default: module.controller }))));
37
+ cli.map(SDXC_COMMANDS.make.middleware, lazy(() => import("./commands/make.js").then((module) => ({ default: module.middleware }))));
38
+ cli.map(SDXC_COMMANDS.make.validator, lazy(() => import("./commands/make.js").then((module) => ({ default: module.validator }))));
39
+ cli.map(SDXC_COMMANDS.make.job, lazy(() => import("./commands/make.js").then((module) => ({ default: module.job }))));
40
+ cli.map(SDXC_COMMANDS.make.model, lazy(() => import("./commands/make.js").then((module) => ({ default: module.model }))));
41
+ cli.map(SDXC_COMMANDS.make.migration, lazy(() => import("./commands/make.js").then((module) => ({ default: module.migration }))));
42
+ cli.map(SDXC_COMMANDS.make.factory, lazy(() => import("./commands/make.js").then((module) => ({ default: module.factory }))));
43
+ cli.map(SDXC_COMMANDS.make.service, lazy(() => import("./commands/make.js").then((module) => ({ default: module.service }))));
44
+ cli.map(SDXC_COMMANDS.make.policy, lazy(() => import("./commands/make.js").then((module) => ({ default: module.policy }))));
45
+ cli.map(SDXC_COMMANDS.make.initializer, lazy(() => import("./commands/make.js").then((module) => ({ default: module.initializer }))));
46
+ cli.map(SDXC_COMMANDS.make.email, lazy(() => import("./commands/make.js").then((module) => ({ default: module.email }))));
47
+ cli.map(SDXC_COMMANDS.make.mcp, lazy(() => import("./commands/make.js").then((module) => ({ default: module.mcp }))));
48
+ cli.map(SDXC_COMMANDS.make.command, lazy(() => import("./commands/make.js").then((module) => ({ default: module.command }))));
49
+ cli.map(SDXC_COMMANDS.make.stubs, lazy(() => import("./commands/make.js").then((module) => ({ default: module.stubs }))));
50
+ cli.map(SDXC_COMMANDS.run, lazy(() => import("./commands/run.js")));
51
+ cli.map(SDXC_COMMANDS.ui.list, lazy(() => import("./commands/ui/list.js")));
52
+ cli.map(SDXC_COMMANDS.ui.add, lazy(() => import("./commands/ui/add.js")));
53
+ cli.map(SDXC_COMMANDS.ui.diff, lazy(() => import("./commands/ui/diff.js")));
54
+ cli.map(SDXC_COMMANDS.ui.update, lazy(() => import("./commands/ui/update.js")));
55
+ cli.map(SDXC_COMMANDS.ui.remove, lazy(() => import("./commands/ui/remove.js")));
56
+ cli.map(SDXC_COMMANDS.upgrade, lazy(() => import("./commands/upgrade.js")));
57
+ return cli;
58
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * The `sdxc create` handler: writes a new project from a built-in template or a GitHub
3
+ * repository into a missing or empty directory. Nothing from the template runs: it installs
4
+ * nothing and prints the next steps, and initializes git only in a directory it made.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ /** Creates the project, then initializes git when asked to, then prints the next steps. */
10
+ declare const _default: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Command<{
11
+ readonly directory: import("@sdxc/cli").Argument<string | undefined>;
12
+ }, {
13
+ readonly template: import("@sdxc/cli").ValueFlag<string, true, false, false>;
14
+ readonly git: import("@sdxc/cli").Flag<boolean | undefined>;
15
+ }>, readonly [import("@sdxc/cli").CommandMiddleware<{
16
+ key: typeof import("../middleware.js").PackageRoot;
17
+ value: string;
18
+ property: "packageRoot";
19
+ }>]>;
20
+ export default _default;
@@ -0,0 +1,164 @@
1
+ /**
2
+ * The `sdxc create` handler: writes a new project from a built-in template or a GitHub
3
+ * repository into a missing or empty directory. Nothing from the template runs: it installs
4
+ * nothing and prints the next steps, and initializes git only in a directory it made.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { relative } from "node:path";
10
+ import { createCommand, success } from "@sdxc/cli";
11
+ import { failure, isFailure, wrap } from "@sdxc/result";
12
+ import { SDXC_COMMANDS } from "../contract.js";
13
+ import { describe, downloadTemplate, GitHubRefusal, githubToken } from "../create/github.js";
14
+ import { resolveTarget } from "../create/target.js";
15
+ import { completeBuiltin, nameProject, parseTemplate, readBuiltinTemplate, writeTree, } from "../create/templates.js";
16
+ import { packageRoot } from "../middleware.js";
17
+ import { packageManager, scriptCommand } from "../package-manager.js";
18
+ /** The middleware `create` runs behind; it runs outside any project. */
19
+ const CREATE_MIDDLEWARE = [packageRoot()];
20
+ /** Creates the project, then initializes git when asked to, then prints the next steps. */
21
+ export default createCommand(SDXC_COMMANDS.create, {
22
+ middleware: CREATE_MIDDLEWARE,
23
+ /** Exits 1 when the target or the template is refused, writing nothing. */
24
+ async handler(ctx) {
25
+ let source = parseTemplate(ctx.flags.template);
26
+ if (isFailure(source))
27
+ return source;
28
+ let target = await resolveTarget(ctx.cwd, ctx.arguments.directory);
29
+ if (isFailure(target))
30
+ return target;
31
+ let fetched = await fetchTemplate(ctx, source.data, target.data.name);
32
+ if (isFailure(fetched))
33
+ return fetched;
34
+ let written = await writeTree(target.data.directory, fetched.data.tree);
35
+ if (isFailure(written))
36
+ return written;
37
+ let shown = relative(ctx.cwd, target.data.directory);
38
+ ctx.stdout(`Created ${target.data.name} from ${fetched.data.description}\n`);
39
+ if (!target.data.exists && ctx.flags.git !== false) {
40
+ let initialized = await initializeGit(ctx, ctx.flags.git, target.data.directory, shown);
41
+ if (isFailure(initialized))
42
+ return initialized;
43
+ }
44
+ let tree = fetched.data.tree;
45
+ let manager = await packageManager({
46
+ declared: treeManifest(tree)?.packageManager,
47
+ findLockFile: (names) => names.find((name) => tree.files.has(name)) ?? null,
48
+ userAgent: ctx.env.npm_config_user_agent,
49
+ });
50
+ let steps = [];
51
+ if (shown !== "")
52
+ steps.push(`cd ${shown.includes(" ") ? JSON.stringify(shown) : shown}`);
53
+ steps.push(manager.install.join(" "));
54
+ if (hasScript(tree, "dev"))
55
+ steps.push(scriptCommand(manager, "dev"));
56
+ ctx.stdout(`\nNext steps:\n${steps.map((step) => ` ${step}\n`).join("")}`);
57
+ return success();
58
+ },
59
+ });
60
+ /**
61
+ * Runs `git init` in the new project when `--git` was passed, or when the user says yes on a
62
+ * terminal, where Enter says yes; without a terminal and without `--git`, no repository is
63
+ * made. A missing `git` is noted and skipped.
64
+ *
65
+ * @param wanted - `--git` or `--no-git`, or `undefined` to ask
66
+ * @param shown - The project directory relative to where the command ran, for the question
67
+ */
68
+ async function initializeGit(ctx, wanted, directory, shown) {
69
+ let available = await ctx.exec(["git", "--version"], { stdio: "ignore" });
70
+ if (isFailure(available)) {
71
+ ctx.stdout("git is not on the PATH, so no repository was initialized\n");
72
+ return success(undefined);
73
+ }
74
+ if (wanted === undefined) {
75
+ let answer = await ctx.prompt.confirm({
76
+ message: `Initialize a git repository in ${shown}?`,
77
+ default: false,
78
+ initial: true,
79
+ name: "git",
80
+ });
81
+ if (isFailure(answer))
82
+ return answer;
83
+ wanted = answer.data;
84
+ }
85
+ if (!wanted)
86
+ return success(undefined);
87
+ let initialized = await ctx.exec(["git", "init", "--quiet"], {
88
+ cwd: directory,
89
+ stdio: "ignore",
90
+ });
91
+ if (isFailure(initialized)) {
92
+ let code = "code" in initialized.error ? initialized.error.code : null;
93
+ return failure(new Error(`git init exited with ${code ?? "an error"} in ${directory}`));
94
+ }
95
+ ctx.stdout("Initialized a git repository\n");
96
+ return success(undefined);
97
+ }
98
+ /** Reads the template `source` names and completes it for the project `name`. */
99
+ async function fetchTemplate(ctx, source, name) {
100
+ if (source.kind === "github") {
101
+ let extracted = await download(ctx, source);
102
+ if (isFailure(extracted))
103
+ return extracted;
104
+ let named = nameProject(extracted.data.tree, name);
105
+ if (isFailure(named))
106
+ return named;
107
+ let commit = extracted.data.commit === null ? "" : ` at ${extracted.data.commit}`;
108
+ return success({ tree: extracted.data.tree, description: `${describe(source)}${commit}` });
109
+ }
110
+ let tree = await readBuiltinTemplate(ctx.packageRoot, source.name);
111
+ if (isFailure(tree))
112
+ return tree;
113
+ let completed = await completeBuiltin(tree.data, name, ctx.packageRoot);
114
+ if (isFailure(completed))
115
+ return completed;
116
+ return success({ tree: tree.data, description: `the ${source.name} template` });
117
+ }
118
+ /**
119
+ * Downloads and extracts a GitHub template as a task. When GitHub answers 401 or 404 and no
120
+ * token is set, a terminal is asked for one, used for this download alone; an empty answer, or
121
+ * no terminal, keeps the refusal.
122
+ */
123
+ async function download(ctx, source) {
124
+ let label = `Downloading ${describe(source)}`;
125
+ let downloaded = await ctx.task(label, (task) => downloadTemplate(source, ctx.env, task.signal));
126
+ let refused = isFailure(downloaded) &&
127
+ downloaded.error instanceof GitHubRefusal &&
128
+ (downloaded.error.status === 401 || downloaded.error.status === 404) &&
129
+ githubToken(ctx.env) === undefined;
130
+ if (!refused)
131
+ return downloaded;
132
+ let token = await ctx.prompt.password({
133
+ message: `GitHub token for ${source.owner}/${source.repo}`,
134
+ default: "",
135
+ name: "token",
136
+ });
137
+ if (isFailure(token))
138
+ return token;
139
+ if (token.data === "")
140
+ return downloaded;
141
+ return ctx.task(label, (task) => downloadTemplate(source, { GITHUB_TOKEN: token.data }, task.signal));
142
+ }
143
+ /** The fields of the tree's `package.json` the next steps read, or `null` without a readable one. */
144
+ function treeManifest(tree) {
145
+ let bytes = tree.files.get("package.json");
146
+ if (bytes === undefined)
147
+ return null;
148
+ let manifest = wrap(() => JSON.parse(new TextDecoder().decode(bytes)));
149
+ if (isFailure(manifest) || typeof manifest.data !== "object" || manifest.data === null) {
150
+ return null;
151
+ }
152
+ let { packageManager: declared, scripts } = manifest.data;
153
+ return {
154
+ ...(typeof declared === "string" ? { packageManager: declared } : {}),
155
+ ...(typeof scripts === "object" && scripts !== null
156
+ ? { scripts: scripts }
157
+ : {}),
158
+ };
159
+ }
160
+ /** Whether the tree's `package.json` declares `script`. */
161
+ function hasScript(tree, script) {
162
+ let scripts = treeManifest(tree)?.scripts;
163
+ return scripts !== undefined && script in scripts;
164
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The `sdxc init` handler: writes `.config/sdxc.jsonc` at the project root, or prints it under
3
+ * `--dry-run`, and names an existing configuration instead of touching it.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ /** Writes the configuration, or prints it under `--dry-run`, in the project `project()` found. */
9
+ declare const _default: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Command<Readonly<Record<string, import("@sdxc/cli").Argument<unknown>>>, {
10
+ readonly dryRun: import("@sdxc/cli").Flag<boolean>;
11
+ }>, readonly [import("@sdxc/cli").CommandMiddleware<{
12
+ key: typeof import("../middleware.js").CurrentProject;
13
+ value: import("../middleware.js").Project;
14
+ property: "project";
15
+ }>]>;
16
+ export default _default;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The `sdxc init` handler: writes `.config/sdxc.jsonc` at the project root, or prints it under
3
+ * `--dry-run`, and names an existing configuration instead of touching it.
4
+ *
5
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
6
+ * @copyright Sergio Xalambrí 2026
7
+ */
8
+ import { createCommand, success } from "@sdxc/cli";
9
+ import { isFailure } from "@sdxc/result";
10
+ import { SDXC_COMMANDS } from "../contract.js";
11
+ import { init } from "../init.js";
12
+ import { project } from "../middleware.js";
13
+ /** Writes the configuration, or prints it under `--dry-run`, in the project `project()` found. */
14
+ export default createCommand(SDXC_COMMANDS.init, {
15
+ middleware: [project()],
16
+ /** Prints the path it wrote, or the file it would write. */
17
+ async handler(ctx) {
18
+ let outcome = await init(ctx.project.root, { dryRun: ctx.flags.dryRun });
19
+ if (isFailure(outcome))
20
+ return outcome;
21
+ if (outcome.data.written)
22
+ ctx.stdout(`Wrote ${outcome.data.path}\n`);
23
+ else
24
+ ctx.stdout(`Would write ${outcome.data.path}:\n\n${outcome.data.content}`);
25
+ return success();
26
+ },
27
+ });