@sdxc/kit 0.0.0-pre.1

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 (144) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +93 -0
  3. package/config.schema.json +89 -0
  4. package/dist/bin.d.ts +9 -0
  5. package/dist/bin.js +10 -0
  6. package/dist/cli.d.ts +33 -0
  7. package/dist/cli.js +58 -0
  8. package/dist/commands/create.d.ts +20 -0
  9. package/dist/commands/create.js +164 -0
  10. package/dist/commands/init.d.ts +16 -0
  11. package/dist/commands/init.js +27 -0
  12. package/dist/commands/make.d.ts +335 -0
  13. package/dist/commands/make.js +152 -0
  14. package/dist/commands/run.d.ts +23 -0
  15. package/dist/commands/run.js +51 -0
  16. package/dist/commands/ui/add.d.ts +23 -0
  17. package/dist/commands/ui/add.js +50 -0
  18. package/dist/commands/ui/diff.d.ts +20 -0
  19. package/dist/commands/ui/diff.js +28 -0
  20. package/dist/commands/ui/list.d.ts +24 -0
  21. package/dist/commands/ui/list.js +45 -0
  22. package/dist/commands/ui/remove.d.ts +22 -0
  23. package/dist/commands/ui/remove.js +48 -0
  24. package/dist/commands/ui/update.d.ts +23 -0
  25. package/dist/commands/ui/update.js +37 -0
  26. package/dist/commands/upgrade.d.ts +30 -0
  27. package/dist/commands/upgrade.js +184 -0
  28. package/dist/config.d.ts +81 -0
  29. package/dist/config.js +157 -0
  30. package/dist/contract.d.ts +161 -0
  31. package/dist/contract.js +308 -0
  32. package/dist/create/github.d.ts +63 -0
  33. package/dist/create/github.js +172 -0
  34. package/dist/create/target.d.ts +31 -0
  35. package/dist/create/target.js +56 -0
  36. package/dist/create/templates.d.ts +62 -0
  37. package/dist/create/templates.js +228 -0
  38. package/dist/dependencies.d.ts +34 -0
  39. package/dist/dependencies.js +76 -0
  40. package/dist/diff.d.ts +14 -0
  41. package/dist/diff.js +103 -0
  42. package/dist/format.d.ts +21 -0
  43. package/dist/format.js +40 -0
  44. package/dist/init.d.ts +38 -0
  45. package/dist/init.js +92 -0
  46. package/dist/lock.d.ts +74 -0
  47. package/dist/lock.js +214 -0
  48. package/dist/make/declare.d.ts +54 -0
  49. package/dist/make/declare.js +495 -0
  50. package/dist/make/generate.d.ts +56 -0
  51. package/dist/make/generate.js +139 -0
  52. package/dist/make/imports.d.ts +43 -0
  53. package/dist/make/imports.js +104 -0
  54. package/dist/make/index.d.ts +43 -0
  55. package/dist/make/index.js +136 -0
  56. package/dist/make/kinds.d.ts +39 -0
  57. package/dist/make/kinds.js +95 -0
  58. package/dist/make/migrations.d.ts +21 -0
  59. package/dist/make/migrations.js +48 -0
  60. package/dist/make/names.d.ts +31 -0
  61. package/dist/make/names.js +47 -0
  62. package/dist/make/stubs.d.ts +44 -0
  63. package/dist/make/stubs.js +89 -0
  64. package/dist/middleware.d.ts +44 -0
  65. package/dist/middleware.js +49 -0
  66. package/dist/package-manager.d.ts +41 -0
  67. package/dist/package-manager.js +80 -0
  68. package/dist/project.d.ts +19 -0
  69. package/dist/project.js +42 -0
  70. package/dist/releases.d.ts +40 -0
  71. package/dist/releases.js +110 -0
  72. package/dist/testing.d.ts +47 -0
  73. package/dist/testing.js +126 -0
  74. package/dist/ui/commands.d.ts +114 -0
  75. package/dist/ui/commands.js +432 -0
  76. package/dist/ui/imports.d.ts +46 -0
  77. package/dist/ui/imports.js +160 -0
  78. package/dist/ui/layout.d.ts +48 -0
  79. package/dist/ui/layout.js +138 -0
  80. package/dist/ui/registry.d.ts +58 -0
  81. package/dist/ui/registry.js +82 -0
  82. package/dist/upgrade/changelog.d.ts +50 -0
  83. package/dist/upgrade/changelog.js +69 -0
  84. package/dist/upgrade/project.d.ts +62 -0
  85. package/dist/upgrade/project.js +132 -0
  86. package/dist/upgrade/prompt.d.ts +51 -0
  87. package/dist/upgrade/prompt.js +227 -0
  88. package/dist/upgrade/registry.d.ts +33 -0
  89. package/dist/upgrade/registry.js +50 -0
  90. package/lock.schema.json +60 -0
  91. package/package.json +45 -0
  92. package/stubs/command.stub +12 -0
  93. package/stubs/command.test.stub +18 -0
  94. package/stubs/controller.form.stub +33 -0
  95. package/stubs/controller.stub +17 -0
  96. package/stubs/controller.test.stub +15 -0
  97. package/stubs/email.stub +44 -0
  98. package/stubs/email.test.stub +16 -0
  99. package/stubs/factory.stub +10 -0
  100. package/stubs/initializer.stub +7 -0
  101. package/stubs/initializer.test.stub +13 -0
  102. package/stubs/job.cron.stub +12 -0
  103. package/stubs/job.stub +11 -0
  104. package/stubs/job.test.stub +15 -0
  105. package/stubs/mcp.resource.stub +12 -0
  106. package/stubs/mcp.stub +10 -0
  107. package/stubs/mcp.test.stub +15 -0
  108. package/stubs/middleware.stub +11 -0
  109. package/stubs/middleware.test.stub +13 -0
  110. package/stubs/migration.stub +1 -0
  111. package/stubs/model.stub +24 -0
  112. package/stubs/model.test.stub +15 -0
  113. package/stubs/policy.stub +13 -0
  114. package/stubs/policy.test.stub +17 -0
  115. package/stubs/service.stub +13 -0
  116. package/stubs/service.test.stub +14 -0
  117. package/stubs/validator.stub +14 -0
  118. package/stubs/validator.test.stub +22 -0
  119. package/templates/app/README.md +57 -0
  120. package/templates/app/app/commands/about.test.ts +29 -0
  121. package/templates/app/app/commands/about.ts +34 -0
  122. package/templates/app/app/commands/index.ts +15 -0
  123. package/templates/app/app/http/controllers/home.tsx +22 -0
  124. package/templates/app/app/http/controllers/not-found.tsx +25 -0
  125. package/templates/app/app/initializers/assets.ts +11 -0
  126. package/templates/app/app/initializers/cli.ts +35 -0
  127. package/templates/app/app/initializers/dispatcher.ts +18 -0
  128. package/templates/app/app/initializers/logger.ts +10 -0
  129. package/templates/app/app/initializers/mcp.ts +16 -0
  130. package/templates/app/app/initializers/router.tsx +65 -0
  131. package/templates/app/app/jobs/index.ts +10 -0
  132. package/templates/app/app/mcp/resources/index.ts +9 -0
  133. package/templates/app/app/mcp/tools/index.ts +10 -0
  134. package/templates/app/bootstrap/browser.ts +27 -0
  135. package/templates/app/bootstrap/cli.ts +9 -0
  136. package/templates/app/bootstrap/worker.ts +31 -0
  137. package/templates/app/cloudflare.config.ts +28 -0
  138. package/templates/app/config/router-context.d.ts +20 -0
  139. package/templates/app/gitignore +9 -0
  140. package/templates/app/package.json +38 -0
  141. package/templates/app/resources/layouts/document.tsx +58 -0
  142. package/templates/app/routes/web.ts +12 -0
  143. package/templates/app/tsconfig.json +40 -0
  144. package/templates/app/vite.config.ts +40 -0
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sergio Xalambrí
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # @sdxc/kit
2
+
3
+ The sdxc command line: start a Remix v3 app, generate its files, copy UI components into it and upgrade it.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm add -g @sdxc/kit
9
+ ```
10
+
11
+ The package installs a command named `sdxc`. It works on projects that depend on the `@sdxc/*` packages, and every command that writes code lists the packages that code imports in `package.json`.
12
+
13
+ ## Usage
14
+
15
+ ```sh
16
+ sdxc create my-app # a Remix v3 app, or --template org/repo from GitHub
17
+ sdxc make controller posts/show # a file where the app layout puts it, with its test
18
+ sdxc ui add dialog # copy a component into the project to edit it
19
+ sdxc upgrade # move to the latest release and print a prompt for the code
20
+ sdxc run users find ada@example.com # run the app's own command line, bootstrap/cli.ts
21
+ ```
22
+
23
+ On a terminal each command asks for what you left out; every question has a flag, so scripts and agents never wait on one.
24
+
25
+ ### Releases
26
+
27
+ Every `@sdxc/*` package versions as the UTC date it was published, and a daily release republishes only the packages that changed, so a project's packages carry different dates from the same release. The kit reads a project's release as the newest date among its `@sdxc/*` pins, and pins a package "at a release" to its newest version on or before that date:
28
+
29
+ - `sdxc create` pins each package the template lists to its `latest` version.
30
+ - `sdxc make` and `sdxc ui add` add a package the written code imports at the project's release, and print the install command to run.
31
+ - `sdxc upgrade [release]` moves every `@sdxc/*` package the project lists to the target release, latest when left out, and `remix` to the version that release requires, then installs and prints a prompt for an AI agent from that release's changelog.
32
+
33
+ ## API
34
+
35
+ ### Commands
36
+
37
+ | Command | What it does |
38
+ | -------------- | ------------------------------------------------------------------------------- |
39
+ | `sdxc create` | Writes a new project from the built-in `app` template or a GitHub repository |
40
+ | `sdxc init` | Writes `.config/sdxc.jsonc` with every key at its default |
41
+ | `sdxc run` | Runs the app's own command line, `bootstrap/cli.ts`, with the project's runtime |
42
+ | `sdxc make` | Writes a controller, job, model, migration or other file, declared and mapped |
43
+ | `sdxc ui` | Copies `@sdxc/ui` components into the project and points imports at the copies |
44
+ | `sdxc upgrade` | Moves the `@sdxc/*` packages and `remix` to a release and prints the prompt |
45
+
46
+ `sdxc <command> --help` lists each command's arguments and flags. Commands run from the project root, the nearest directory with a `package.json`.
47
+
48
+ ### Configuration
49
+
50
+ The CLI reads `.config/sdxc.jsonc` (or `sdxc.jsonc` at the project root). Every key is optional.
51
+
52
+ | Key | Default | Meaning |
53
+ | ----------------- | -------------------------------------- | ---------------------------------------------------------------------------- |
54
+ | `ui.directory` | `resources/components/ui` | Where `sdxc ui add` writes components |
55
+ | `ui.alias` | inferred from tsconfig `paths` | Import prefix for the copies |
56
+ | `ui.tests` | `false` | Copy a component's tests beside it |
57
+ | `make.routes` | `web` | Route contract `sdxc make controller` adds to, a module in `routes/` |
58
+ | `make.migrations` | `{ "default": "database/migrations" }` | Migration chains by name |
59
+ | `make.tests` | `true` | Write a test beside every generated file except migrations and factories |
60
+ | `make.stubs` | `.config/sdxc/stubs` | Stubs that replace the built-in ones |
61
+ | `format` | none | Command run once on every file a command wrote or edited, the paths appended |
62
+ | `lock` | `.config/sdxc.lock.jsonl` | Where the CLI keeps its state |
63
+
64
+ `format` is an argument list, such as `["bunx", "vp", "fmt"]`.
65
+
66
+ ### `@sdxc/kit/config.schema.json`
67
+
68
+ The JSON Schema 2020-12 document for `.config/sdxc.jsonc`. `sdxc init` points the file's `$schema` at `https://unpkg.com/@sdxc/kit/config.schema.json`.
69
+
70
+ ### `@sdxc/kit/lock.schema.json`
71
+
72
+ The JSON Schema 2020-12 document for one line of the lock file, where the CLI records state such as copied components. Commit the lock file and leave it to the CLI.
73
+
74
+ ### `createSDXC(options?)` and `kitVersion()`
75
+
76
+ Builds the command line the `sdxc` binary runs, for a program that embeds it: `await createSDXC({ version: kitVersion() }).run(argv)` answers the exit code.
77
+
78
+ ## Versioning
79
+
80
+ Releases are dated rather than semantic. A version is the UTC date it was published,
81
+ written `YYYY.M.D`, so `2026.9.4` is the release from 4 September 2026. At most one
82
+ release goes out per day, and every release ships `@sdxc/kit`.
83
+
84
+ Those numbers say when, not what: a later date means a later release and carries no
85
+ compatibility promise. Any release may change or remove a command or flag.
86
+
87
+ ## License
88
+
89
+ MIT
90
+
91
+ ## Author
92
+
93
+ [Sergio Xalambrí](https://sergiodxa.com)
@@ -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
+ });