@sdxc/kit 0.0.0-stage → 2026.10.17
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 -2
- package/changelog.jsonl +1097 -0
- package/config.schema.json +89 -0
- package/dist/author.d.ts +36 -0
- package/dist/author.js +107 -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 +169 -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 +53 -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 +69 -0
- package/dist/create/templates.js +251 -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 +40 -0
- package/dist/init.js +100 -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 +598 -0
- package/dist/make/generate.d.ts +62 -0
- package/dist/make/generate.js +160 -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 +140 -0
- package/dist/make/kinds.d.ts +40 -0
- package/dist/make/kinds.js +96 -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 +60 -0
- package/dist/testing.js +148 -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 +16 -0
- package/stubs/command.test.stub +21 -0
- package/stubs/controller.api.stub +21 -0
- package/stubs/controller.api.test.stub +18 -0
- package/stubs/controller.form.stub +63 -0
- package/stubs/controller.form.test.stub +61 -0
- package/stubs/controller.stub +24 -0
- package/stubs/controller.test.stub +18 -0
- package/stubs/email.stub +26 -0
- package/stubs/email.test.stub +21 -0
- package/stubs/factory.stub +13 -0
- package/stubs/initializer.stub +9 -0
- package/stubs/initializer.test.stub +16 -0
- package/stubs/job.cron.stub +16 -0
- package/stubs/job.stub +15 -0
- package/stubs/job.test.stub +18 -0
- package/stubs/mcp.resource.stub +15 -0
- package/stubs/mcp.stub +13 -0
- package/stubs/mcp.test.stub +18 -0
- package/stubs/middleware.stub +16 -0
- package/stubs/middleware.test.stub +16 -0
- package/stubs/migration.stub +1 -0
- package/stubs/model.stub +33 -0
- package/stubs/model.test.stub +18 -0
- package/stubs/policy.stub +16 -0
- package/stubs/policy.test.stub +20 -0
- package/stubs/service.stub +17 -0
- package/stubs/service.test.stub +17 -0
- package/stubs/validator.stub +17 -0
- package/stubs/validator.test.stub +25 -0
- package/templates/app/.env.example +16 -0
- package/templates/app/README.md +84 -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/db/console.ts +6 -0
- package/templates/app/app/commands/db/migrate.test.ts +30 -0
- package/templates/app/app/commands/db/migrate.ts +55 -0
- package/templates/app/app/commands/index.ts +31 -0
- package/templates/app/app/commands/typegen.test.ts +17 -0
- package/templates/app/app/commands/typegen.ts +16 -0
- package/templates/app/app/http/controllers/api/health.tsx +15 -0
- package/templates/app/app/http/controllers/api/not-found.tsx +16 -0
- package/templates/app/app/http/controllers/api/openapi.tsx +17 -0
- package/templates/app/app/http/controllers/home.tsx +30 -0
- package/templates/app/app/http/controllers/mcp.tsx +16 -0
- package/templates/app/app/http/controllers/not-found.tsx +30 -0
- package/templates/app/app/http/controllers/robots.test.ts +18 -0
- package/templates/app/app/http/controllers/robots.ts +24 -0
- package/templates/app/app/http/controllers/sitemap.test.ts +28 -0
- package/templates/app/app/http/controllers/sitemap.ts +25 -0
- package/templates/app/app/http/middleware/api.ts +10 -0
- package/templates/app/app/http/middleware/page.test.ts +40 -0
- package/templates/app/app/http/middleware/page.ts +49 -0
- package/templates/app/app/http/middleware/server-timing.test.ts +15 -0
- package/templates/app/app/http/middleware/server-timing.ts +42 -0
- package/templates/app/app/initializers/assets.ts +11 -0
- package/templates/app/app/initializers/captcha.ts +11 -0
- package/templates/app/app/initializers/cli.ts +75 -0
- package/templates/app/app/initializers/database.test.ts +18 -0
- package/templates/app/app/initializers/database.ts +18 -0
- package/templates/app/app/initializers/dispatcher.ts +36 -0
- package/templates/app/app/initializers/honeypot.ts +11 -0
- package/templates/app/app/initializers/i18n.test.ts +16 -0
- package/templates/app/app/initializers/i18n.ts +28 -0
- package/templates/app/app/initializers/local-database.test.ts +33 -0
- package/templates/app/app/initializers/local-database.ts +53 -0
- package/templates/app/app/initializers/logger.ts +10 -0
- package/templates/app/app/initializers/mail.test.ts +27 -0
- package/templates/app/app/initializers/mail.ts +11 -0
- package/templates/app/app/initializers/mcp.ts +16 -0
- package/templates/app/app/initializers/openapi.ts +21 -0
- package/templates/app/app/initializers/router.test.ts +61 -0
- package/templates/app/app/initializers/router.tsx +111 -0
- package/templates/app/app/initializers/seo.ts +15 -0
- package/templates/app/app/initializers/session.test.ts +34 -0
- package/templates/app/app/initializers/session.ts +29 -0
- package/templates/app/app/initializers/spam.ts +10 -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/app/models/index.ts +10 -0
- package/templates/app/app/services/migrations.test.ts +45 -0
- package/templates/app/app/services/migrations.ts +60 -0
- package/templates/app/app/test/cloudflare-workers.ts +25 -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 +56 -0
- package/templates/app/config/constants.ts +19 -0
- package/templates/app/config/problems.ts +24 -0
- package/templates/app/config/security-policy.ts +34 -0
- package/templates/app/config/security-txt.ts +28 -0
- package/templates/app/database/migrations/.gitkeep +0 -0
- package/templates/app/gitignore +9 -0
- package/templates/app/package.json +68 -0
- package/templates/app/resources/layouts/document.tsx +79 -0
- package/templates/app/resources/locales/en.json +10 -0
- package/templates/app/routes/api.ts +29 -0
- package/templates/app/routes/web.ts +14 -0
- package/templates/app/tsconfig.json +40 -0
- package/templates/app/vite.config.ts +44 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"$schema": {
|
|
6
|
+
"type": "string",
|
|
7
|
+
"description": "The JSON Schema editors check this file against"
|
|
8
|
+
},
|
|
9
|
+
"ui": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"directory": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"default": "resources/components/ui",
|
|
15
|
+
"description": "Where `sdxc ui add` writes components"
|
|
16
|
+
},
|
|
17
|
+
"alias": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"description": "Import prefix for the copies; inferred from tsconfig `paths` when omitted",
|
|
20
|
+
"examples": ["~/components/ui"]
|
|
21
|
+
},
|
|
22
|
+
"tests": {
|
|
23
|
+
"type": "boolean",
|
|
24
|
+
"default": false,
|
|
25
|
+
"description": "Copy a component's tests beside it"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"additionalProperties": false,
|
|
29
|
+
"default": {
|
|
30
|
+
"directory": "resources/components/ui",
|
|
31
|
+
"tests": false
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"make": {
|
|
35
|
+
"type": "object",
|
|
36
|
+
"properties": {
|
|
37
|
+
"routes": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"default": "web",
|
|
40
|
+
"description": "Route contract `sdxc make controller` adds to, a module in routes/"
|
|
41
|
+
},
|
|
42
|
+
"migrations": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"additionalProperties": {
|
|
45
|
+
"type": "string"
|
|
46
|
+
},
|
|
47
|
+
"default": {
|
|
48
|
+
"default": "database/migrations"
|
|
49
|
+
},
|
|
50
|
+
"description": "Migration chains by name; `--chain <name>` picks one"
|
|
51
|
+
},
|
|
52
|
+
"tests": {
|
|
53
|
+
"type": "boolean",
|
|
54
|
+
"default": true,
|
|
55
|
+
"description": "Write a test beside every generated file except migrations and factories"
|
|
56
|
+
},
|
|
57
|
+
"stubs": {
|
|
58
|
+
"type": "string",
|
|
59
|
+
"default": ".config/sdxc/stubs",
|
|
60
|
+
"description": "Stubs here replace the built-in ones; `sdxc make stubs` copies them out"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"additionalProperties": false,
|
|
64
|
+
"default": {
|
|
65
|
+
"routes": "web",
|
|
66
|
+
"migrations": {
|
|
67
|
+
"default": "database/migrations"
|
|
68
|
+
},
|
|
69
|
+
"tests": true,
|
|
70
|
+
"stubs": ".config/sdxc/stubs"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"format": {
|
|
74
|
+
"type": "array",
|
|
75
|
+
"items": {
|
|
76
|
+
"type": "string"
|
|
77
|
+
},
|
|
78
|
+
"minItems": 1,
|
|
79
|
+
"description": "Command run on every file the CLI writes or edits, paths appended",
|
|
80
|
+
"examples": [["bunx", "vp", "fmt"]]
|
|
81
|
+
},
|
|
82
|
+
"lock": {
|
|
83
|
+
"type": "string",
|
|
84
|
+
"default": ".config/sdxc.lock.jsonl",
|
|
85
|
+
"description": "Where the CLI keeps its state; commit it with the project"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"additionalProperties": false
|
|
89
|
+
}
|
package/dist/author.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `@author` and `@copyright` tags closing the module JSDoc of every file `make` and `create`
|
|
3
|
+
* write, credited to the project's package.json `author` or else the git user, so a generated
|
|
4
|
+
* file opens with the header the project's documentation rules ask for.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/** Who a generated file credits; `url` is linked from the `@author` tag when present. */
|
|
10
|
+
export interface Author {
|
|
11
|
+
name: string;
|
|
12
|
+
url: string | null;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Reads a package.json `author` in either npm form: `"Name <email> (url)"`, where the email and
|
|
16
|
+
* url are optional, or `{ name, email, url }`. Anything without a name is `null`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseAuthor(field: unknown): Author | null;
|
|
19
|
+
/**
|
|
20
|
+
* The author of files written under `directory`: the `author` of the nearest package.json from
|
|
21
|
+
* `directory` up to the repository root (the first folder holding `.git`), else `git config
|
|
22
|
+
* user.name` there, else `null`, so a file carries no tags rather than a guessed name.
|
|
23
|
+
* `directory` may not exist yet; the search starts from it all the same.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveAuthor(directory: string): Promise<Author | null>;
|
|
26
|
+
/**
|
|
27
|
+
* The lines a module JSDoc ends with to credit `author`: a blank comment line, `@author` (linked
|
|
28
|
+
* when there is a url) and `@copyright` with the UTC `year`, each led by a newline so the result
|
|
29
|
+
* splices in right before the line that closes the block. With no author it is empty.
|
|
30
|
+
*/
|
|
31
|
+
export declare function headerTags(author: Author | null, year?: number): string;
|
|
32
|
+
/**
|
|
33
|
+
* `source` with `tags` added to the module JSDoc it opens with (after a `#!` line, if any). A
|
|
34
|
+
* file that opens with no JSDoc, or whose JSDoc already has an `@author`, is answered as it is.
|
|
35
|
+
*/
|
|
36
|
+
export declare function addHeaderTags(source: string, tags: string): string;
|
package/dist/author.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `@author` and `@copyright` tags closing the module JSDoc of every file `make` and `create`
|
|
3
|
+
* write, credited to the project's package.json `author` or else the git user, so a generated
|
|
4
|
+
* file opens with the header the project's documentation rules ask for.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { execFile } from "node:child_process";
|
|
10
|
+
import { readFile, stat } from "node:fs/promises";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
import { isFailure, isSuccess, wrap } from "@sdxc/result";
|
|
13
|
+
/**
|
|
14
|
+
* Reads a package.json `author` in either npm form: `"Name <email> (url)"`, where the email and
|
|
15
|
+
* url are optional, or `{ name, email, url }`. Anything without a name is `null`.
|
|
16
|
+
*/
|
|
17
|
+
export function parseAuthor(field) {
|
|
18
|
+
if (typeof field === "string") {
|
|
19
|
+
let match = /^([^<(]*?)\s*(?:<[^>]*>)?\s*(?:\(([^)]*)\))?\s*$/.exec(field.trim());
|
|
20
|
+
let name = match?.[1]?.trim() ?? "";
|
|
21
|
+
if (name === "")
|
|
22
|
+
return null;
|
|
23
|
+
let url = match?.[2]?.trim() ?? "";
|
|
24
|
+
return { name, url: url === "" ? null : url };
|
|
25
|
+
}
|
|
26
|
+
if (typeof field !== "object" || field === null || Array.isArray(field))
|
|
27
|
+
return null;
|
|
28
|
+
let { name, url } = field;
|
|
29
|
+
if (typeof name !== "string" || name.trim() === "")
|
|
30
|
+
return null;
|
|
31
|
+
return {
|
|
32
|
+
name: name.trim(),
|
|
33
|
+
url: typeof url === "string" && url.trim() !== "" ? url.trim() : null,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The author of files written under `directory`: the `author` of the nearest package.json from
|
|
38
|
+
* `directory` up to the repository root (the first folder holding `.git`), else `git config
|
|
39
|
+
* user.name` there, else `null`, so a file carries no tags rather than a guessed name.
|
|
40
|
+
* `directory` may not exist yet; the search starts from it all the same.
|
|
41
|
+
*/
|
|
42
|
+
export async function resolveAuthor(directory) {
|
|
43
|
+
let existing = null;
|
|
44
|
+
for (let current = directory;; current = dirname(current)) {
|
|
45
|
+
let found = await wrap(() => stat(current));
|
|
46
|
+
if (isSuccess(found) && found.data.isDirectory()) {
|
|
47
|
+
existing ??= current;
|
|
48
|
+
let text = await wrap(() => readFile(join(current, "package.json"), "utf8"));
|
|
49
|
+
if (isSuccess(text)) {
|
|
50
|
+
let manifest = wrap(() => JSON.parse(text.data));
|
|
51
|
+
let author = isFailure(manifest) ? null : parseAuthor(manifest.data.author);
|
|
52
|
+
if (author !== null)
|
|
53
|
+
return author;
|
|
54
|
+
}
|
|
55
|
+
if (isSuccess(await wrap(() => stat(join(current, ".git")))))
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
if (dirname(current) === current)
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
if (existing === null)
|
|
62
|
+
return null;
|
|
63
|
+
let name = await gitUserName(existing);
|
|
64
|
+
return name === null ? null : { name, url: null };
|
|
65
|
+
}
|
|
66
|
+
/** `git config user.name` as git resolves it in `cwd`, or `null` when git or the name is missing. */
|
|
67
|
+
function gitUserName(cwd) {
|
|
68
|
+
return new Promise((resolve) => {
|
|
69
|
+
execFile("git", ["config", "user.name"], { cwd }, (error, stdout) => {
|
|
70
|
+
let name = error === null ? stdout.trim() : "";
|
|
71
|
+
resolve(name === "" ? null : name);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The lines a module JSDoc ends with to credit `author`: a blank comment line, `@author` (linked
|
|
77
|
+
* when there is a url) and `@copyright` with the UTC `year`, each led by a newline so the result
|
|
78
|
+
* splices in right before the line that closes the block. With no author it is empty.
|
|
79
|
+
*/
|
|
80
|
+
export function headerTags(author, year = new Date().getUTCFullYear()) {
|
|
81
|
+
if (author === null)
|
|
82
|
+
return "";
|
|
83
|
+
let credit = author.url === null ? author.name : `[${author.name}](${author.url})`;
|
|
84
|
+
return `\n *\n * @author ${credit}\n * @copyright ${author.name} ${year}`;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* `source` with `tags` added to the module JSDoc it opens with (after a `#!` line, if any). A
|
|
88
|
+
* file that opens with no JSDoc, or whose JSDoc already has an `@author`, is answered as it is.
|
|
89
|
+
*/
|
|
90
|
+
export function addHeaderTags(source, tags) {
|
|
91
|
+
if (tags === "")
|
|
92
|
+
return source;
|
|
93
|
+
let start = source.startsWith("#!") ? source.indexOf("\n") + 1 : 0;
|
|
94
|
+
if (!source.startsWith("/**", start))
|
|
95
|
+
return source;
|
|
96
|
+
let end = source.indexOf("*/", start);
|
|
97
|
+
if (end === -1)
|
|
98
|
+
return source;
|
|
99
|
+
let block = source.slice(start, end);
|
|
100
|
+
if (block.includes("@author"))
|
|
101
|
+
return source;
|
|
102
|
+
let close = block.lastIndexOf("\n");
|
|
103
|
+
if (close === -1)
|
|
104
|
+
return source;
|
|
105
|
+
let at = start + close;
|
|
106
|
+
return `${source.slice(0, at)}${tags}${source.slice(at)}`;
|
|
107
|
+
}
|
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,169 @@
|
|
|
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 { headerTags, resolveAuthor } from "../author.js";
|
|
13
|
+
import { SDXC_COMMANDS } from "../contract.js";
|
|
14
|
+
import { describe, downloadTemplate, GitHubRefusal, githubToken } from "../create/github.js";
|
|
15
|
+
import { resolveTarget } from "../create/target.js";
|
|
16
|
+
import { completeBuiltin, creditTemplate, nameProject, parseTemplate, readBuiltinTemplate, writeTree, } from "../create/templates.js";
|
|
17
|
+
import { packageRoot } from "../middleware.js";
|
|
18
|
+
import { packageManager, scriptCommand } from "../package-manager.js";
|
|
19
|
+
/** The middleware `create` runs behind; it runs outside any project. */
|
|
20
|
+
const CREATE_MIDDLEWARE = [packageRoot()];
|
|
21
|
+
/** Creates the project, then initializes git when asked to, then prints the next steps. */
|
|
22
|
+
export default createCommand(SDXC_COMMANDS.create, {
|
|
23
|
+
middleware: CREATE_MIDDLEWARE,
|
|
24
|
+
/** Exits 1 when the target or the template is refused, writing nothing. */
|
|
25
|
+
async handler(ctx) {
|
|
26
|
+
let source = parseTemplate(ctx.flags.template);
|
|
27
|
+
if (isFailure(source))
|
|
28
|
+
return source;
|
|
29
|
+
let target = await resolveTarget(ctx.cwd, ctx.arguments.directory);
|
|
30
|
+
if (isFailure(target))
|
|
31
|
+
return target;
|
|
32
|
+
let fetched = await fetchTemplate(ctx, source.data, target.data.name, target.data.directory);
|
|
33
|
+
if (isFailure(fetched))
|
|
34
|
+
return fetched;
|
|
35
|
+
let written = await writeTree(target.data.directory, fetched.data.tree);
|
|
36
|
+
if (isFailure(written))
|
|
37
|
+
return written;
|
|
38
|
+
let shown = relative(ctx.cwd, target.data.directory);
|
|
39
|
+
ctx.stdout(`Created ${target.data.name} from ${fetched.data.description}\n`);
|
|
40
|
+
if (!target.data.exists && ctx.flags.git !== false) {
|
|
41
|
+
let initialized = await initializeGit(ctx, ctx.flags.git, target.data.directory, shown);
|
|
42
|
+
if (isFailure(initialized))
|
|
43
|
+
return initialized;
|
|
44
|
+
}
|
|
45
|
+
let tree = fetched.data.tree;
|
|
46
|
+
let manager = await packageManager({
|
|
47
|
+
declared: treeManifest(tree)?.packageManager,
|
|
48
|
+
findLockFile: (names) => names.find((name) => tree.files.has(name)) ?? null,
|
|
49
|
+
userAgent: ctx.env.npm_config_user_agent,
|
|
50
|
+
});
|
|
51
|
+
let steps = [];
|
|
52
|
+
if (shown !== "")
|
|
53
|
+
steps.push(`cd ${shown.includes(" ") ? JSON.stringify(shown) : shown}`);
|
|
54
|
+
steps.push(manager.install.join(" "));
|
|
55
|
+
if (hasScript(tree, "dev"))
|
|
56
|
+
steps.push(scriptCommand(manager, "dev"));
|
|
57
|
+
ctx.stdout(`\nNext steps:\n${steps.map((step) => ` ${step}\n`).join("")}`);
|
|
58
|
+
return success();
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* Runs `git init` in the new project when `--git` was passed, or when the user says yes on a
|
|
63
|
+
* terminal, where Enter says yes; without a terminal and without `--git`, no repository is
|
|
64
|
+
* made. A missing `git` is noted and skipped.
|
|
65
|
+
*
|
|
66
|
+
* @param wanted - `--git` or `--no-git`, or `undefined` to ask
|
|
67
|
+
* @param shown - The project directory relative to where the command ran, for the question
|
|
68
|
+
*/
|
|
69
|
+
async function initializeGit(ctx, wanted, directory, shown) {
|
|
70
|
+
let available = await ctx.exec(["git", "--version"], { stdio: "ignore" });
|
|
71
|
+
if (isFailure(available)) {
|
|
72
|
+
ctx.stdout("git is not on the PATH, so no repository was initialized\n");
|
|
73
|
+
return success(undefined);
|
|
74
|
+
}
|
|
75
|
+
if (wanted === undefined) {
|
|
76
|
+
let answer = await ctx.prompt.confirm({
|
|
77
|
+
message: `Initialize a git repository in ${shown}?`,
|
|
78
|
+
default: false,
|
|
79
|
+
initial: true,
|
|
80
|
+
name: "git",
|
|
81
|
+
});
|
|
82
|
+
if (isFailure(answer))
|
|
83
|
+
return answer;
|
|
84
|
+
wanted = answer.data;
|
|
85
|
+
}
|
|
86
|
+
if (!wanted)
|
|
87
|
+
return success(undefined);
|
|
88
|
+
let initialized = await ctx.exec(["git", "init", "--quiet"], {
|
|
89
|
+
cwd: directory,
|
|
90
|
+
stdio: "ignore",
|
|
91
|
+
});
|
|
92
|
+
if (isFailure(initialized)) {
|
|
93
|
+
let code = "code" in initialized.error ? initialized.error.code : null;
|
|
94
|
+
return failure(new Error(`git init exited with ${code ?? "an error"} in ${directory}`));
|
|
95
|
+
}
|
|
96
|
+
ctx.stdout("Initialized a git repository\n");
|
|
97
|
+
return success(undefined);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Reads the template `source` names and completes it for the project `name`. A built-in
|
|
101
|
+
* template's modules credit the author resolved from `directory`, where the project is written.
|
|
102
|
+
*/
|
|
103
|
+
async function fetchTemplate(ctx, source, name, directory) {
|
|
104
|
+
if (source.kind === "github") {
|
|
105
|
+
let extracted = await download(ctx, source);
|
|
106
|
+
if (isFailure(extracted))
|
|
107
|
+
return extracted;
|
|
108
|
+
let named = nameProject(extracted.data.tree, name);
|
|
109
|
+
if (isFailure(named))
|
|
110
|
+
return named;
|
|
111
|
+
let commit = extracted.data.commit === null ? "" : ` at ${extracted.data.commit}`;
|
|
112
|
+
return success({ tree: extracted.data.tree, description: `${describe(source)}${commit}` });
|
|
113
|
+
}
|
|
114
|
+
let tree = await readBuiltinTemplate(ctx.packageRoot, source.name);
|
|
115
|
+
if (isFailure(tree))
|
|
116
|
+
return tree;
|
|
117
|
+
let completed = await completeBuiltin(tree.data, name, ctx.packageRoot);
|
|
118
|
+
if (isFailure(completed))
|
|
119
|
+
return completed;
|
|
120
|
+
creditTemplate(tree.data, headerTags(await resolveAuthor(directory)));
|
|
121
|
+
return success({ tree: tree.data, description: `the ${source.name} template` });
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Downloads and extracts a GitHub template as a task. When GitHub answers 401 or 404 and no
|
|
125
|
+
* token is set, a terminal is asked for one, used for this download alone; an empty answer, or
|
|
126
|
+
* no terminal, keeps the refusal.
|
|
127
|
+
*/
|
|
128
|
+
async function download(ctx, source) {
|
|
129
|
+
let label = `Downloading ${describe(source)}`;
|
|
130
|
+
let downloaded = await ctx.task(label, (task) => downloadTemplate(source, ctx.env, task.signal));
|
|
131
|
+
let refused = isFailure(downloaded) &&
|
|
132
|
+
downloaded.error instanceof GitHubRefusal &&
|
|
133
|
+
(downloaded.error.status === 401 || downloaded.error.status === 404) &&
|
|
134
|
+
githubToken(ctx.env) === undefined;
|
|
135
|
+
if (!refused)
|
|
136
|
+
return downloaded;
|
|
137
|
+
let token = await ctx.prompt.password({
|
|
138
|
+
message: `GitHub token for ${source.owner}/${source.repo}`,
|
|
139
|
+
default: "",
|
|
140
|
+
name: "token",
|
|
141
|
+
});
|
|
142
|
+
if (isFailure(token))
|
|
143
|
+
return token;
|
|
144
|
+
if (token.data === "")
|
|
145
|
+
return downloaded;
|
|
146
|
+
return ctx.task(label, (task) => downloadTemplate(source, { GITHUB_TOKEN: token.data }, task.signal));
|
|
147
|
+
}
|
|
148
|
+
/** The fields of the tree's `package.json` the next steps read, or `null` without a readable one. */
|
|
149
|
+
function treeManifest(tree) {
|
|
150
|
+
let bytes = tree.files.get("package.json");
|
|
151
|
+
if (bytes === undefined)
|
|
152
|
+
return null;
|
|
153
|
+
let manifest = wrap(() => JSON.parse(new TextDecoder().decode(bytes)));
|
|
154
|
+
if (isFailure(manifest) || typeof manifest.data !== "object" || manifest.data === null) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
let { packageManager: declared, scripts } = manifest.data;
|
|
158
|
+
return {
|
|
159
|
+
...(typeof declared === "string" ? { packageManager: declared } : {}),
|
|
160
|
+
...(typeof scripts === "object" && scripts !== null
|
|
161
|
+
? { scripts: scripts }
|
|
162
|
+
: {}),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** Whether the tree's `package.json` declares `script`. */
|
|
166
|
+
function hasScript(tree, script) {
|
|
167
|
+
let scripts = treeManifest(tree)?.scripts;
|
|
168
|
+
return scripts !== undefined && script in scripts;
|
|
169
|
+
}
|
|
@@ -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
|
+
});
|