@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.
- package/LICENSE.md +21 -0
- package/README.md +92 -2
- package/changelog.jsonl +1040 -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 +62 -0
- package/dist/make/generate.js +154 -0
- package/dist/make/imports.d.ts +43 -0
- package/dist/make/imports.js +105 -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 +41 -0
- package/dist/make/migrations.js +116 -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 +50 -0
- package/dist/testing.js +129 -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 +44 -5
- package/registry/ui/accordion.json +15 -0
- package/registry/ui/alert-dialog.json +20 -0
- package/registry/ui/alert.json +15 -0
- package/registry/ui/aspect-ratio.json +13 -0
- package/registry/ui/attachment.json +15 -0
- package/registry/ui/avatar.json +15 -0
- package/registry/ui/badge.json +13 -0
- package/registry/ui/breadcrumbs.json +15 -0
- package/registry/ui/bubble.json +13 -0
- package/registry/ui/button.json +16 -0
- package/registry/ui/calendar.json +16 -0
- package/registry/ui/card.json +18 -0
- package/registry/ui/carousel.json +15 -0
- package/registry/ui/chart.json +13 -0
- package/registry/ui/checkbox-group.json +13 -0
- package/registry/ui/checkbox.json +16 -0
- package/registry/ui/color-area.json +13 -0
- package/registry/ui/color-field.json +20 -0
- package/registry/ui/color-picker.json +17 -0
- package/registry/ui/color-slider.json +13 -0
- package/registry/ui/color-swatch-picker.json +15 -0
- package/registry/ui/color-swatch.json +13 -0
- package/registry/ui/color-wheel.json +13 -0
- package/registry/ui/combobox.json +15 -0
- package/registry/ui/command.json +13 -0
- package/registry/ui/confirm.json +19 -0
- package/registry/ui/context-menu.json +16 -0
- package/registry/ui/date-field.json +19 -0
- package/registry/ui/date-picker.json +15 -0
- package/registry/ui/date-range-picker.json +16 -0
- package/registry/ui/description.json +13 -0
- package/registry/ui/dialog.json +19 -0
- package/registry/ui/disclosure.json +18 -0
- package/registry/ui/drawer.json +18 -0
- package/registry/ui/drop-indicator.json +13 -0
- package/registry/ui/drop-zone.json +13 -0
- package/registry/ui/empty.json +15 -0
- package/registry/ui/field-error.json +13 -0
- package/registry/ui/file-trigger.json +13 -0
- package/registry/ui/form.json +21 -0
- package/registry/ui/grid-list.json +18 -0
- package/registry/ui/group.json +13 -0
- package/registry/ui/header.json +13 -0
- package/registry/ui/heading-scope.json +20 -0
- package/registry/ui/heading.json +15 -0
- package/registry/ui/highlight.json +16 -0
- package/registry/ui/hover-card.json +13 -0
- package/registry/ui/image-placeholder.json +16 -0
- package/registry/ui/input.json +13 -0
- package/registry/ui/item.json +13 -0
- package/registry/ui/keyboard.json +13 -0
- package/registry/ui/label.json +13 -0
- package/registry/ui/link-button.json +16 -0
- package/registry/ui/link.json +13 -0
- package/registry/ui/listbox.json +15 -0
- package/registry/ui/logo.json +15 -0
- package/registry/ui/marker.json +13 -0
- package/registry/ui/menu.json +19 -0
- package/registry/ui/menubar.json +13 -0
- package/registry/ui/message-scroller.json +16 -0
- package/registry/ui/message.json +13 -0
- package/registry/ui/meter.json +13 -0
- package/registry/ui/modal.json +15 -0
- package/registry/ui/nav-link.json +13 -0
- package/registry/ui/navigation-menu.json +15 -0
- package/registry/ui/number-field.json +15 -0
- package/registry/ui/otp-field.json +15 -0
- package/registry/ui/overlay-arrow.json +13 -0
- package/registry/ui/pagination.json +16 -0
- package/registry/ui/popover.json +13 -0
- package/registry/ui/progress-bar.json +13 -0
- package/registry/ui/radio-group.json +13 -0
- package/registry/ui/range-calendar.json +16 -0
- package/registry/ui/resizable.json +13 -0
- package/registry/ui/scroll-area.json +13 -0
- package/registry/ui/search-field.json +16 -0
- package/registry/ui/section.json +13 -0
- package/registry/ui/select.json +13 -0
- package/registry/ui/selection-indicator.json +13 -0
- package/registry/ui/sentinel-row.json +16 -0
- package/registry/ui/separator.json +13 -0
- package/registry/ui/shared-element.json +13 -0
- package/registry/ui/sheet.json +15 -0
- package/registry/ui/shortcut-list.json +18 -0
- package/registry/ui/sidebar.json +20 -0
- package/registry/ui/skeleton.json +13 -0
- package/registry/ui/slider.json +16 -0
- package/registry/ui/spinner.json +13 -0
- package/registry/ui/switch.json +16 -0
- package/registry/ui/table.json +16 -0
- package/registry/ui/tabs.json +17 -0
- package/registry/ui/tag-group.json +18 -0
- package/registry/ui/text-field.json +19 -0
- package/registry/ui/text.json +13 -0
- package/registry/ui/textarea.json +13 -0
- package/registry/ui/time-field.json +19 -0
- package/registry/ui/toast.json +16 -0
- package/registry/ui/toggle-button.json +17 -0
- package/registry/ui/toolbar.json +13 -0
- package/registry/ui/tooltip.json +16 -0
- package/registry/ui/tree.json +18 -0
- package/registry/ui/typeset.json +16 -0
- package/registry/ui/youtube-embed.json +16 -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
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps a project's `package.json` listing every `@sdxc/*` package its generated code imports:
|
|
3
|
+
* a package missing from it is added at the project's own release, so code `sdxc make` writes
|
|
4
|
+
* installs beside packages of the same day and never pulls a newer one in on its own.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { findModuleReferences } from "@sdxc/codemod";
|
|
12
|
+
import { failure, isFailure, success, wrap } from "@sdxc/result";
|
|
13
|
+
import { projectRelease, resolveRelease, scopedPackageOf } from "./releases.js";
|
|
14
|
+
/** The `package.json` sections that count as listing a package. */
|
|
15
|
+
const LISTING_FIELDS = [
|
|
16
|
+
"dependencies",
|
|
17
|
+
"devDependencies",
|
|
18
|
+
"optionalDependencies",
|
|
19
|
+
"peerDependencies",
|
|
20
|
+
];
|
|
21
|
+
/** Every `@sdxc/*` package `files` import, statically or dynamically, sorted. */
|
|
22
|
+
export function importedPackages(files) {
|
|
23
|
+
let names = new Set();
|
|
24
|
+
for (let file of files) {
|
|
25
|
+
let references = findModuleReferences(file.path, file.content);
|
|
26
|
+
if (isFailure(references))
|
|
27
|
+
continue;
|
|
28
|
+
for (let { specifier } of references.data) {
|
|
29
|
+
let name = scopedPackageOf(specifier);
|
|
30
|
+
if (name !== null)
|
|
31
|
+
names.add(name);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return [...names].sort();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The edit adding to the project at `root` every `@sdxc/*` package `files` import that its
|
|
38
|
+
* `package.json` does not list, each at its newest version on or before the project's release,
|
|
39
|
+
* the newest date among its `@sdxc/*` pins, or at `latest` when it pins none. `null` when
|
|
40
|
+
* nothing is missing.
|
|
41
|
+
*/
|
|
42
|
+
export async function missingDependencies(root, files, signal) {
|
|
43
|
+
let before = await wrap(() => readFile(join(root, "package.json"), "utf8"));
|
|
44
|
+
if (isFailure(before))
|
|
45
|
+
return before;
|
|
46
|
+
let manifest = wrap(() => JSON.parse(before.data));
|
|
47
|
+
if (isFailure(manifest)) {
|
|
48
|
+
return failure(new Error(`package.json: ${manifest.error.message}`));
|
|
49
|
+
}
|
|
50
|
+
let sections = LISTING_FIELDS.map((field) => section(manifest.data[field]));
|
|
51
|
+
let listed = new Set(sections.flatMap((entries) => Object.keys(entries)));
|
|
52
|
+
let missing = importedPackages(files).filter((name) => !listed.has(name));
|
|
53
|
+
if (missing.length === 0)
|
|
54
|
+
return success(null);
|
|
55
|
+
let release = projectRelease(sections.slice(0, 3));
|
|
56
|
+
let versions = await resolveRelease(missing, release, signal);
|
|
57
|
+
if (isFailure(versions))
|
|
58
|
+
return versions;
|
|
59
|
+
let dependencies = { ...section(manifest.data.dependencies) };
|
|
60
|
+
for (let [name, version] of versions.data)
|
|
61
|
+
dependencies[name] = version;
|
|
62
|
+
manifest.data.dependencies = Object.fromEntries(Object.entries(dependencies).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
63
|
+
let indent = /^[ \t]+/m.exec(before.data)?.[0] ?? "\t";
|
|
64
|
+
return success({
|
|
65
|
+
path: "package.json",
|
|
66
|
+
before: before.data,
|
|
67
|
+
after: `${JSON.stringify(manifest.data, null, indent)}\n`,
|
|
68
|
+
added: [...versions.data].map(([name, version]) => ({ name, version })),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/** A `package.json` section as a string record, or an empty one when it is missing or malformed. */
|
|
72
|
+
function section(value) {
|
|
73
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
74
|
+
return {};
|
|
75
|
+
return Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === "string"));
|
|
76
|
+
}
|
package/dist/diff.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Line diffs in the unified format `git diff` prints, for `--dry-run` and `sdxc ui diff`: the
|
|
3
|
+
* shortest edit between two texts, grouped into hunks with three lines of context, so a reader
|
|
4
|
+
* sees what a command would change in the shape every review tool already shows.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* The unified diff from `before` to `after`, headed `--- a/<path>` and `+++ b/<path>`, or an
|
|
11
|
+
* empty string when the texts are equal. A `null` side is a file that does not exist, headed
|
|
12
|
+
* `/dev/null` as git heads a created or deleted file.
|
|
13
|
+
*/
|
|
14
|
+
export declare function unifiedDiff(path: string, before: string | null, after: string | null): string;
|
package/dist/diff.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Line diffs in the unified format `git diff` prints, for `--dry-run` and `sdxc ui diff`: the
|
|
3
|
+
* shortest edit between two texts, grouped into hunks with three lines of context, so a reader
|
|
4
|
+
* sees what a command would change in the shape every review tool already shows.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** Lines of unchanged context around each change. */
|
|
10
|
+
const CONTEXT = 3;
|
|
11
|
+
/**
|
|
12
|
+
* The unified diff from `before` to `after`, headed `--- a/<path>` and `+++ b/<path>`, or an
|
|
13
|
+
* empty string when the texts are equal. A `null` side is a file that does not exist, headed
|
|
14
|
+
* `/dev/null` as git heads a created or deleted file.
|
|
15
|
+
*/
|
|
16
|
+
export function unifiedDiff(path, before, after) {
|
|
17
|
+
if (before === after)
|
|
18
|
+
return "";
|
|
19
|
+
let steps = editScript(splitLines(before ?? ""), splitLines(after ?? ""));
|
|
20
|
+
let header = [
|
|
21
|
+
`--- ${before === null ? "/dev/null" : `a/${path}`}`,
|
|
22
|
+
`+++ ${after === null ? "/dev/null" : `b/${path}`}`,
|
|
23
|
+
];
|
|
24
|
+
return [...header, ...hunks(steps)].join("\n") + "\n";
|
|
25
|
+
}
|
|
26
|
+
/** `text` as lines without their terminators; a final newline ends the last line. */
|
|
27
|
+
function splitLines(text) {
|
|
28
|
+
if (text === "")
|
|
29
|
+
return [];
|
|
30
|
+
let lines = text.split("\n");
|
|
31
|
+
if (lines.at(-1) === "")
|
|
32
|
+
lines.pop();
|
|
33
|
+
return lines;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The edit from `a` to `b` through their longest common subsequence, removals before additions
|
|
37
|
+
* within each change, as `diff` orders them.
|
|
38
|
+
*/
|
|
39
|
+
function editScript(a, b) {
|
|
40
|
+
let width = b.length + 1;
|
|
41
|
+
let lengths = new Uint32Array((a.length + 1) * width);
|
|
42
|
+
for (let i = a.length - 1; i >= 0; i--) {
|
|
43
|
+
for (let j = b.length - 1; j >= 0; j--) {
|
|
44
|
+
lengths[i * width + j] =
|
|
45
|
+
a[i] === b[j]
|
|
46
|
+
? (lengths[(i + 1) * width + j + 1] ?? 0) + 1
|
|
47
|
+
: Math.max(lengths[(i + 1) * width + j] ?? 0, lengths[i * width + j + 1] ?? 0);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
let steps = [];
|
|
51
|
+
let i = 0;
|
|
52
|
+
let j = 0;
|
|
53
|
+
while (i < a.length || j < b.length) {
|
|
54
|
+
if (i < a.length && j < b.length && a[i] === b[j]) {
|
|
55
|
+
steps.push({ kind: " ", line: a[i] ?? "" });
|
|
56
|
+
i += 1;
|
|
57
|
+
j += 1;
|
|
58
|
+
}
|
|
59
|
+
else if (j >= b.length ||
|
|
60
|
+
(i < a.length && (lengths[(i + 1) * width + j] ?? 0) >= (lengths[i * width + j + 1] ?? 0))) {
|
|
61
|
+
steps.push({ kind: "-", line: a[i] ?? "" });
|
|
62
|
+
i += 1;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
steps.push({ kind: "+", line: b[j] ?? "" });
|
|
66
|
+
j += 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return steps;
|
|
70
|
+
}
|
|
71
|
+
/** The steps grouped into `@@` hunks, changes closer than twice the context sharing one. */
|
|
72
|
+
function hunks(steps) {
|
|
73
|
+
let output = [];
|
|
74
|
+
let changed = steps.flatMap((step, index) => (step.kind === " " ? [] : [index]));
|
|
75
|
+
let start = 0;
|
|
76
|
+
while (start < changed.length) {
|
|
77
|
+
let end = start;
|
|
78
|
+
while (end + 1 < changed.length &&
|
|
79
|
+
(changed[end + 1] ?? 0) - (changed[end] ?? 0) <= CONTEXT * 2 + 1) {
|
|
80
|
+
end += 1;
|
|
81
|
+
}
|
|
82
|
+
let from = Math.max(0, (changed[start] ?? 0) - CONTEXT);
|
|
83
|
+
let to = Math.min(steps.length, (changed[end] ?? 0) + CONTEXT + 1);
|
|
84
|
+
let oldStart = 1;
|
|
85
|
+
let newStart = 1;
|
|
86
|
+
for (let step of steps.slice(0, from)) {
|
|
87
|
+
if (step.kind !== "+")
|
|
88
|
+
oldStart += 1;
|
|
89
|
+
if (step.kind !== "-")
|
|
90
|
+
newStart += 1;
|
|
91
|
+
}
|
|
92
|
+
let body = steps.slice(from, to);
|
|
93
|
+
let oldCount = body.filter((step) => step.kind !== "+").length;
|
|
94
|
+
let newCount = body.filter((step) => step.kind !== "-").length;
|
|
95
|
+
output.push(`@@ -${range(oldStart, oldCount)} +${range(newStart, newCount)} @@`, ...body.map((step) => `${step.kind}${step.line}`));
|
|
96
|
+
start = end + 1;
|
|
97
|
+
}
|
|
98
|
+
return output;
|
|
99
|
+
}
|
|
100
|
+
/** A hunk range as unified diff writes it: an empty side starts one line earlier. */
|
|
101
|
+
function range(start, count) {
|
|
102
|
+
return `${count === 0 ? start - 1 : start},${count}`;
|
|
103
|
+
}
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the project's `format` command over the files a command wrote or edited, once per
|
|
3
|
+
* command, so generated code lands in the project's own style. The command is an argument list
|
|
4
|
+
* spawned without a shell, so a path is always one argument whatever characters it holds.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { AnyCommandContext } from "@sdxc/cli";
|
|
10
|
+
import type { Result } from "@sdxc/result";
|
|
11
|
+
/**
|
|
12
|
+
* Runs `command` in `root` with `paths` appended as arguments, as a task whose output passes
|
|
13
|
+
* through to the terminal. Without a command or a path nothing runs. A command that cannot start
|
|
14
|
+
* or exits non-zero is a failure that says the files stay as the CLI wrote them.
|
|
15
|
+
*
|
|
16
|
+
* @param ctx - The running command, whose `exec` and `task` run the formatter
|
|
17
|
+
* @param command - The configured `format` value: the program, then its arguments.
|
|
18
|
+
* @param paths - The written and edited files, relative to `root`.
|
|
19
|
+
* @param root - The project root, which the command runs in.
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatFiles(ctx: Pick<AnyCommandContext, "exec" | "task">, command: readonly string[] | undefined, paths: readonly string[], root: string): Promise<Result<void, Error>>;
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the project's `format` command over the files a command wrote or edited, once per
|
|
3
|
+
* command, so generated code lands in the project's own style. The command is an argument list
|
|
4
|
+
* spawned without a shell, so a path is always one argument whatever characters it holds.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { ExecError } from "@sdxc/cli";
|
|
10
|
+
import { failure, isFailure, success } from "@sdxc/result";
|
|
11
|
+
/**
|
|
12
|
+
* Runs `command` in `root` with `paths` appended as arguments, as a task whose output passes
|
|
13
|
+
* through to the terminal. Without a command or a path nothing runs. A command that cannot start
|
|
14
|
+
* or exits non-zero is a failure that says the files stay as the CLI wrote them.
|
|
15
|
+
*
|
|
16
|
+
* @param ctx - The running command, whose `exec` and `task` run the formatter
|
|
17
|
+
* @param command - The configured `format` value: the program, then its arguments.
|
|
18
|
+
* @param paths - The written and edited files, relative to `root`.
|
|
19
|
+
* @param root - The project root, which the command runs in.
|
|
20
|
+
*/
|
|
21
|
+
export async function formatFiles(ctx, command, paths, root) {
|
|
22
|
+
if (command === undefined || command.length === 0 || paths.length === 0) {
|
|
23
|
+
return success(undefined);
|
|
24
|
+
}
|
|
25
|
+
let label = `Formatting ${paths.length === 1 ? "1 file" : `${paths.length} files`}`;
|
|
26
|
+
let ran = await ctx.task(label, (task) => ctx.exec([...command, ...paths], { cwd: root, stdio: "inherit", signal: task.signal }));
|
|
27
|
+
if (!isFailure(ran))
|
|
28
|
+
return success(undefined);
|
|
29
|
+
let error = ran.error;
|
|
30
|
+
if (!(error instanceof ExecError))
|
|
31
|
+
return failure(error);
|
|
32
|
+
let display = command.join(" ");
|
|
33
|
+
if (error.code !== null) {
|
|
34
|
+
return failure(new Error(`format command \`${display}\` exited with ${error.code}; the files stay as written`));
|
|
35
|
+
}
|
|
36
|
+
if (error.cause instanceof Error) {
|
|
37
|
+
return failure(new Error(`format command \`${display}\` could not start: ${error.cause.message}`));
|
|
38
|
+
}
|
|
39
|
+
return failure(new Error(`format command \`${display}\` was stopped by a signal; the files stay as written`));
|
|
40
|
+
}
|
package/dist/init.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc init`: writes `.config/sdxc.jsonc` with every default spelled out, rendered from the
|
|
3
|
+
* configuration schema, so a key added to the schema reaches the output with its description
|
|
4
|
+
* as the comment above it. An existing configuration file is never overwritten.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Result } from "@sdxc/result";
|
|
10
|
+
/** Where `init` writes the configuration, relative to the project root. */
|
|
11
|
+
export declare const INIT_LOCATION: ".config/sdxc.jsonc";
|
|
12
|
+
/**
|
|
13
|
+
* The `$schema` reference that brings editor completion: the schema the latest `@sdxc/kit`
|
|
14
|
+
* publishes, which reaches a project whether or not the kit is installed in it.
|
|
15
|
+
*/
|
|
16
|
+
export declare const SCHEMA_REFERENCE = "https://unpkg.com/@sdxc/kit/config.schema.json";
|
|
17
|
+
/** What `init` did, for the CLI to report. */
|
|
18
|
+
export interface InitOutcome {
|
|
19
|
+
/** The file, relative to the project root. */
|
|
20
|
+
path: string;
|
|
21
|
+
content: string;
|
|
22
|
+
/** `false` under `--dry-run`, when the content was only rendered. */
|
|
23
|
+
written: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Writes the rendered configuration to {@link INIT_LOCATION} in the project at `root`, creating
|
|
27
|
+
* `.config/`. A configuration file at either location is a failure naming it; `dryRun` renders
|
|
28
|
+
* the file and writes nothing.
|
|
29
|
+
*/
|
|
30
|
+
export declare function init(root: string, options: {
|
|
31
|
+
dryRun: boolean;
|
|
32
|
+
}): Promise<Result<InitOutcome, Error>>;
|
|
33
|
+
/**
|
|
34
|
+
* The configuration file `init` writes: `$schema` first, then every key in schema order with
|
|
35
|
+
* its description as a comment. A key with a default is written with it; a key without one is
|
|
36
|
+
* written commented out with its first example.
|
|
37
|
+
*/
|
|
38
|
+
export declare function renderConfig(): Result<string, Error>;
|
package/dist/init.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdxc init`: writes `.config/sdxc.jsonc` with every default spelled out, rendered from the
|
|
3
|
+
* configuration schema, so a key added to the schema reaches the output with its description
|
|
4
|
+
* as the comment above it. An existing configuration file is never overwritten.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
10
|
+
import { dirname, join } from "node:path";
|
|
11
|
+
import { failure, isFailure, success, wrap } from "@sdxc/result";
|
|
12
|
+
import { CONFIG_LOCATIONS, configJSONSchema, findConfigFile } from "./config.js";
|
|
13
|
+
/** Where `init` writes the configuration, relative to the project root. */
|
|
14
|
+
export const INIT_LOCATION = CONFIG_LOCATIONS[0];
|
|
15
|
+
/**
|
|
16
|
+
* The `$schema` reference that brings editor completion: the schema the latest `@sdxc/kit`
|
|
17
|
+
* publishes, which reaches a project whether or not the kit is installed in it.
|
|
18
|
+
*/
|
|
19
|
+
export const SCHEMA_REFERENCE = "https://unpkg.com/@sdxc/kit/config.schema.json";
|
|
20
|
+
/**
|
|
21
|
+
* Writes the rendered configuration to {@link INIT_LOCATION} in the project at `root`, creating
|
|
22
|
+
* `.config/`. A configuration file at either location is a failure naming it; `dryRun` renders
|
|
23
|
+
* the file and writes nothing.
|
|
24
|
+
*/
|
|
25
|
+
export async function init(root, options) {
|
|
26
|
+
let existing = await findConfigFile(root);
|
|
27
|
+
if (isFailure(existing))
|
|
28
|
+
return existing;
|
|
29
|
+
if (existing.data !== null) {
|
|
30
|
+
return failure(new Error(`${existing.data} already exists; sdxc init leaves it as it is`));
|
|
31
|
+
}
|
|
32
|
+
let content = renderConfig();
|
|
33
|
+
if (isFailure(content))
|
|
34
|
+
return content;
|
|
35
|
+
let outcome = { path: INIT_LOCATION, content: content.data, written: false };
|
|
36
|
+
if (options.dryRun)
|
|
37
|
+
return success(outcome);
|
|
38
|
+
let target = join(root, INIT_LOCATION);
|
|
39
|
+
let written = await wrap(async () => {
|
|
40
|
+
await mkdir(dirname(target), { recursive: true });
|
|
41
|
+
await writeFile(target, content.data, { flag: "wx" });
|
|
42
|
+
});
|
|
43
|
+
if (isFailure(written))
|
|
44
|
+
return written;
|
|
45
|
+
return success({ ...outcome, written: true });
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The configuration file `init` writes: `$schema` first, then every key in schema order with
|
|
49
|
+
* its description as a comment. A key with a default is written with it; a key without one is
|
|
50
|
+
* written commented out with its first example.
|
|
51
|
+
*/
|
|
52
|
+
export function renderConfig() {
|
|
53
|
+
let schema = configJSONSchema();
|
|
54
|
+
if (isFailure(schema))
|
|
55
|
+
return schema;
|
|
56
|
+
let lines = ["{", `\t${JSON.stringify("$schema")}: ${JSON.stringify(SCHEMA_REFERENCE)},`];
|
|
57
|
+
renderProperties(schema.data, 1, lines);
|
|
58
|
+
lines.push("}");
|
|
59
|
+
return success(`${lines.join("\n")}\n`);
|
|
60
|
+
}
|
|
61
|
+
/** Appends one line per key of `schema`'s properties, nesting into a group that has its own. */
|
|
62
|
+
function renderProperties(schema, depth, lines) {
|
|
63
|
+
let indent = "\t".repeat(depth);
|
|
64
|
+
for (let [key, property] of Object.entries(schema.properties ?? {})) {
|
|
65
|
+
if (key === "$schema" || typeof property === "boolean")
|
|
66
|
+
continue;
|
|
67
|
+
if (typeof property.description === "string")
|
|
68
|
+
lines.push(`${indent}// ${property.description}`);
|
|
69
|
+
let name = JSON.stringify(key);
|
|
70
|
+
if (property.properties !== undefined) {
|
|
71
|
+
lines.push(`${indent}${name}: {`);
|
|
72
|
+
renderProperties(property, depth + 1, lines);
|
|
73
|
+
lines.push(`${indent}},`);
|
|
74
|
+
}
|
|
75
|
+
else if ("default" in property) {
|
|
76
|
+
lines.push(`${indent}${name}: ${inline(property.default)},`);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
lines.push(`${indent}// ${name}: ${inline(property.examples?.[0] ?? null)},`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** `value` as JSON on one line, with a space after each comma and inside each brace. */
|
|
84
|
+
function inline(value) {
|
|
85
|
+
if (Array.isArray(value))
|
|
86
|
+
return `[${value.map(inline).join(", ")}]`;
|
|
87
|
+
if (typeof value === "object" && value !== null) {
|
|
88
|
+
let entries = Object.entries(value).map(([key, item]) => `${JSON.stringify(key)}: ${inline(item)}`);
|
|
89
|
+
return entries.length === 0 ? "{}" : `{ ${entries.join(", ")} }`;
|
|
90
|
+
}
|
|
91
|
+
return JSON.stringify(value);
|
|
92
|
+
}
|
package/dist/lock.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI's state file: JSON Lines at the configured `lock` path, one entry per line sorted by
|
|
3
|
+
* `kind` then `name`, so every command changes exactly the lines of what it touched. Entries of
|
|
4
|
+
* a kind this CLI does not know are kept byte for byte, so state a newer CLI wrote survives.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { JSONSchema } from "@sdxc/json-schema";
|
|
10
|
+
import type { Result } from "@sdxc/result";
|
|
11
|
+
import * as s from "@sdxc/json-schema";
|
|
12
|
+
import type { Config } from "./config.js";
|
|
13
|
+
/** Where the lock file lives when the configuration does not move it. */
|
|
14
|
+
export declare const DEFAULT_LOCK = ".config/sdxc.lock.jsonl";
|
|
15
|
+
/** A `ui` line: a vendored component, the release it came from and every file written for it. */
|
|
16
|
+
export declare const UI_LOCK_ENTRY: s.Schema<{
|
|
17
|
+
name: string;
|
|
18
|
+
kind: "ui";
|
|
19
|
+
release: string;
|
|
20
|
+
files: Record<string, string>;
|
|
21
|
+
}, {
|
|
22
|
+
name: string;
|
|
23
|
+
kind: "ui";
|
|
24
|
+
release: string;
|
|
25
|
+
files: Record<string, string>;
|
|
26
|
+
}>;
|
|
27
|
+
/** A `ui` entry as the commands read and write it. */
|
|
28
|
+
export type UILockEntry = s.InferOutput<typeof UI_LOCK_ENTRY>;
|
|
29
|
+
/** One line of the file: a known entry parsed, or an unknown kind kept as written. */
|
|
30
|
+
export type LockLine = {
|
|
31
|
+
kind: "ui";
|
|
32
|
+
name: string;
|
|
33
|
+
entry: UILockEntry;
|
|
34
|
+
} | {
|
|
35
|
+
kind: string;
|
|
36
|
+
name: string;
|
|
37
|
+
text: string;
|
|
38
|
+
};
|
|
39
|
+
/** The state file as read: where it is, relative to the project root, and its lines in order. */
|
|
40
|
+
export interface Lock {
|
|
41
|
+
path: string;
|
|
42
|
+
lines: LockLine[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The entry schema as JSON Schema 2020-12, shipped as `lock.schema.json`: every line names its
|
|
46
|
+
* `kind` and `name`, a `ui` line is held to the `ui` entry, and any other kind is accepted.
|
|
47
|
+
*/
|
|
48
|
+
export declare function lockJSONSchema(): Result<JSONSchema, Error>;
|
|
49
|
+
/**
|
|
50
|
+
* The lock file of the project at `root`, empty when there is none yet. A configured location
|
|
51
|
+
* other than the default that is missing while the default exists is a failure naming both, so
|
|
52
|
+
* moving `lock` never starts a second, empty state beside the real one.
|
|
53
|
+
*/
|
|
54
|
+
export declare function readLock(root: string, config: Config): Promise<Result<Lock, Error>>;
|
|
55
|
+
/**
|
|
56
|
+
* The lines of a lock file's `text`. A line that is not JSON, fails its schema, or repeats a
|
|
57
|
+
* `kind` and `name` already seen is a failure naming its line number, and nothing is returned.
|
|
58
|
+
*/
|
|
59
|
+
export declare function parseLock(path: string, text: string): Promise<Result<Lock, Error>>;
|
|
60
|
+
/** Every `ui` entry, in file order. */
|
|
61
|
+
export declare function uiEntries(lock: Lock): UILockEntry[];
|
|
62
|
+
/** The `ui` entry for `name`, or `undefined` when that component is not copied. */
|
|
63
|
+
export declare function uiEntry(lock: Lock, name: string): UILockEntry | undefined;
|
|
64
|
+
/** `lock` with `entry` replacing the line of the same name, or inserted where the order puts it. */
|
|
65
|
+
export declare function setUIEntry(lock: Lock, entry: UILockEntry): Lock;
|
|
66
|
+
/** `lock` without the `ui` line for `name`; every other line is unchanged. */
|
|
67
|
+
export declare function removeUIEntry(lock: Lock, name: string): Lock;
|
|
68
|
+
/**
|
|
69
|
+
* The file's text: one `\n`-terminated line per entry, sorted, known entries with their keys in
|
|
70
|
+
* schema order and unknown ones exactly as read.
|
|
71
|
+
*/
|
|
72
|
+
export declare function renderLock(lock: Lock): Result<string, Error>;
|
|
73
|
+
/** Writes `lock` at its path in `root`, creating its folders; a lock with no lines is removed. */
|
|
74
|
+
export declare function writeLock(root: string, lock: Lock): Promise<Result<void, Error>>;
|