@20baht/cli 0.2.0 → 0.3.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/README.md +95 -41
- package/dist/application/create.js +8 -4
- package/dist/application/generate.js +27 -21
- package/dist/application/update.js +104 -0
- package/dist/args.js +3 -0
- package/dist/cli.js +56 -22
- package/dist/domain/create-plan.js +4 -3
- package/dist/domain/form-dsl.js +1 -1
- package/dist/domain/generate-plan.js +3 -3
- package/dist/domain/update-plan.js +93 -0
- package/dist/infrastructure/fs-reader.js +34 -2
- package/dist/infrastructure/npm-registry.js +28 -0
- package/package.json +10 -7
- package/templates/angular/apps/server/package.json +2 -0
- package/templates/angular/apps/server/src/app.ts +10 -0
- package/templates/angular/apps/server/src/forms/contact.form.ts +34 -0
- package/templates/angular/apps/server/test/app.test.ts +29 -0
- package/templates/angular/package.json.hbs +1 -1
- package/templates/create/apps/web/package.json.hbs +1 -1
- package/templates/{angular → federation}/README.md.hbs +2 -2
- package/templates/{angular → federation}/_dependency-cruiser.mjs +1 -1
- package/templates/{angular → federation}/apps/shell/package.json +3 -3
- package/templates/{angular → federation}/apps/shell/src/app/modules/home/home.component.ts.hbs +1 -1
- package/templates/{angular → federation}/apps/shell/src/environments/environment.development.ts +1 -1
- package/templates/{angular → federation}/eslint.config.ts.hbs +1 -1
- package/templates/new/README.md.hbs +1 -1
- package/templates/new/package.json.hbs +1 -1
- package/templates/remote/package.json.hbs +3 -3
- package/templates/standalone/README.md.hbs +44 -0
- package/templates/standalone/_dependency-cruiser.mjs +29 -0
- package/templates/standalone/apps/web/_editorconfig +17 -0
- package/templates/standalone/apps/web/angular.json +72 -0
- package/templates/standalone/apps/web/package.json +39 -0
- package/templates/standalone/apps/web/src/app/app.config.ts +14 -0
- package/templates/standalone/apps/web/src/app/app.css +4 -0
- package/templates/standalone/apps/web/src/app/app.html.hbs +16 -0
- package/templates/standalone/apps/web/src/app/app.routes.ts.hbs +23 -0
- package/templates/standalone/apps/web/src/app/app.ts +43 -0
- package/templates/standalone/apps/web/src/app/core/navigation/navigation.spec.ts +26 -0
- package/templates/standalone/apps/web/src/app/core/navigation/navigation.ts +14 -0
- package/templates/standalone/apps/web/src/app/modules/contact/contact.component.ts.hbs +87 -0
- package/templates/standalone/apps/web/src/app/modules/home/home.component.ts.hbs +37 -0
- package/templates/standalone/apps/web/src/app/modules/not-found/not-found.component.ts +36 -0
- package/templates/standalone/apps/web/src/app/services/contact.service.ts.hbs +19 -0
- package/templates/standalone/apps/web/src/app/services/hello.service.ts.hbs +14 -0
- package/templates/standalone/apps/web/src/index.html.hbs +12 -0
- package/templates/standalone/apps/web/src/main.ts +10 -0
- package/templates/standalone/apps/web/src/styles.css +19 -0
- package/templates/standalone/apps/web/tsconfig.app.json +10 -0
- package/templates/standalone/apps/web/tsconfig.json.hbs +39 -0
- package/templates/standalone/apps/web/tsconfig.spec.json +9 -0
- package/templates/standalone/bahtui.json +6 -0
- package/templates/standalone/eslint.config.ts.hbs +24 -0
- package/templates/standalone/knip.ts +23 -0
- /package/templates/{angular → federation}/apps/shell/_editorconfig +0 -0
- /package/templates/{angular → federation}/apps/shell/angular.json +0 -0
- /package/templates/{angular → federation}/apps/shell/federation.config.mjs +0 -0
- /package/templates/{angular → federation}/apps/shell/public/federation.manifest.json +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/app.config.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/app.css +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/app.html.hbs +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/app.routes.ts.hbs +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/app.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/core/federation/load-remote.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/core/federation/manifest.spec.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/core/federation/manifest.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/core/federation/remote-loader.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/core/federation/timeout.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/modules/unavailable/unavailable.component.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/bootstrap.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/environments/environment.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/index.html.hbs +0 -0
- /package/templates/{angular → federation}/apps/shell/src/main.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/styles.css +0 -0
- /package/templates/{angular → federation}/apps/shell/tsconfig.app.json +0 -0
- /package/templates/{angular → federation}/apps/shell/tsconfig.federation.json +0 -0
- /package/templates/{angular → federation}/apps/shell/tsconfig.json.hbs +0 -0
- /package/templates/{angular → federation}/apps/shell/tsconfig.spec.json +0 -0
- /package/templates/{angular → federation}/bahtui.json +0 -0
- /package/templates/{angular → federation}/knip.ts +0 -0
package/README.md
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
# @20baht/cli
|
|
2
2
|
|
|
3
3
|
Scaffolding CLI for bun workspaces and [bahtui](https://github.com/bank20baht/20baht) form
|
|
4
|
-
projects. Ships the `bahtui`
|
|
4
|
+
projects. Ships the `20baht` binary (it was `bahtui` up to 0.2.0; `bahtui.json` and the
|
|
5
|
+
`// bahtui:remotes` marker lines keep their names).
|
|
5
6
|
|
|
6
7
|
```sh
|
|
7
8
|
bun add -g @20baht/cli # or: npm i -g @20baht/cli
|
|
8
|
-
|
|
9
|
+
20baht --help
|
|
9
10
|
|
|
10
11
|
# one-off, no install
|
|
11
12
|
bunx @20baht/cli new my-workspace
|
|
@@ -16,24 +17,26 @@ steps.
|
|
|
16
17
|
|
|
17
18
|
## Commands
|
|
18
19
|
|
|
19
|
-
| Command | What it does
|
|
20
|
-
| ---------------------------------------- |
|
|
21
|
-
| `
|
|
22
|
-
| `
|
|
23
|
-
| `
|
|
24
|
-
| `
|
|
25
|
-
| `
|
|
26
|
-
| `
|
|
27
|
-
| `
|
|
28
|
-
| `
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
| Command | What it does |
|
|
21
|
+
| ---------------------------------------- | ---------------------------------------------------------------------- |
|
|
22
|
+
| `20baht new <name>` | Bare bun workspace in `./<name>` — toolchain only, no apps |
|
|
23
|
+
| `20baht create <name>` | Angular app + Elysia server + shared kit in `./<name>` |
|
|
24
|
+
| `20baht create <name> --federation` | The same as microfrontends: Native Federation dynamic host + one remote |
|
|
25
|
+
| `20baht create <name> --react` | React + Elysia + Eden DDD monorepo |
|
|
26
|
+
| `20baht init` | Write `bahtui.json` into an existing repo (enables the generators) |
|
|
27
|
+
| `20baht update [version]` | Existing repo: `@20baht/*` to the latest or a chosen version |
|
|
28
|
+
| `20baht g model <domain>` | `libs/domain/<domain>/model` package |
|
|
29
|
+
| `20baht g form <domain>/<name> --fields` | Engine-validated `FormDefinition` JSON inside that model package |
|
|
30
|
+
| `20baht g remote <name>` | Federation workspace: another remote, wired into the host and checks |
|
|
31
|
+
| `20baht g deploy [nginx]` | Federation workspace: nginx + systemd deploy, release/deploy/preview |
|
|
32
|
+
|
|
33
|
+
### `20baht new <name>`
|
|
31
34
|
|
|
32
35
|
Angular-style project bootstrap. Generates a bun workspace with the shared toolchain and
|
|
33
36
|
nothing else — you add `apps/*` and `packages/*` yourself.
|
|
34
37
|
|
|
35
38
|
```sh
|
|
36
|
-
|
|
39
|
+
20baht new acme
|
|
37
40
|
cd acme
|
|
38
41
|
bun run check # lint + format:check + knip + typecheck — green on the empty repo
|
|
39
42
|
```
|
|
@@ -70,31 +73,40 @@ Add a workspace by creating `apps/<name>/package.json` with `dev` / `build` / `t
|
|
|
70
73
|
scripts; `bun run dev`, `bun run build` and `bun run typecheck` pick it up automatically.
|
|
71
74
|
Add a matching entry to `knip.ts` so dead-code checks cover it.
|
|
72
75
|
|
|
73
|
-
### `
|
|
76
|
+
### `20baht create <name>`
|
|
74
77
|
|
|
75
|
-
Same flags as `new
|
|
78
|
+
Same flags as `new`. The `new` toolchain, plus an app on the family's main stack:
|
|
76
79
|
|
|
77
80
|
```
|
|
78
|
-
apps/web
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
apps/web Angular (:4200): @20baht/angular app shell and navigator, a page calling
|
|
82
|
+
GET /api/hello, a Contact page (a <baht-form> from the server's schema), a
|
|
83
|
+
not-found page
|
|
84
|
+
apps/server Elysia under /api (:3001); exports `type App`, emitted to dist/types for the web app.
|
|
85
|
+
One form as data (src/forms/contact.form.ts): served, and validated on submit
|
|
86
|
+
packages/kit typed ngx-eden client + error text, compiled into the app as @<name>/kit
|
|
87
|
+
bahtui.json { "frontend": "angular", "apps": { "web": "apps/web", ... } }
|
|
82
88
|
```
|
|
83
89
|
|
|
84
90
|
```sh
|
|
85
|
-
|
|
91
|
+
20baht create shop
|
|
86
92
|
cd shop
|
|
87
|
-
bun run dev # web on :
|
|
93
|
+
bun run dev # web on :4200, server on :3001
|
|
88
94
|
```
|
|
89
95
|
|
|
90
|
-
|
|
96
|
+
`eslint.config.ts` adds the `angular()` and `bahtui()` presets, `.dependency-cruiser.mjs` "core/,
|
|
97
|
+
services/, shared/ know no page" and "packages know no app". The generated repo passes its own
|
|
98
|
+
`bun run check` (`bun run --filter @20baht/cli accept:angular` proves it: scaffold, install, first
|
|
99
|
+
commit, check). `g remote` and `g deploy` do not apply to it: they need the federation host below.
|
|
91
100
|
|
|
92
|
-
|
|
101
|
+
### `20baht create <name> --federation`
|
|
102
|
+
|
|
103
|
+
Same flags and the same server and kit as `create`, with the web side as microfrontends on
|
|
93
104
|
[Native Federation](https://www.npmjs.com/package/@angular-architects/native-federation):
|
|
94
105
|
|
|
95
106
|
```
|
|
96
|
-
apps/shell host (:4200):
|
|
97
|
-
|
|
107
|
+
apps/shell dynamic host (:4200): reads its remotes from a federation manifest at runtime
|
|
108
|
+
(a remote is added or repointed with no host build); @20baht/angular app
|
|
109
|
+
shell, navigator built from that manifest, a fallback page for each remote that cannot load
|
|
98
110
|
apps/hello-web remote (:4201): one page calling GET /api/hello, exposed as ./Routes
|
|
99
111
|
apps/server Elysia under /api; exports `type App`, emitted to dist/types for the web apps
|
|
100
112
|
packages/kit typed ngx-eden client + error text, compiled into each app as @<name>/kit
|
|
@@ -104,8 +116,8 @@ bahtui.json { "frontend": "angular", "apps": { "web": "apps/shell", ... }
|
|
|
104
116
|
`eslint.config.ts` adds the `angular()` and `bahtui()` presets for the web apps, `knip.ts` a
|
|
105
117
|
workspace per app, `.dependency-cruiser.mjs` "apps never import each other", "core/, services/,
|
|
106
118
|
shared/ know no page" and "packages know no app". The generated repo passes its own
|
|
107
|
-
`bun run check` (`bun run --filter @20baht/cli accept:
|
|
108
|
-
`g remote`, check). What it gets right on purpose:
|
|
119
|
+
`bun run check` (`bun run --filter @20baht/cli accept:federation` proves it: scaffold, install,
|
|
120
|
+
`g remote`, `g deploy`, check, release). What it gets right on purpose:
|
|
109
121
|
|
|
110
122
|
- `features.ignoreUnusedDeps: false` in every `federation.config.mjs` (its scan refuses the kit,
|
|
111
123
|
which lives outside the app folder), so every dependency is shared and each app lists
|
|
@@ -115,18 +127,35 @@ shared/ know no page" and "packages know no app". The generated repo passes its
|
|
|
115
127
|
extensionless (Angular's compiler rejects `./x.ts` specifiers).
|
|
116
128
|
- A remote that is down at boot gets a fallback page under its URL prefix.
|
|
117
129
|
|
|
118
|
-
### `
|
|
130
|
+
### `20baht create <name> --react`
|
|
131
|
+
|
|
132
|
+
Same flags. Its own lighter toolchain, not `new`'s:
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
apps/web React 19 + Vite on @20baht/ui (tokens, <baht-*> elements, dark toggle)
|
|
136
|
+
apps/api Elysia — exports `type App`, the Eden type anchor
|
|
137
|
+
libs/shared/eden treaty<App> — the one typed HTTP client
|
|
138
|
+
bahtui.json generator config (see below)
|
|
139
|
+
```
|
|
119
140
|
|
|
120
|
-
|
|
141
|
+
```sh
|
|
142
|
+
20baht create shop --react
|
|
143
|
+
cd shop
|
|
144
|
+
bun run dev # web on :5173, api on :3001
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### `20baht g remote <name>`
|
|
148
|
+
|
|
149
|
+
In a `create --federation` workspace: `apps/<name>-web` on the next free port, mounted at
|
|
121
150
|
`/<name>`, plus a line in `eslint.config.ts`, `knip.ts`, `.dependency-cruiser.mjs`, the dev
|
|
122
151
|
manifest (`apps/shell/src/environments/environment.development.ts`) and the deployed one
|
|
123
152
|
(`apps/shell/public/federation.manifest.json`). The TS/JS files carry a `// bahtui:remotes` line
|
|
124
153
|
the entry goes above; if one is gone, nothing is written and the error names the file. Run
|
|
125
154
|
`bun install` afterwards.
|
|
126
155
|
|
|
127
|
-
### `
|
|
156
|
+
### `20baht g deploy [nginx]`
|
|
128
157
|
|
|
129
|
-
In a `create --
|
|
158
|
+
In a `create --federation` workspace, one web server for everything:
|
|
130
159
|
|
|
131
160
|
```
|
|
132
161
|
deploy/nginx.conf host at /, remotes at /remotes/<app>/, /federation.manifest.json from
|
|
@@ -143,14 +172,39 @@ scripts/preview.ts bun run preview: serve .release/ like nginx does, on :8
|
|
|
143
172
|
It adds the three scripts to `package.json` and `.release` to `.gitignore`, `.prettierignore` and
|
|
144
173
|
the eslint ignores. It refuses an existing `deploy/` (or existing script names) without `--force`.
|
|
145
174
|
|
|
146
|
-
### `
|
|
175
|
+
### `20baht update [version]`
|
|
176
|
+
|
|
177
|
+
At the root of any repo that uses the libraries (it needs no `bahtui.json`):
|
|
178
|
+
|
|
179
|
+
```sh
|
|
180
|
+
20baht update --dry-run # what would change
|
|
181
|
+
20baht update # every @20baht/* dependency to its latest version, then bun install
|
|
182
|
+
20baht update 0.2.1 # to 0.2.1 instead, for each library that has a 0.2.1
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
It reads every `package.json` outside `node_modules`, build output and dot folders, asks the npm
|
|
186
|
+
registry about each `@20baht/*` package it finds there, and edits the dependency lines
|
|
187
|
+
(`dependencies`, `devDependencies`, `peerDependencies`, `optionalDependencies`):
|
|
188
|
+
|
|
189
|
+
- **No version:** each library goes to its own latest. Nothing is lowered.
|
|
190
|
+
- **A version:** each library that has that version is set to it, up or down, so it also rolls
|
|
191
|
+
back. The libraries do not all share one number (`@20baht/ui` and `@20baht/stickers` version
|
|
192
|
+
apart), so the ones without that version are left alone and named.
|
|
193
|
+
- A `^` or `~` is kept. A range it cannot read (`>=0.1.0 <0.2.0`, a tag) is left and reported;
|
|
194
|
+
`workspace:*` is left silently.
|
|
195
|
+
|
|
196
|
+
The files are edited as text, so their formatting stays. If the registry cannot be reached,
|
|
197
|
+
nothing is changed. It touches no other dependency and no source file: read the libraries'
|
|
198
|
+
changelogs for what changed, then run the repo's own check. Flags: `--dry-run`, `--no-install`.
|
|
199
|
+
|
|
200
|
+
### `20baht init`
|
|
147
201
|
|
|
148
|
-
Writes `bahtui.json` into the current directory so `
|
|
202
|
+
Writes `bahtui.json` into the current directory so `20baht g …` knows where things live.
|
|
149
203
|
|
|
150
204
|
```sh
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
205
|
+
20baht init # frontend react, backend elysia
|
|
206
|
+
20baht init --frontend none # no React feature slices
|
|
207
|
+
20baht init --backend none # no Elysia plugins
|
|
154
208
|
```
|
|
155
209
|
|
|
156
210
|
```json
|
|
@@ -163,12 +217,12 @@ bahtui init --backend none # no Elysia plugins
|
|
|
163
217
|
}
|
|
164
218
|
```
|
|
165
219
|
|
|
166
|
-
### `
|
|
220
|
+
### `20baht g model <domain>`
|
|
167
221
|
|
|
168
222
|
Creates `<libsDir>/domain/<domain>/model` — a framework-free package for entities and form
|
|
169
223
|
JSON. `<domain>` is kebab-case.
|
|
170
224
|
|
|
171
|
-
### `
|
|
225
|
+
### `20baht g form <domain>/<name> --fields "<dsl>"`
|
|
172
226
|
|
|
173
227
|
Builds a `FormDefinition`, validates it with
|
|
174
228
|
[`@20baht/validator`](https://www.npmjs.com/package/@20baht/validator) (the same
|
|
@@ -176,7 +230,7 @@ engine the browser components run), and writes
|
|
|
176
230
|
`<libsDir>/domain/<domain>/model/src/<name>.form.json`.
|
|
177
231
|
|
|
178
232
|
```sh
|
|
179
|
-
|
|
233
|
+
20baht g form ticket/create \
|
|
180
234
|
--fields "title:text:required,priority:dropdown:options=low|medium|high,qty:number:min=1"
|
|
181
235
|
```
|
|
182
236
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FEDERATION_HOST, overlayTemplates, planCreate, PRESET_TEMPLATE_SETS, } from '../domain/create-plan.js';
|
|
2
2
|
import { withFirstRemote } from '../domain/remote-plan.js';
|
|
3
3
|
import { validateProjectName } from '../domain/naming.js';
|
|
4
4
|
function logDryRun(blueprint, deps) {
|
|
@@ -39,8 +39,8 @@ export function runCreate(input, deps) {
|
|
|
39
39
|
const render = (raw, data) => deps.renderer.render(raw, data);
|
|
40
40
|
const sets = PRESET_TEMPLATE_SETS[input.preset].map((set) => deps.templates.load(set));
|
|
41
41
|
const planned = planCreate(input, overlayTemplates(sets), render);
|
|
42
|
-
const blueprint = input.preset === '
|
|
43
|
-
? withFirstRemote(planned, input.name,
|
|
42
|
+
const blueprint = input.preset === 'federation'
|
|
43
|
+
? withFirstRemote(planned, input.name, FEDERATION_HOST, deps.templates.load('remote'), render)
|
|
44
44
|
: planned;
|
|
45
45
|
if (input.dryRun) {
|
|
46
46
|
logDryRun(blueprint, deps);
|
|
@@ -58,8 +58,12 @@ const NEXT_STEPS = {
|
|
|
58
58
|
'bun run lint && bun run test && bun run build',
|
|
59
59
|
],
|
|
60
60
|
angular: [
|
|
61
|
+
'bun run dev # web :4200, server :3001',
|
|
62
|
+
'bun run check # lint + format:check + typecheck + madge + deps + knip + dup + build + test',
|
|
63
|
+
],
|
|
64
|
+
federation: [
|
|
61
65
|
'bun run dev # shell :4200, hello-web :4201, server :3001',
|
|
62
|
-
'
|
|
66
|
+
'20baht g remote <name> # add another remote',
|
|
63
67
|
'bun run check # lint + format:check + typecheck + madge + deps + knip + dup + build + test',
|
|
64
68
|
],
|
|
65
69
|
workspace: [
|
|
@@ -28,7 +28,7 @@ function isPlainObject(value) {
|
|
|
28
28
|
function loadConfig(root, reader) {
|
|
29
29
|
const raw = reader.read(`${root}/bahtui.json`);
|
|
30
30
|
if (raw === null) {
|
|
31
|
-
throw new GenerateError('No bahtui.json here — run "
|
|
31
|
+
throw new GenerateError('No bahtui.json here — run "20baht init" (or create) first.');
|
|
32
32
|
}
|
|
33
33
|
let parsed;
|
|
34
34
|
try {
|
|
@@ -73,7 +73,7 @@ function emit(blueprint, dryRun, deps) {
|
|
|
73
73
|
for (const f of blueprint.files)
|
|
74
74
|
deps.log.step(f.path);
|
|
75
75
|
}
|
|
76
|
-
/** `
|
|
76
|
+
/** `20baht init` (PRD P2): bahtui.json for an existing repo, paths detected. */
|
|
77
77
|
export function runInit(input, deps) {
|
|
78
78
|
if (deps.reader.exists(`${input.root}/bahtui.json`) && !input.force && !input.dryRun) {
|
|
79
79
|
throw new GenerateError('bahtui.json already exists — use --force to overwrite.');
|
|
@@ -91,9 +91,9 @@ export function runInit(input, deps) {
|
|
|
91
91
|
delete config.edenClient;
|
|
92
92
|
emit(planInit(input.root, config), input.dryRun, deps);
|
|
93
93
|
if (!input.dryRun)
|
|
94
|
-
deps.log.info('bahtui.json written — `
|
|
94
|
+
deps.log.info('bahtui.json written — `20baht g model <domain>` is ready.');
|
|
95
95
|
}
|
|
96
|
-
/** `
|
|
96
|
+
/** `20baht g model|form` (PRD P3). Engine-validates before any write. */
|
|
97
97
|
export function runGenerate(input, deps) {
|
|
98
98
|
const config = loadConfig(input.root, deps.reader);
|
|
99
99
|
if (input.kind === 'model') {
|
|
@@ -120,7 +120,7 @@ export function runGenerate(input, deps) {
|
|
|
120
120
|
throw new GenerateError('g form needs --fields, e.g. --fields "title:text:required,qty:number:min=1".');
|
|
121
121
|
}
|
|
122
122
|
if (!deps.reader.exists(`${input.root}/${modelDir(config, domain)}`)) {
|
|
123
|
-
throw new GenerateError(`${modelDir(config, domain)} does not exist — run "
|
|
123
|
+
throw new GenerateError(`${modelDir(config, domain)} does not exist — run "20baht g model ${domain}" first.`);
|
|
124
124
|
}
|
|
125
125
|
let form;
|
|
126
126
|
try {
|
|
@@ -169,19 +169,29 @@ function projectName(root, reader) {
|
|
|
169
169
|
return name;
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
172
|
-
*
|
|
172
|
+
* The host app folder of a federation workspace (`20baht create --federation`): `apps.web` of
|
|
173
|
+
* an Angular bahtui.json, holding a `federation.config.mjs`. A one-app workspace
|
|
174
|
+
* (`20baht create`) has neither a host nor manifests for `command` to edit.
|
|
175
|
+
*/
|
|
176
|
+
function federationHost(command, root, reader) {
|
|
177
|
+
const config = loadConfig(root, reader);
|
|
178
|
+
const host = config.apps.web;
|
|
179
|
+
if (config.frontend !== 'angular' || host === undefined) {
|
|
180
|
+
throw new GenerateError(`${command} needs a federation workspace (bahtui.json "frontend": "angular" and "apps.web", from 20baht create --federation).`);
|
|
181
|
+
}
|
|
182
|
+
validateConfigPath('apps.web', host);
|
|
183
|
+
if (!reader.exists(`${root}/${host}/federation.config.mjs`)) {
|
|
184
|
+
throw new GenerateError(`${command} needs a Native Federation host, and ${host} has no federation.config.mjs (a workspace from 20baht create --federation has one).`);
|
|
185
|
+
}
|
|
186
|
+
return host;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* `20baht g remote <name>` in an Angular workspace (`20baht create --federation`): a new Native
|
|
173
190
|
* Federation remote under `apps/<name>-web`, added to the host's manifests, eslint, knip and
|
|
174
191
|
* dependency-cruiser. Nothing is written when any of those files cannot take it.
|
|
175
192
|
*/
|
|
176
193
|
export function runGenerateRemote(input, deps) {
|
|
177
|
-
const
|
|
178
|
-
if (config.frontend !== 'angular') {
|
|
179
|
-
throw new GenerateError('g remote needs an Angular workspace (bahtui.json "frontend": "angular", from bahtui create --angular).');
|
|
180
|
-
}
|
|
181
|
-
const host = config.apps.web;
|
|
182
|
-
if (host === undefined)
|
|
183
|
-
throw new GenerateError('bahtui.json needs "apps.web", the host app.');
|
|
184
|
-
validateConfigPath('apps.web', host);
|
|
194
|
+
const host = federationHost('g remote', input.root, deps.reader);
|
|
185
195
|
const errors = validateRemoteName(input.name);
|
|
186
196
|
if (errors.length > 0)
|
|
187
197
|
throw new GenerateError(errors.join(' '));
|
|
@@ -214,17 +224,13 @@ function emitThen(input, files, deps, next) {
|
|
|
214
224
|
deps.log.info(next);
|
|
215
225
|
}
|
|
216
226
|
/**
|
|
217
|
-
* `
|
|
227
|
+
* `20baht g deploy [nginx]` in an Angular workspace: `deploy/` (nginx.conf, a systemd unit,
|
|
218
228
|
* env.example, install.sh) and `scripts/{release,deploy,preview}.ts`, wired into package.json,
|
|
219
229
|
* `.gitignore`, `.prettierignore` and eslint. Nothing is written when an edit cannot apply.
|
|
220
230
|
*/
|
|
221
231
|
export function runGenerateDeploy(input, deps) {
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
throw new GenerateError('g deploy needs an Angular workspace (bahtui.json "frontend": "angular", from bahtui create --angular).');
|
|
225
|
-
}
|
|
226
|
-
validateConfigPath('apps.web', config.apps.web);
|
|
227
|
-
const host = config.apps.web.split('/').pop() ?? config.apps.web;
|
|
232
|
+
const hostPath = federationHost('g deploy', input.root, deps.reader);
|
|
233
|
+
const host = hostPath.split('/').pop() ?? hostPath;
|
|
228
234
|
if (deps.reader.exists(`${input.root}/deploy`) && !input.force) {
|
|
229
235
|
throw new GenerateError('deploy/ already exists — use --force.');
|
|
230
236
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { familyDependencies, isPackageJson, planUpdate, VERSION } from '../domain/update-plan.js';
|
|
2
|
+
export class UpdateError extends Error {
|
|
3
|
+
}
|
|
4
|
+
/** Every `@20baht/*` package the repo depends on, in name order. */
|
|
5
|
+
function familyNames(files) {
|
|
6
|
+
const names = new Set();
|
|
7
|
+
for (const file of files) {
|
|
8
|
+
for (const name of familyDependencies(file.contents)?.keys() ?? [])
|
|
9
|
+
names.add(name);
|
|
10
|
+
}
|
|
11
|
+
return [...names].sort((a, b) => (a < b ? -1 : 1));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Where each library goes: its latest, or the chosen version when the registry has that version
|
|
15
|
+
* of it. The libraries do not all share one number, so a chosen version moves the ones that
|
|
16
|
+
* have it and leaves the rest, each named in a note.
|
|
17
|
+
*/
|
|
18
|
+
async function resolveTargets(names, version, registry) {
|
|
19
|
+
const targets = new Map();
|
|
20
|
+
const notes = [];
|
|
21
|
+
const found = await Promise.all(names.map((name) => registry.info(name)));
|
|
22
|
+
names.forEach((name, i) => {
|
|
23
|
+
const info = found[i];
|
|
24
|
+
if (info === null || info === undefined)
|
|
25
|
+
notes.push(`${name} is not on the registry, left as it is.`);
|
|
26
|
+
else if (version === undefined)
|
|
27
|
+
targets.set(name, info.latest);
|
|
28
|
+
else if (info.versions.includes(version))
|
|
29
|
+
targets.set(name, version);
|
|
30
|
+
else
|
|
31
|
+
notes.push(`${name} has no ${version} (latest is ${info.latest}), left as it is.`);
|
|
32
|
+
});
|
|
33
|
+
return { targets, notes };
|
|
34
|
+
}
|
|
35
|
+
/** The repo's package.json files, as read. */
|
|
36
|
+
function packageFiles(root, deps) {
|
|
37
|
+
return deps.walker
|
|
38
|
+
.list(root)
|
|
39
|
+
.filter(isPackageJson)
|
|
40
|
+
.flatMap((path) => {
|
|
41
|
+
const contents = deps.reader.read(`${root}/${path}`);
|
|
42
|
+
return contents === null ? [] : [{ path, contents }];
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** Writes the changed files and installs; on `--dry-run` only counts them. */
|
|
46
|
+
function apply(files, input, deps) {
|
|
47
|
+
if (input.dryRun) {
|
|
48
|
+
deps.log.info(`dry-run — ${String(files.length)} files would change, nothing written.`);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
deps.writer.writeFiles({ root: input.root, files, postCommands: [] });
|
|
52
|
+
deps.log.info(`${String(files.length)} files updated.`);
|
|
53
|
+
if (input.install) {
|
|
54
|
+
deps.log.step('bun install');
|
|
55
|
+
try {
|
|
56
|
+
deps.runner.run('bun', ['install'], input.root);
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
throw new UpdateError(`${err instanceof Error ? err.message : String(err)}\nthe files are updated — fix the cause and rerun: bun install`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
deps.log.info("Next: read the libraries' changelogs for what changed, then run the repo's own check.");
|
|
63
|
+
}
|
|
64
|
+
/** Asks the registry; a failure there is reported as one, with nothing changed. */
|
|
65
|
+
async function targetsFor(names, input, deps) {
|
|
66
|
+
try {
|
|
67
|
+
return await resolveTargets(names, input.version, deps.registry);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
throw new UpdateError(`could not ask the npm registry for versions, nothing changed: ${err instanceof Error ? err.message : String(err)}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* `20baht update [version]` at a repo root: every `@20baht/*` dependency of every package.json
|
|
75
|
+
* to the latest version (never lowering one), or to `version` where the library has it (up or
|
|
76
|
+
* down), then `bun install`. `--dry-run` only says what would change.
|
|
77
|
+
*/
|
|
78
|
+
export async function runUpdate(input, deps) {
|
|
79
|
+
if (input.version !== undefined && !VERSION.test(input.version)) {
|
|
80
|
+
throw new UpdateError(`"${input.version}" is not a version — 20baht update 0.2.1, or no version for the latest.`);
|
|
81
|
+
}
|
|
82
|
+
if (!deps.reader.exists(`${input.root}/package.json`)) {
|
|
83
|
+
throw new UpdateError('No package.json here — run 20baht update at the root of the repo.');
|
|
84
|
+
}
|
|
85
|
+
const files = packageFiles(input.root, deps);
|
|
86
|
+
const names = familyNames(files);
|
|
87
|
+
if (names.length === 0) {
|
|
88
|
+
deps.log.info('Nothing to update: no package.json here depends on a @20baht library.');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const resolved = await targetsFor(names, input, deps);
|
|
92
|
+
const plan = planUpdate(files, { targets: resolved.targets, lower: input.version !== undefined });
|
|
93
|
+
for (const line of plan.changes)
|
|
94
|
+
deps.log.step(line);
|
|
95
|
+
for (const line of [...resolved.notes, ...plan.notes])
|
|
96
|
+
deps.log.info(`note: ${line}`);
|
|
97
|
+
if (plan.files.length > 0) {
|
|
98
|
+
apply(plan.files, input, deps);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
deps.log.info(input.version === undefined
|
|
102
|
+
? 'Nothing to update: every @20baht library is at its latest version.'
|
|
103
|
+
: `Nothing to update: no @20baht library here moves to ${input.version}.`);
|
|
104
|
+
}
|
package/dist/args.js
CHANGED
package/dist/cli.js
CHANGED
|
@@ -7,35 +7,43 @@ import { runGenerate, runGenerateDeploy, runGenerateRemote, runInit, GenerateErr
|
|
|
7
7
|
import { DiskTemplateSource } from './infrastructure/template-source.js';
|
|
8
8
|
import { TemplateRenderer } from './infrastructure/template-renderer.js';
|
|
9
9
|
import { DiskFileWriter } from './infrastructure/fs-writer.js';
|
|
10
|
-
import { DiskFileReader } from './infrastructure/fs-reader.js';
|
|
10
|
+
import { DiskFileReader, DiskFileWalker } from './infrastructure/fs-reader.js';
|
|
11
|
+
import { runUpdate, UpdateError } from './application/update.js';
|
|
12
|
+
import { NpmRegistry } from './infrastructure/npm-registry.js';
|
|
11
13
|
import { ShellRunner } from './infrastructure/shell-runner.js';
|
|
12
14
|
import { KNOWN_FLAGS, parseArgs } from './args.js';
|
|
13
|
-
const HELP = `
|
|
15
|
+
const HELP = `20baht — scaffolding for apps on the @20baht libraries (Angular + Elysia)
|
|
14
16
|
|
|
15
17
|
Usage:
|
|
16
|
-
|
|
18
|
+
20baht new <name> [options] bare bun workspace in ./<name> — toolchain only
|
|
17
19
|
(eslint, prettier, knip, husky, commitlint, gitleaks, jscpd, depcruise, CI), no apps
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
bahtui
|
|
20
|
+
20baht create <name> [options] Angular app + Elysia server + shared web kit in ./<name>,
|
|
21
|
+
on the same toolchain
|
|
22
|
+
20baht create <name> --federation the same as microfrontends: a Native Federation dynamic
|
|
23
|
+
host (remotes read from a manifest at runtime) + one remote
|
|
24
|
+
20baht create <name> --react React + Elysia + Eden monorepo
|
|
25
|
+
20baht init [options] write bahtui.json into an existing repo
|
|
26
|
+
20baht update [version] at a repo root: every @20baht/* dependency to its latest
|
|
27
|
+
version, or to <version> where the library has it, then
|
|
28
|
+
bun install
|
|
29
|
+
20baht g model <domain> libs/domain/<d>/model package
|
|
30
|
+
20baht g form <domain>/<name> --fields "key:type:mod,…"
|
|
24
31
|
engine-validated FormDefinition JSON
|
|
25
|
-
|
|
32
|
+
20baht g remote <name> federation workspace: apps/<name>-web remote, added to the
|
|
26
33
|
host manifests, eslint, knip and dependency-cruiser
|
|
27
|
-
|
|
34
|
+
20baht g deploy [nginx] federation workspace: deploy/ (nginx, systemd, install.sh)
|
|
28
35
|
and release / deploy / preview scripts
|
|
29
36
|
Field DSL:
|
|
30
37
|
title:text:required,priority:dropdown:options=low|medium|high,qty:number:min=1
|
|
31
38
|
|
|
32
39
|
Options:
|
|
33
40
|
--fields <dsl> g form: the field list (required)
|
|
34
|
-
--
|
|
41
|
+
--federation create: a Native Federation dynamic host and a remote instead of one app
|
|
42
|
+
--react create: the React scaffold instead of Angular
|
|
35
43
|
--frontend <react|none> init: default react
|
|
36
44
|
--backend <elysia|none> init: default elysia
|
|
37
45
|
--dry-run print what would be generated, write nothing
|
|
38
|
-
--no-install new/create: skip "bun install" (also skips the initial commit)
|
|
46
|
+
--no-install new/create/update: skip "bun install" (also skips the initial commit)
|
|
39
47
|
--no-git new/create: skip git init + initial commit
|
|
40
48
|
--skip-install / --skip-git Angular-style aliases of the two above
|
|
41
49
|
--force overwrite existing files/dirs
|
|
@@ -83,11 +91,19 @@ function preflight({ flags }) {
|
|
|
83
91
|
function presetFor(a, command) {
|
|
84
92
|
if (command === 'new')
|
|
85
93
|
return 'workspace';
|
|
86
|
-
|
|
94
|
+
if (a.flags.has('--angular')) {
|
|
95
|
+
throw new CreateError('--angular is gone: create makes an Angular app without it. For the Native Federation host and remote it used to mean, pass --federation.');
|
|
96
|
+
}
|
|
97
|
+
const federation = a.flags.has('--federation');
|
|
98
|
+
if (!a.flags.has('--react'))
|
|
99
|
+
return federation ? 'federation' : 'angular';
|
|
100
|
+
if (federation)
|
|
101
|
+
throw new CreateError('--federation is the Angular scaffold; drop --react.');
|
|
102
|
+
return 'full';
|
|
87
103
|
}
|
|
88
104
|
function commandCreate(a, command) {
|
|
89
105
|
if (!a.name) {
|
|
90
|
-
log.error(`${command} needs a project name:
|
|
106
|
+
log.error(`${command} needs a project name: 20baht ${command} <name>`);
|
|
91
107
|
return 1;
|
|
92
108
|
}
|
|
93
109
|
runCreate({
|
|
@@ -132,11 +148,11 @@ function commandGenerate(a, generateDeps) {
|
|
|
132
148
|
if (name === 'deploy')
|
|
133
149
|
return commandDeploy(a, generateDeps);
|
|
134
150
|
if (name !== 'model' && name !== 'form') {
|
|
135
|
-
log.error('Unknown generator —
|
|
151
|
+
log.error('Unknown generator — 20baht g model <domain> | g form <domain>/<name> | g remote <name> | g deploy.');
|
|
136
152
|
return 1;
|
|
137
153
|
}
|
|
138
154
|
if (!sub) {
|
|
139
|
-
log.error(`g ${name} needs a target:
|
|
155
|
+
log.error(`g ${name} needs a target: 20baht g ${name} <${name === 'model' ? 'domain' : 'domain/name'}>`);
|
|
140
156
|
return 1;
|
|
141
157
|
}
|
|
142
158
|
runGenerate({
|
|
@@ -151,7 +167,7 @@ function commandGenerate(a, generateDeps) {
|
|
|
151
167
|
}
|
|
152
168
|
function commandRemote(a, generateDeps) {
|
|
153
169
|
if (!a.sub) {
|
|
154
|
-
log.error('g remote needs a name:
|
|
170
|
+
log.error('g remote needs a name: 20baht g remote <name>');
|
|
155
171
|
return 1;
|
|
156
172
|
}
|
|
157
173
|
runGenerateRemote({
|
|
@@ -170,6 +186,20 @@ function commandDeploy(a, generateDeps) {
|
|
|
170
186
|
runGenerateDeploy({ root: process.cwd(), dryRun: a.flags.has('--dry-run'), force: a.flags.has('--force') }, { ...generateDeps, templates: new DiskTemplateSource(), renderer: new TemplateRenderer() });
|
|
171
187
|
return 0;
|
|
172
188
|
}
|
|
189
|
+
async function commandUpdate(a, generateDeps) {
|
|
190
|
+
await runUpdate({
|
|
191
|
+
root: process.cwd(),
|
|
192
|
+
version: a.name,
|
|
193
|
+
dryRun: a.flags.has('--dry-run'),
|
|
194
|
+
install: !a.flags.has('--no-install') && !a.flags.has('--skip-install'),
|
|
195
|
+
}, {
|
|
196
|
+
...generateDeps,
|
|
197
|
+
walker: new DiskFileWalker(),
|
|
198
|
+
registry: new NpmRegistry(),
|
|
199
|
+
runner: new ShellRunner(),
|
|
200
|
+
});
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
173
203
|
function dispatch(a, command) {
|
|
174
204
|
const generateDeps = {
|
|
175
205
|
reader: new DiskFileReader(),
|
|
@@ -180,13 +210,15 @@ function dispatch(a, command) {
|
|
|
180
210
|
return commandCreate(a, command);
|
|
181
211
|
if (command === 'init')
|
|
182
212
|
return commandInit(a, generateDeps);
|
|
213
|
+
if (command === 'update')
|
|
214
|
+
return commandUpdate(a, generateDeps);
|
|
183
215
|
if (command === 'g')
|
|
184
216
|
return commandGenerate(a, generateDeps);
|
|
185
217
|
log.error(`Unknown command "${command}".`);
|
|
186
218
|
log.error(HELP);
|
|
187
219
|
return 1;
|
|
188
220
|
}
|
|
189
|
-
function main(rawArgv) {
|
|
221
|
+
async function main(rawArgv) {
|
|
190
222
|
const parsed = parseArgs(rawArgv);
|
|
191
223
|
const early = preflight(parsed);
|
|
192
224
|
if (early !== null)
|
|
@@ -197,11 +229,13 @@ function main(rawArgv) {
|
|
|
197
229
|
return 1;
|
|
198
230
|
}
|
|
199
231
|
try {
|
|
200
|
-
return dispatch(parsed, parsed.command);
|
|
232
|
+
return await dispatch(parsed, parsed.command);
|
|
201
233
|
}
|
|
202
234
|
catch (err) {
|
|
203
|
-
log.error(err instanceof CreateError || err instanceof GenerateError
|
|
235
|
+
log.error(err instanceof CreateError || err instanceof GenerateError || err instanceof UpdateError
|
|
236
|
+
? err.message
|
|
237
|
+
: String(err));
|
|
204
238
|
return 1;
|
|
205
239
|
}
|
|
206
240
|
}
|
|
207
|
-
|
|
241
|
+
void main(process.argv.slice(2)).then((code) => process.exit(code));
|
|
@@ -3,10 +3,11 @@ import { isTemplate, outputPath } from './template-path.js';
|
|
|
3
3
|
export const PRESET_TEMPLATE_SETS = {
|
|
4
4
|
full: ['create'],
|
|
5
5
|
workspace: ['new'],
|
|
6
|
-
angular: ['new', 'angular'],
|
|
6
|
+
angular: ['new', 'angular', 'standalone'],
|
|
7
|
+
federation: ['new', 'angular', 'federation'],
|
|
7
8
|
};
|
|
8
|
-
/** The
|
|
9
|
-
export const
|
|
9
|
+
/** The federation preset's host app folder. */
|
|
10
|
+
export const FEDERATION_HOST = 'apps/shell';
|
|
10
11
|
/**
|
|
11
12
|
* Lays template sets over each other by output path (`x.hbs` and `x` are the same file). A
|
|
12
13
|
* `_gitkeep` placeholder is dropped from any folder a later set puts files in.
|