@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.
- package/LICENSE.md +21 -0
- package/README.md +93 -0
- package/config.schema.json +89 -0
- package/dist/bin.d.ts +9 -0
- package/dist/bin.js +10 -0
- package/dist/cli.d.ts +33 -0
- package/dist/cli.js +58 -0
- package/dist/commands/create.d.ts +20 -0
- package/dist/commands/create.js +164 -0
- package/dist/commands/init.d.ts +16 -0
- package/dist/commands/init.js +27 -0
- package/dist/commands/make.d.ts +335 -0
- package/dist/commands/make.js +152 -0
- package/dist/commands/run.d.ts +23 -0
- package/dist/commands/run.js +51 -0
- package/dist/commands/ui/add.d.ts +23 -0
- package/dist/commands/ui/add.js +50 -0
- package/dist/commands/ui/diff.d.ts +20 -0
- package/dist/commands/ui/diff.js +28 -0
- package/dist/commands/ui/list.d.ts +24 -0
- package/dist/commands/ui/list.js +45 -0
- package/dist/commands/ui/remove.d.ts +22 -0
- package/dist/commands/ui/remove.js +48 -0
- package/dist/commands/ui/update.d.ts +23 -0
- package/dist/commands/ui/update.js +37 -0
- package/dist/commands/upgrade.d.ts +30 -0
- package/dist/commands/upgrade.js +184 -0
- package/dist/config.d.ts +81 -0
- package/dist/config.js +157 -0
- package/dist/contract.d.ts +161 -0
- package/dist/contract.js +308 -0
- package/dist/create/github.d.ts +63 -0
- package/dist/create/github.js +172 -0
- package/dist/create/target.d.ts +31 -0
- package/dist/create/target.js +56 -0
- package/dist/create/templates.d.ts +62 -0
- package/dist/create/templates.js +228 -0
- package/dist/dependencies.d.ts +34 -0
- package/dist/dependencies.js +76 -0
- package/dist/diff.d.ts +14 -0
- package/dist/diff.js +103 -0
- package/dist/format.d.ts +21 -0
- package/dist/format.js +40 -0
- package/dist/init.d.ts +38 -0
- package/dist/init.js +92 -0
- package/dist/lock.d.ts +74 -0
- package/dist/lock.js +214 -0
- package/dist/make/declare.d.ts +54 -0
- package/dist/make/declare.js +495 -0
- package/dist/make/generate.d.ts +56 -0
- package/dist/make/generate.js +139 -0
- package/dist/make/imports.d.ts +43 -0
- package/dist/make/imports.js +104 -0
- package/dist/make/index.d.ts +43 -0
- package/dist/make/index.js +136 -0
- package/dist/make/kinds.d.ts +39 -0
- package/dist/make/kinds.js +95 -0
- package/dist/make/migrations.d.ts +21 -0
- package/dist/make/migrations.js +48 -0
- package/dist/make/names.d.ts +31 -0
- package/dist/make/names.js +47 -0
- package/dist/make/stubs.d.ts +44 -0
- package/dist/make/stubs.js +89 -0
- package/dist/middleware.d.ts +44 -0
- package/dist/middleware.js +49 -0
- package/dist/package-manager.d.ts +41 -0
- package/dist/package-manager.js +80 -0
- package/dist/project.d.ts +19 -0
- package/dist/project.js +42 -0
- package/dist/releases.d.ts +40 -0
- package/dist/releases.js +110 -0
- package/dist/testing.d.ts +47 -0
- package/dist/testing.js +126 -0
- package/dist/ui/commands.d.ts +114 -0
- package/dist/ui/commands.js +432 -0
- package/dist/ui/imports.d.ts +46 -0
- package/dist/ui/imports.js +160 -0
- package/dist/ui/layout.d.ts +48 -0
- package/dist/ui/layout.js +138 -0
- package/dist/ui/registry.d.ts +58 -0
- package/dist/ui/registry.js +82 -0
- package/dist/upgrade/changelog.d.ts +50 -0
- package/dist/upgrade/changelog.js +69 -0
- package/dist/upgrade/project.d.ts +62 -0
- package/dist/upgrade/project.js +132 -0
- package/dist/upgrade/prompt.d.ts +51 -0
- package/dist/upgrade/prompt.js +227 -0
- package/dist/upgrade/registry.d.ts +33 -0
- package/dist/upgrade/registry.js +50 -0
- package/lock.schema.json +60 -0
- package/package.json +45 -0
- package/stubs/command.stub +12 -0
- package/stubs/command.test.stub +18 -0
- package/stubs/controller.form.stub +33 -0
- package/stubs/controller.stub +17 -0
- package/stubs/controller.test.stub +15 -0
- package/stubs/email.stub +44 -0
- package/stubs/email.test.stub +16 -0
- package/stubs/factory.stub +10 -0
- package/stubs/initializer.stub +7 -0
- package/stubs/initializer.test.stub +13 -0
- package/stubs/job.cron.stub +12 -0
- package/stubs/job.stub +11 -0
- package/stubs/job.test.stub +15 -0
- package/stubs/mcp.resource.stub +12 -0
- package/stubs/mcp.stub +10 -0
- package/stubs/mcp.test.stub +15 -0
- package/stubs/middleware.stub +11 -0
- package/stubs/middleware.test.stub +13 -0
- package/stubs/migration.stub +1 -0
- package/stubs/model.stub +24 -0
- package/stubs/model.test.stub +15 -0
- package/stubs/policy.stub +13 -0
- package/stubs/policy.test.stub +17 -0
- package/stubs/service.stub +13 -0
- package/stubs/service.test.stub +14 -0
- package/stubs/validator.stub +14 -0
- package/stubs/validator.test.stub +22 -0
- package/templates/app/README.md +57 -0
- package/templates/app/app/commands/about.test.ts +29 -0
- package/templates/app/app/commands/about.ts +34 -0
- package/templates/app/app/commands/index.ts +15 -0
- package/templates/app/app/http/controllers/home.tsx +22 -0
- package/templates/app/app/http/controllers/not-found.tsx +25 -0
- package/templates/app/app/initializers/assets.ts +11 -0
- package/templates/app/app/initializers/cli.ts +35 -0
- package/templates/app/app/initializers/dispatcher.ts +18 -0
- package/templates/app/app/initializers/logger.ts +10 -0
- package/templates/app/app/initializers/mcp.ts +16 -0
- package/templates/app/app/initializers/router.tsx +65 -0
- package/templates/app/app/jobs/index.ts +10 -0
- package/templates/app/app/mcp/resources/index.ts +9 -0
- package/templates/app/app/mcp/tools/index.ts +10 -0
- package/templates/app/bootstrap/browser.ts +27 -0
- package/templates/app/bootstrap/cli.ts +9 -0
- package/templates/app/bootstrap/worker.ts +31 -0
- package/templates/app/cloudflare.config.ts +28 -0
- package/templates/app/config/router-context.d.ts +20 -0
- package/templates/app/gitignore +9 -0
- package/templates/app/package.json +38 -0
- package/templates/app/resources/layouts/document.tsx +58 -0
- package/templates/app/routes/web.ts +12 -0
- package/templates/app/tsconfig.json +40 -0
- package/templates/app/vite.config.ts +40 -0
package/dist/config.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `sdxc` project configuration: one schema holds every key with its default and its
|
|
3
|
+
* description, so validating a project's file, rendering `sdxc init`'s output and emitting
|
|
4
|
+
* `config.schema.json` for editors all read the same definition.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { readFile, stat } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import * as s from "@sdxc/json-schema";
|
|
12
|
+
import * as checks from "@sdxc/json-schema/checks";
|
|
13
|
+
import * as JSONC from "@sdxc/jsonc";
|
|
14
|
+
import { failure, isFailure, isSuccess, success, wrap } from "@sdxc/result";
|
|
15
|
+
import { resolveInside } from "./project.js";
|
|
16
|
+
/** Where the CLI looks for the configuration, relative to the project root, in lookup order. */
|
|
17
|
+
export const CONFIG_LOCATIONS = [".config/sdxc.jsonc", "sdxc.jsonc"];
|
|
18
|
+
/** The `ui` group as a project with no `ui` key gets it. */
|
|
19
|
+
const UI_DEFAULTS = { directory: "resources/components/ui", tests: false };
|
|
20
|
+
/** The `make` group as a project with no `make` key gets it. */
|
|
21
|
+
const MAKE_DEFAULTS = {
|
|
22
|
+
routes: "web",
|
|
23
|
+
migrations: { default: "database/migrations" },
|
|
24
|
+
tests: true,
|
|
25
|
+
stubs: ".config/sdxc/stubs",
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Every configuration key. Each leaf carries its default, or an example when it has none, and
|
|
29
|
+
* a description that becomes its comment in `sdxc init`'s output; an unknown key is an error, so
|
|
30
|
+
* a misspelt key is reported instead of silently ignored.
|
|
31
|
+
*/
|
|
32
|
+
export const CONFIG_SCHEMA = s.object({
|
|
33
|
+
$schema: s.optional(s.string()).meta({
|
|
34
|
+
description: "The JSON Schema editors check this file against",
|
|
35
|
+
}),
|
|
36
|
+
ui: s.defaulted(s.object({
|
|
37
|
+
directory: s
|
|
38
|
+
.defaulted(s.string(), UI_DEFAULTS.directory)
|
|
39
|
+
.meta({ description: "Where `sdxc ui add` writes components" }),
|
|
40
|
+
alias: s.optional(s.string()).meta({
|
|
41
|
+
description: "Import prefix for the copies; inferred from tsconfig `paths` when omitted",
|
|
42
|
+
examples: ["~/components/ui"],
|
|
43
|
+
}),
|
|
44
|
+
tests: s
|
|
45
|
+
.defaulted(s.boolean(), UI_DEFAULTS.tests)
|
|
46
|
+
.meta({ description: "Copy a component's tests beside it" }),
|
|
47
|
+
}, { unknownKeys: "error" }), UI_DEFAULTS),
|
|
48
|
+
make: s.defaulted(s.object({
|
|
49
|
+
routes: s.defaulted(s.string(), MAKE_DEFAULTS.routes).meta({
|
|
50
|
+
description: "Route contract `sdxc make controller` adds to, a module in routes/",
|
|
51
|
+
}),
|
|
52
|
+
migrations: s
|
|
53
|
+
.defaulted(s.record(s.string(), s.string()), MAKE_DEFAULTS.migrations)
|
|
54
|
+
.meta({ description: "Migration chains by name; `--chain <name>` picks one" }),
|
|
55
|
+
tests: s.defaulted(s.boolean(), MAKE_DEFAULTS.tests).meta({
|
|
56
|
+
description: "Write a test beside every generated file except migrations and factories",
|
|
57
|
+
}),
|
|
58
|
+
stubs: s.defaulted(s.string(), MAKE_DEFAULTS.stubs).meta({
|
|
59
|
+
description: "Stubs here replace the built-in ones; `sdxc make stubs` copies them out",
|
|
60
|
+
}),
|
|
61
|
+
}, { unknownKeys: "error" }), MAKE_DEFAULTS),
|
|
62
|
+
format: s.optional(s.array(s.string()).pipe(checks.minItems(1))).meta({
|
|
63
|
+
description: "Command run on every file the CLI writes or edits, paths appended",
|
|
64
|
+
examples: [["bunx", "vp", "fmt"]],
|
|
65
|
+
}),
|
|
66
|
+
lock: s.defaulted(s.string(), ".config/sdxc.lock.jsonl").meta({
|
|
67
|
+
description: "Where the CLI keeps its state; commit it with the project",
|
|
68
|
+
}),
|
|
69
|
+
}, { unknownKeys: "error" });
|
|
70
|
+
/**
|
|
71
|
+
* The configuration schema as a JSON Schema 2020-12 document, which `config.schema.json`
|
|
72
|
+
* ships and `sdxc init` renders.
|
|
73
|
+
*/
|
|
74
|
+
export function configJSONSchema() {
|
|
75
|
+
return s.toJSONSchema(CONFIG_SCHEMA);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The configuration file of the project at `root`, relative to it, or `null` when there is
|
|
79
|
+
* none. A file at both locations is a failure naming them, since either could be the one meant.
|
|
80
|
+
*/
|
|
81
|
+
export async function findConfigFile(root) {
|
|
82
|
+
let present = [];
|
|
83
|
+
for (let location of CONFIG_LOCATIONS) {
|
|
84
|
+
let found = await wrap(() => stat(join(root, location)));
|
|
85
|
+
if (isSuccess(found) && found.data.isFile())
|
|
86
|
+
present.push(location);
|
|
87
|
+
}
|
|
88
|
+
if (present.length > 1) {
|
|
89
|
+
return failure(new Error(`Found both ${present.join(" and ")}; keep one configuration file and delete the other`));
|
|
90
|
+
}
|
|
91
|
+
return success(present[0] ?? null);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Reads, validates and completes the configuration of the project at `root`. Every failing key
|
|
95
|
+
* is reported on its own line with its path, and every configured path must stay inside the
|
|
96
|
+
* project; a project without a file runs with the defaults.
|
|
97
|
+
*/
|
|
98
|
+
export async function loadConfig(root) {
|
|
99
|
+
let path = await findConfigFile(root);
|
|
100
|
+
if (isFailure(path))
|
|
101
|
+
return path;
|
|
102
|
+
if (path.data === null)
|
|
103
|
+
return parseConfig({}, root, null);
|
|
104
|
+
let location = path.data;
|
|
105
|
+
let text = await wrap(() => readFile(join(root, location), "utf8"));
|
|
106
|
+
if (isFailure(text))
|
|
107
|
+
return failure(new Error(`${location}: ${text.error.message}`));
|
|
108
|
+
let parsed = JSONC.parse(text.data);
|
|
109
|
+
if (isFailure(parsed))
|
|
110
|
+
return failure(new Error(`${location}: ${parsed.error.message}`));
|
|
111
|
+
return parseConfig(parsed.data, root, location);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Validates an already parsed configuration value against {@link CONFIG_SCHEMA} and the project
|
|
115
|
+
* boundary. Messages read `<file>: <key path>: <problem>`, one per line.
|
|
116
|
+
*
|
|
117
|
+
* @param value - The parsed file, or `{}` for a project without one.
|
|
118
|
+
* @param root - The project root every configured path resolves against.
|
|
119
|
+
* @param location - The file the value came from, named in every message.
|
|
120
|
+
*/
|
|
121
|
+
export function parseConfig(value, root, location) {
|
|
122
|
+
let label = location ?? "configuration";
|
|
123
|
+
let checked = s.parseSafe(CONFIG_SCHEMA, value);
|
|
124
|
+
if (!checked.success) {
|
|
125
|
+
let lines = checked.issues.map((issue) => {
|
|
126
|
+
let key = (issue.path ?? []).map(pathSegment).join(".");
|
|
127
|
+
return `${label}: ${key === "" ? "(root)" : key}: ${issue.message}`;
|
|
128
|
+
});
|
|
129
|
+
return failure(new Error(lines.join("\n")));
|
|
130
|
+
}
|
|
131
|
+
let config = checked.value;
|
|
132
|
+
let outside = [];
|
|
133
|
+
for (let [key, configured] of configuredPaths(config)) {
|
|
134
|
+
let resolved = resolveInside(root, configured);
|
|
135
|
+
if (isFailure(resolved))
|
|
136
|
+
outside.push(`${label}: ${key}: ${resolved.error.message}`);
|
|
137
|
+
}
|
|
138
|
+
if (outside.length > 0)
|
|
139
|
+
return failure(new Error(outside.join("\n")));
|
|
140
|
+
return success({ path: location, config });
|
|
141
|
+
}
|
|
142
|
+
/** Every key whose value is a path in the project, with that path, for the boundary check. */
|
|
143
|
+
function configuredPaths(config) {
|
|
144
|
+
let paths = [
|
|
145
|
+
["ui.directory", config.ui.directory],
|
|
146
|
+
["make.stubs", config.make.stubs],
|
|
147
|
+
["lock", config.lock],
|
|
148
|
+
];
|
|
149
|
+
for (let [chain, folder] of Object.entries(config.make.migrations)) {
|
|
150
|
+
paths.push([`make.migrations.${chain}`, folder]);
|
|
151
|
+
}
|
|
152
|
+
return paths;
|
|
153
|
+
}
|
|
154
|
+
/** One segment of a Standard Schema issue path, which may be a bare key or a `{ key }` record. */
|
|
155
|
+
function pathSegment(segment) {
|
|
156
|
+
return String(typeof segment === "object" ? segment.key : segment);
|
|
157
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `sdxc` command line as a contract: every command, its arguments and its flags, with the
|
|
3
|
+
* prompts that fill them on a terminal. Help, usage errors and each handler's typed
|
|
4
|
+
* `ctx.arguments` and `ctx.flags` all come from this one declaration.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** Route methods `make controller --method` accepts; `form` declares a GET page with a POST action. */
|
|
10
|
+
export declare const METHODS: readonly ["get", "post", "put", "patch", "delete", "form"];
|
|
11
|
+
/** Every command `sdxc` takes. */
|
|
12
|
+
export declare const SDXC_COMMANDS: import("@sdxc/cli").Group<Omit<{
|
|
13
|
+
readonly create: import("@sdxc/cli").Command<{
|
|
14
|
+
readonly directory: import("@sdxc/cli").Argument<string | undefined>;
|
|
15
|
+
}, {
|
|
16
|
+
readonly template: import("@sdxc/cli").ValueFlag<string, true, false, false>;
|
|
17
|
+
readonly git: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
18
|
+
}>;
|
|
19
|
+
readonly init: import("@sdxc/cli").Command<Readonly<Record<string, import("@sdxc/cli").Argument<unknown>>>, {
|
|
20
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
21
|
+
}>;
|
|
22
|
+
readonly make: import("@sdxc/cli").Group<Omit<{
|
|
23
|
+
readonly description: "Write a controller, job, model or other file where the app layout puts it";
|
|
24
|
+
readonly arguments: {
|
|
25
|
+
readonly kind: import("@sdxc/cli").Argument<import("./make/kinds.js").KindName>;
|
|
26
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
27
|
+
};
|
|
28
|
+
readonly flags: {
|
|
29
|
+
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
30
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
31
|
+
};
|
|
32
|
+
readonly tasks: true;
|
|
33
|
+
readonly controller: import("@sdxc/cli").Command<{
|
|
34
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
35
|
+
}, {
|
|
36
|
+
readonly method: import("@sdxc/cli").ValueFlag<"delete" | "get" | "post" | "put" | "patch" | "form", true, false, false>;
|
|
37
|
+
readonly path: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
38
|
+
readonly routes: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
39
|
+
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
40
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
41
|
+
}>;
|
|
42
|
+
readonly middleware: import("@sdxc/cli").Command<{
|
|
43
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
44
|
+
}, {
|
|
45
|
+
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
46
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
47
|
+
}>;
|
|
48
|
+
readonly validator: import("@sdxc/cli").Command<{
|
|
49
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
50
|
+
}, {
|
|
51
|
+
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
52
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
53
|
+
}>;
|
|
54
|
+
readonly job: import("@sdxc/cli").Command<{
|
|
55
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
56
|
+
}, {
|
|
57
|
+
readonly cron: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
58
|
+
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
59
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
60
|
+
}>;
|
|
61
|
+
readonly model: import("@sdxc/cli").Command<{
|
|
62
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
63
|
+
}, {
|
|
64
|
+
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
65
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
66
|
+
}>;
|
|
67
|
+
readonly migration: import("@sdxc/cli").Command<{
|
|
68
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
69
|
+
}, {
|
|
70
|
+
readonly chain: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
71
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
72
|
+
}>;
|
|
73
|
+
readonly factory: import("@sdxc/cli").Command<{
|
|
74
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
75
|
+
}, {
|
|
76
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
77
|
+
}>;
|
|
78
|
+
readonly service: import("@sdxc/cli").Command<{
|
|
79
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
80
|
+
}, {
|
|
81
|
+
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
82
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
83
|
+
}>;
|
|
84
|
+
readonly policy: import("@sdxc/cli").Command<{
|
|
85
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
86
|
+
}, {
|
|
87
|
+
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
88
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
89
|
+
}>;
|
|
90
|
+
readonly initializer: import("@sdxc/cli").Command<{
|
|
91
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
92
|
+
}, {
|
|
93
|
+
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
94
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
95
|
+
}>;
|
|
96
|
+
readonly email: import("@sdxc/cli").Command<{
|
|
97
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
98
|
+
}, {
|
|
99
|
+
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
100
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
101
|
+
}>;
|
|
102
|
+
readonly mcp: import("@sdxc/cli").Command<{
|
|
103
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
104
|
+
}, {
|
|
105
|
+
readonly resource: import("@sdxc/cli").Flag<boolean>;
|
|
106
|
+
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
107
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
108
|
+
}>;
|
|
109
|
+
readonly command: import("@sdxc/cli").Command<{
|
|
110
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
111
|
+
}, {
|
|
112
|
+
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
113
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
114
|
+
}>;
|
|
115
|
+
readonly stubs: import("@sdxc/cli").Command<{
|
|
116
|
+
readonly kinds: import("@sdxc/cli").Argument<import("./make/kinds.js").KindName[]>;
|
|
117
|
+
}, Readonly<Record<string, import("@sdxc/cli").Flag<unknown>>>>;
|
|
118
|
+
}, "description" | "hidden" | "arguments" | "flags" | "tasks">, {
|
|
119
|
+
readonly kind: import("@sdxc/cli").Argument<import("./make/kinds.js").KindName>;
|
|
120
|
+
readonly name: import("@sdxc/cli").Argument<string>;
|
|
121
|
+
}, {
|
|
122
|
+
readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
|
|
123
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
124
|
+
}>;
|
|
125
|
+
readonly run: import("@sdxc/cli").Command<{
|
|
126
|
+
readonly args: import("@sdxc/cli").Argument<string[]>;
|
|
127
|
+
}, Readonly<Record<string, import("@sdxc/cli").Flag<unknown>>>>;
|
|
128
|
+
readonly ui: import("@sdxc/cli").Group<Omit<{
|
|
129
|
+
readonly description: "Copy @sdxc/ui components into the project and keep imports on the copies";
|
|
130
|
+
readonly list: import("@sdxc/cli").Command<Readonly<Record<string, import("@sdxc/cli").Argument<unknown>>>, Readonly<Record<string, import("@sdxc/cli").Flag<unknown>>>>;
|
|
131
|
+
readonly add: import("@sdxc/cli").Command<{
|
|
132
|
+
readonly components: import("@sdxc/cli").Argument<string[]>;
|
|
133
|
+
}, {
|
|
134
|
+
readonly withDeps: import("@sdxc/cli").Flag<boolean>;
|
|
135
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
136
|
+
}>;
|
|
137
|
+
readonly diff: import("@sdxc/cli").Command<{
|
|
138
|
+
readonly component: import("@sdxc/cli").Argument<string>;
|
|
139
|
+
}, Readonly<Record<string, import("@sdxc/cli").Flag<unknown>>>>;
|
|
140
|
+
readonly update: import("@sdxc/cli").Command<{
|
|
141
|
+
readonly components: import("@sdxc/cli").Argument<[string, ...string[]]>;
|
|
142
|
+
}, {
|
|
143
|
+
readonly force: import("@sdxc/cli").Flag<boolean>;
|
|
144
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
145
|
+
}>;
|
|
146
|
+
readonly remove: import("@sdxc/cli").Command<{
|
|
147
|
+
readonly components: import("@sdxc/cli").Argument<string[]>;
|
|
148
|
+
}, {
|
|
149
|
+
readonly dryRun: import("@sdxc/cli").Flag<boolean>;
|
|
150
|
+
}>;
|
|
151
|
+
}, "description" | "hidden" | "arguments" | "flags" | "tasks">, Record<never, never>, Record<never, never>>;
|
|
152
|
+
readonly upgrade: import("@sdxc/cli").Command<{
|
|
153
|
+
readonly version: import("@sdxc/cli").Argument<string | undefined>;
|
|
154
|
+
}, {
|
|
155
|
+
readonly install: import("@sdxc/cli").Flag<boolean>;
|
|
156
|
+
readonly output: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
157
|
+
readonly prompt: import("@sdxc/cli").Flag<boolean>;
|
|
158
|
+
readonly from: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
159
|
+
readonly remixFrom: import("@sdxc/cli").ValueFlag<string, false, false, false>;
|
|
160
|
+
}>;
|
|
161
|
+
}, "description" | "hidden" | "arguments" | "flags" | "tasks">, Record<never, never>, Record<never, never>>;
|
package/dist/contract.js
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `sdxc` command line as a contract: every command, its arguments and its flags, with the
|
|
3
|
+
* prompts that fill them on a terminal. Help, usage errors and each handler's typed
|
|
4
|
+
* `ctx.arguments` and `ctx.flags` all come from this one declaration.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { argument, command, commands, flag, prompt } from "@sdxc/cli";
|
|
10
|
+
import * as s from "remix/data-schema";
|
|
11
|
+
import { BUILTIN_TEMPLATES, DEFAULT_TEMPLATE } from "./create/templates.js";
|
|
12
|
+
import { KINDS } from "./make/kinds.js";
|
|
13
|
+
/** Route methods `make controller --method` accepts; `form` declares a GET page with a POST action. */
|
|
14
|
+
export const METHODS = ["get", "post", "put", "patch", "delete", "form"];
|
|
15
|
+
/** Every kind `sdxc make` writes, in the order its help lists them. */
|
|
16
|
+
const KIND_NAMES = Object.keys(KINDS);
|
|
17
|
+
/** Text that holds at least one character, so an empty answer keeps a prompt open. */
|
|
18
|
+
function nonEmpty(message) {
|
|
19
|
+
return s.string().refine((value) => value.trim() !== "", message);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The `<name>` of a `make` kind, asked for on a terminal when it is left out.
|
|
23
|
+
*
|
|
24
|
+
* @param kind - The kind, as the question names it
|
|
25
|
+
* @param placeholder - An example name, shown dimmed while the answer is empty
|
|
26
|
+
*/
|
|
27
|
+
function nameArgument(kind, placeholder) {
|
|
28
|
+
return argument(nonEmpty("Name it"), {
|
|
29
|
+
description: "The file's name; a slash makes a folder inside the kind's folder",
|
|
30
|
+
prompt: prompt.text({ message: `What should the ${kind} be called?`, placeholder }),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `--test` / `--no-test`, shared by every kind that writes a test beside its file; unset, it
|
|
35
|
+
* takes `make.tests`.
|
|
36
|
+
*/
|
|
37
|
+
const TEST_FLAG = flag.boolean("test", {
|
|
38
|
+
default: undefined,
|
|
39
|
+
description: "Write a test beside the file, or skip it with --no-test (default: make.tests)",
|
|
40
|
+
});
|
|
41
|
+
/** `--dry-run`, shared by every command that can print what it would write instead. */
|
|
42
|
+
const DRY_RUN_FLAG = flag.boolean("dry-run", {
|
|
43
|
+
description: "Print what would be written and change nothing",
|
|
44
|
+
});
|
|
45
|
+
/** Every command `sdxc` takes. */
|
|
46
|
+
export const SDXC_COMMANDS = commands({
|
|
47
|
+
create: command({
|
|
48
|
+
description: "Write a new project from a built-in template or a GitHub repository",
|
|
49
|
+
arguments: {
|
|
50
|
+
directory: argument(nonEmpty("Name a directory, or . for this one"), {
|
|
51
|
+
optional: true,
|
|
52
|
+
description: "Where to write it, missing or empty apart from .git; the current directory when left out",
|
|
53
|
+
prompt: prompt.text({ message: "Where should the project go?", placeholder: "my-app" }),
|
|
54
|
+
}),
|
|
55
|
+
},
|
|
56
|
+
flags: {
|
|
57
|
+
template: flag.string("template", {
|
|
58
|
+
default: DEFAULT_TEMPLATE,
|
|
59
|
+
valueName: "template",
|
|
60
|
+
description: "A built-in template, or a GitHub repository as org/repo[/path][#ref]",
|
|
61
|
+
prompt: prompt.select({
|
|
62
|
+
message: "Which template?",
|
|
63
|
+
options: BUILTIN_TEMPLATES,
|
|
64
|
+
ask: "always",
|
|
65
|
+
}),
|
|
66
|
+
}),
|
|
67
|
+
git: flag.boolean("git", {
|
|
68
|
+
default: undefined,
|
|
69
|
+
description: "Initialize a git repository without asking, or skip it with --no-git",
|
|
70
|
+
}),
|
|
71
|
+
},
|
|
72
|
+
tasks: true,
|
|
73
|
+
examples: ["create blog", "create blog --template org/repo/apps/blog#main --no-git"],
|
|
74
|
+
}),
|
|
75
|
+
init: command({
|
|
76
|
+
description: "Write .config/sdxc.jsonc with every default spelled out",
|
|
77
|
+
flags: { dryRun: flag.boolean("dry-run", { description: "Print it and write nothing" }) },
|
|
78
|
+
}),
|
|
79
|
+
make: commands({
|
|
80
|
+
description: "Write a controller, job, model or other file where the app layout puts it",
|
|
81
|
+
arguments: {
|
|
82
|
+
kind: argument(s.enum_(KIND_NAMES), {
|
|
83
|
+
description: "What to write; each kind is also a command with its own flags",
|
|
84
|
+
prompt: prompt.select({ message: "What should sdxc make?", options: KIND_NAMES }),
|
|
85
|
+
}),
|
|
86
|
+
name: argument(nonEmpty("Name it"), {
|
|
87
|
+
description: "The file's name; a slash makes a folder inside the kind's folder",
|
|
88
|
+
prompt: prompt.text({ message: "What should it be called?" }),
|
|
89
|
+
}),
|
|
90
|
+
},
|
|
91
|
+
flags: { test: TEST_FLAG, dryRun: DRY_RUN_FLAG },
|
|
92
|
+
tasks: true,
|
|
93
|
+
controller: command({
|
|
94
|
+
description: "A route handler in app/http/controllers, declared and mapped",
|
|
95
|
+
tasks: true,
|
|
96
|
+
arguments: { name: nameArgument("controller", "admin/users") },
|
|
97
|
+
flags: {
|
|
98
|
+
method: flag.string("method", {
|
|
99
|
+
default: "get",
|
|
100
|
+
valueName: "method",
|
|
101
|
+
schema: s.enum_(METHODS),
|
|
102
|
+
description: METHODS.join(", "),
|
|
103
|
+
prompt: prompt.select({ message: "Which method?", options: METHODS, ask: "always" }),
|
|
104
|
+
}),
|
|
105
|
+
path: flag.string("path", {
|
|
106
|
+
valueName: "path",
|
|
107
|
+
description: "The route's pattern (default: /<name>)",
|
|
108
|
+
}),
|
|
109
|
+
routes: flag.string("routes", {
|
|
110
|
+
valueName: "contract",
|
|
111
|
+
description: "The route contract in routes/ (default: make.routes)",
|
|
112
|
+
}),
|
|
113
|
+
test: TEST_FLAG,
|
|
114
|
+
dryRun: DRY_RUN_FLAG,
|
|
115
|
+
},
|
|
116
|
+
examples: ["make controller ping --method post --path /api/ping"],
|
|
117
|
+
}),
|
|
118
|
+
middleware: command({
|
|
119
|
+
description: "A middleware in app/http/middleware",
|
|
120
|
+
tasks: true,
|
|
121
|
+
arguments: { name: nameArgument("middleware", "require-user") },
|
|
122
|
+
flags: { test: TEST_FLAG, dryRun: DRY_RUN_FLAG },
|
|
123
|
+
}),
|
|
124
|
+
validator: command({
|
|
125
|
+
description: "An input validator in app/http/validators",
|
|
126
|
+
tasks: true,
|
|
127
|
+
arguments: { name: nameArgument("validator", "signup") },
|
|
128
|
+
flags: { test: TEST_FLAG, dryRun: DRY_RUN_FLAG },
|
|
129
|
+
}),
|
|
130
|
+
job: command({
|
|
131
|
+
description: "A background job in app/jobs, declared and mapped",
|
|
132
|
+
tasks: true,
|
|
133
|
+
arguments: { name: nameArgument("job", "trials/expire") },
|
|
134
|
+
flags: {
|
|
135
|
+
cron: flag.string("cron", {
|
|
136
|
+
valueName: "expression",
|
|
137
|
+
description: "A scheduled job instead of one with input",
|
|
138
|
+
}),
|
|
139
|
+
test: TEST_FLAG,
|
|
140
|
+
dryRun: DRY_RUN_FLAG,
|
|
141
|
+
},
|
|
142
|
+
examples: ['make job digest --cron "0 8 * * *"'],
|
|
143
|
+
}),
|
|
144
|
+
model: command({
|
|
145
|
+
description: "A model in app/models",
|
|
146
|
+
tasks: true,
|
|
147
|
+
arguments: { name: nameArgument("model", "post") },
|
|
148
|
+
flags: { test: TEST_FLAG, dryRun: DRY_RUN_FLAG },
|
|
149
|
+
}),
|
|
150
|
+
migration: command({
|
|
151
|
+
description: "A numbered SQL migration in a configured chain",
|
|
152
|
+
tasks: true,
|
|
153
|
+
arguments: { name: nameArgument("migration", "create-posts") },
|
|
154
|
+
flags: {
|
|
155
|
+
chain: flag.string("chain", {
|
|
156
|
+
valueName: "chain",
|
|
157
|
+
description: "The chain in make.migrations (default: default)",
|
|
158
|
+
}),
|
|
159
|
+
dryRun: DRY_RUN_FLAG,
|
|
160
|
+
},
|
|
161
|
+
}),
|
|
162
|
+
factory: command({
|
|
163
|
+
description: "A test factory in database/factories",
|
|
164
|
+
tasks: true,
|
|
165
|
+
arguments: { name: nameArgument("factory", "post") },
|
|
166
|
+
flags: { dryRun: DRY_RUN_FLAG },
|
|
167
|
+
}),
|
|
168
|
+
service: command({
|
|
169
|
+
description: "A service in app/services",
|
|
170
|
+
tasks: true,
|
|
171
|
+
arguments: { name: nameArgument("service", "billing/charge") },
|
|
172
|
+
flags: { test: TEST_FLAG, dryRun: DRY_RUN_FLAG },
|
|
173
|
+
}),
|
|
174
|
+
policy: command({
|
|
175
|
+
description: "An authorization policy in app/policies",
|
|
176
|
+
tasks: true,
|
|
177
|
+
arguments: { name: nameArgument("policy", "can-edit") },
|
|
178
|
+
flags: { test: TEST_FLAG, dryRun: DRY_RUN_FLAG },
|
|
179
|
+
}),
|
|
180
|
+
initializer: command({
|
|
181
|
+
description: "An initializer in app/initializers",
|
|
182
|
+
tasks: true,
|
|
183
|
+
arguments: { name: nameArgument("initializer", "cache") },
|
|
184
|
+
flags: { test: TEST_FLAG, dryRun: DRY_RUN_FLAG },
|
|
185
|
+
}),
|
|
186
|
+
email: command({
|
|
187
|
+
description: "An email template in app/emails",
|
|
188
|
+
tasks: true,
|
|
189
|
+
arguments: { name: nameArgument("email", "welcome") },
|
|
190
|
+
flags: { test: TEST_FLAG, dryRun: DRY_RUN_FLAG },
|
|
191
|
+
}),
|
|
192
|
+
mcp: command({
|
|
193
|
+
description: "An MCP tool in app/mcp/tools, or a resource, declared and mapped",
|
|
194
|
+
tasks: true,
|
|
195
|
+
arguments: { name: nameArgument("tool", "get-post") },
|
|
196
|
+
flags: {
|
|
197
|
+
resource: flag.boolean("resource", {
|
|
198
|
+
description: "A resource in app/mcp/resources instead of a tool",
|
|
199
|
+
}),
|
|
200
|
+
test: TEST_FLAG,
|
|
201
|
+
dryRun: DRY_RUN_FLAG,
|
|
202
|
+
},
|
|
203
|
+
}),
|
|
204
|
+
command: command({
|
|
205
|
+
description: "A command-line command in app/commands, declared and mapped",
|
|
206
|
+
tasks: true,
|
|
207
|
+
arguments: { name: nameArgument("command", "users/grant") },
|
|
208
|
+
flags: { test: TEST_FLAG, dryRun: DRY_RUN_FLAG },
|
|
209
|
+
examples: ["make command users/grant"],
|
|
210
|
+
}),
|
|
211
|
+
stubs: command({
|
|
212
|
+
description: "Copy the built-in stubs into make.stubs to edit",
|
|
213
|
+
arguments: {
|
|
214
|
+
kinds: argument.variadic(s.enum_(KIND_NAMES), {
|
|
215
|
+
valueName: "kind",
|
|
216
|
+
description: "The kinds whose stubs to copy; every kind when left out",
|
|
217
|
+
}),
|
|
218
|
+
},
|
|
219
|
+
}),
|
|
220
|
+
}),
|
|
221
|
+
run: command({
|
|
222
|
+
description: "Run the project's own command line, bootstrap/cli.ts, with its runtime",
|
|
223
|
+
arguments: {
|
|
224
|
+
args: argument.rest({
|
|
225
|
+
valueName: "command",
|
|
226
|
+
description: "The app's command and its arguments, passed through as typed",
|
|
227
|
+
}),
|
|
228
|
+
},
|
|
229
|
+
examples: ["run users find ada@example.com --limit 5", "run --help"],
|
|
230
|
+
}),
|
|
231
|
+
ui: commands({
|
|
232
|
+
description: "Copy @sdxc/ui components into the project and keep imports on the copies",
|
|
233
|
+
list: command({ description: "Every component, marking copies that are edited or behind" }),
|
|
234
|
+
add: command({
|
|
235
|
+
description: "Copy components and point the project's imports at the copies",
|
|
236
|
+
tasks: true,
|
|
237
|
+
arguments: {
|
|
238
|
+
components: argument.variadic(s.string(), {
|
|
239
|
+
valueName: "component",
|
|
240
|
+
description: "The components to copy; asked for on a terminal when left out",
|
|
241
|
+
}),
|
|
242
|
+
},
|
|
243
|
+
flags: {
|
|
244
|
+
withDeps: flag.boolean("with-deps", {
|
|
245
|
+
description: "Also copy every component they reach through others",
|
|
246
|
+
}),
|
|
247
|
+
dryRun: DRY_RUN_FLAG,
|
|
248
|
+
},
|
|
249
|
+
}),
|
|
250
|
+
diff: command({
|
|
251
|
+
description: "Show how a copy differs from the installed version",
|
|
252
|
+
arguments: { component: argument(s.string()) },
|
|
253
|
+
}),
|
|
254
|
+
update: command({
|
|
255
|
+
description: "Replace copied files with the installed version",
|
|
256
|
+
tasks: true,
|
|
257
|
+
arguments: {
|
|
258
|
+
components: argument.variadic(s.string(), { min: 1, valueName: "component" }),
|
|
259
|
+
},
|
|
260
|
+
flags: {
|
|
261
|
+
force: flag.boolean("force", { description: "Replace edited files without asking" }),
|
|
262
|
+
dryRun: DRY_RUN_FLAG,
|
|
263
|
+
},
|
|
264
|
+
}),
|
|
265
|
+
remove: command({
|
|
266
|
+
description: "Delete copies and point imports back at @sdxc/ui/<name>",
|
|
267
|
+
tasks: true,
|
|
268
|
+
arguments: {
|
|
269
|
+
components: argument.variadic(s.string(), {
|
|
270
|
+
valueName: "component",
|
|
271
|
+
description: "The copies to delete; asked for on a terminal when left out",
|
|
272
|
+
}),
|
|
273
|
+
},
|
|
274
|
+
flags: { dryRun: DRY_RUN_FLAG },
|
|
275
|
+
}),
|
|
276
|
+
}),
|
|
277
|
+
upgrade: command({
|
|
278
|
+
description: "Move the @sdxc packages to another release and print the prompt for the code",
|
|
279
|
+
tasks: true,
|
|
280
|
+
arguments: {
|
|
281
|
+
version: argument(s.string(), {
|
|
282
|
+
optional: true,
|
|
283
|
+
description: "The release to move to, a date such as 2026.10.14; the latest when left out",
|
|
284
|
+
}),
|
|
285
|
+
},
|
|
286
|
+
flags: {
|
|
287
|
+
install: flag.boolean("install", {
|
|
288
|
+
default: true,
|
|
289
|
+
description: "Change package.json only and print the commands to run next",
|
|
290
|
+
}),
|
|
291
|
+
output: flag.string("output", {
|
|
292
|
+
valueName: "file",
|
|
293
|
+
description: "Write the prompt to a file instead of stdout",
|
|
294
|
+
}),
|
|
295
|
+
prompt: flag.boolean("prompt", {
|
|
296
|
+
description: "Print the prompt for this release of @sdxc/kit only; needs --from",
|
|
297
|
+
}),
|
|
298
|
+
from: flag.string("from", {
|
|
299
|
+
valueName: "version",
|
|
300
|
+
description: "The release the project moved from, with --prompt",
|
|
301
|
+
}),
|
|
302
|
+
remixFrom: flag.string("remix-from", {
|
|
303
|
+
valueName: "version",
|
|
304
|
+
description: "The remix version the project moved from, with --prompt",
|
|
305
|
+
}),
|
|
306
|
+
},
|
|
307
|
+
}),
|
|
308
|
+
});
|