@20baht/cli 0.1.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +93 -41
  2. package/dist/application/create.js +8 -4
  3. package/dist/application/generate.js +27 -21
  4. package/dist/application/update.js +104 -0
  5. package/dist/args.js +3 -0
  6. package/dist/cli.js +56 -22
  7. package/dist/domain/create-plan.js +4 -3
  8. package/dist/domain/form-dsl.js +6 -22
  9. package/dist/domain/generate-plan.js +3 -3
  10. package/dist/domain/update-plan.js +93 -0
  11. package/dist/infrastructure/fs-reader.js +34 -2
  12. package/dist/infrastructure/npm-registry.js +28 -0
  13. package/package.json +10 -7
  14. package/templates/angular/package.json.hbs +1 -1
  15. package/templates/create/apps/web/package.json.hbs +1 -1
  16. package/templates/{angular → federation}/README.md.hbs +2 -2
  17. package/templates/{angular → federation}/_dependency-cruiser.mjs +1 -1
  18. package/templates/{angular → federation}/apps/shell/package.json +3 -3
  19. package/templates/{angular → federation}/apps/shell/src/app/modules/home/home.component.ts.hbs +1 -1
  20. package/templates/{angular → federation}/apps/shell/src/environments/environment.development.ts +1 -1
  21. package/templates/{angular → federation}/eslint.config.ts.hbs +1 -1
  22. package/templates/new/README.md.hbs +1 -1
  23. package/templates/new/package.json.hbs +1 -1
  24. package/templates/remote/package.json.hbs +3 -3
  25. package/templates/standalone/README.md.hbs +36 -0
  26. package/templates/standalone/_dependency-cruiser.mjs +29 -0
  27. package/templates/standalone/apps/web/_editorconfig +17 -0
  28. package/templates/standalone/apps/web/angular.json +72 -0
  29. package/templates/standalone/apps/web/package.json +39 -0
  30. package/templates/standalone/apps/web/src/app/app.config.ts +14 -0
  31. package/templates/standalone/apps/web/src/app/app.css +4 -0
  32. package/templates/standalone/apps/web/src/app/app.html.hbs +16 -0
  33. package/templates/standalone/apps/web/src/app/app.routes.ts.hbs +17 -0
  34. package/templates/standalone/apps/web/src/app/app.ts +43 -0
  35. package/templates/standalone/apps/web/src/app/core/navigation/navigation.spec.ts +26 -0
  36. package/templates/standalone/apps/web/src/app/core/navigation/navigation.ts +11 -0
  37. package/templates/standalone/apps/web/src/app/modules/home/home.component.ts.hbs +37 -0
  38. package/templates/standalone/apps/web/src/app/modules/not-found/not-found.component.ts +36 -0
  39. package/templates/standalone/apps/web/src/app/services/hello.service.ts.hbs +14 -0
  40. package/templates/standalone/apps/web/src/index.html.hbs +12 -0
  41. package/templates/standalone/apps/web/src/main.ts +10 -0
  42. package/templates/standalone/apps/web/src/styles.css +19 -0
  43. package/templates/standalone/apps/web/tsconfig.app.json +10 -0
  44. package/templates/standalone/apps/web/tsconfig.json.hbs +39 -0
  45. package/templates/standalone/apps/web/tsconfig.spec.json +9 -0
  46. package/templates/standalone/bahtui.json +6 -0
  47. package/templates/standalone/eslint.config.ts.hbs +24 -0
  48. package/templates/standalone/knip.ts +23 -0
  49. /package/templates/{angular → federation}/apps/shell/_editorconfig +0 -0
  50. /package/templates/{angular → federation}/apps/shell/angular.json +0 -0
  51. /package/templates/{angular → federation}/apps/shell/federation.config.mjs +0 -0
  52. /package/templates/{angular → federation}/apps/shell/public/federation.manifest.json +0 -0
  53. /package/templates/{angular → federation}/apps/shell/src/app/app.config.ts +0 -0
  54. /package/templates/{angular → federation}/apps/shell/src/app/app.css +0 -0
  55. /package/templates/{angular → federation}/apps/shell/src/app/app.html.hbs +0 -0
  56. /package/templates/{angular → federation}/apps/shell/src/app/app.routes.ts.hbs +0 -0
  57. /package/templates/{angular → federation}/apps/shell/src/app/app.ts +0 -0
  58. /package/templates/{angular → federation}/apps/shell/src/app/core/federation/load-remote.ts +0 -0
  59. /package/templates/{angular → federation}/apps/shell/src/app/core/federation/manifest.spec.ts +0 -0
  60. /package/templates/{angular → federation}/apps/shell/src/app/core/federation/manifest.ts +0 -0
  61. /package/templates/{angular → federation}/apps/shell/src/app/core/federation/remote-loader.ts +0 -0
  62. /package/templates/{angular → federation}/apps/shell/src/app/core/federation/timeout.ts +0 -0
  63. /package/templates/{angular → federation}/apps/shell/src/app/modules/unavailable/unavailable.component.ts +0 -0
  64. /package/templates/{angular → federation}/apps/shell/src/bootstrap.ts +0 -0
  65. /package/templates/{angular → federation}/apps/shell/src/environments/environment.ts +0 -0
  66. /package/templates/{angular → federation}/apps/shell/src/index.html.hbs +0 -0
  67. /package/templates/{angular → federation}/apps/shell/src/main.ts +0 -0
  68. /package/templates/{angular → federation}/apps/shell/src/styles.css +0 -0
  69. /package/templates/{angular → federation}/apps/shell/tsconfig.app.json +0 -0
  70. /package/templates/{angular → federation}/apps/shell/tsconfig.federation.json +0 -0
  71. /package/templates/{angular → federation}/apps/shell/tsconfig.json.hbs +0 -0
  72. /package/templates/{angular → federation}/apps/shell/tsconfig.spec.json +0 -0
  73. /package/templates/{angular → federation}/bahtui.json +0 -0
  74. /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` binary.
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
- bahtui --help
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
- | `bahtui new <name>` | Bare bun workspace in `./<name>` — toolchain only, no apps |
22
- | `bahtui create <name>` | Full DDD monorepo in `./<name>` — React + Elysia + Eden |
23
- | `bahtui create <name> --angular` | Angular Native Federation host + one remote + Elysia + shared kit |
24
- | `bahtui init` | Write `bahtui.json` into an existing repo (enables the generators) |
25
- | `bahtui g model <domain>` | `libs/domain/<domain>/model` package |
26
- | `bahtui g form <domain>/<name> --fields` | Engine-validated `FormDefinition` JSON inside that model package |
27
- | `bahtui g remote <name>` | Angular workspace: another remote, wired into the host and checks |
28
- | `bahtui g deploy [nginx]` | Angular workspace: nginx + systemd deploy, release/deploy/preview |
29
-
30
- ### `bahtui new <name>`
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
- bahtui new acme
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,38 @@ 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
- ### `bahtui create <name>`
76
+ ### `20baht create <name>`
74
77
 
75
- Same flags as `new`, but scaffolds a complete stack:
78
+ Same flags as `new`. The `new` toolchain, plus an app on the family's main stack:
76
79
 
77
80
  ```
78
- apps/web React 19 + Vite on @20baht/ui (tokens, <baht-*> elements, dark toggle)
79
- apps/api Elysia — exports `type App`, the Eden type anchor
80
- libs/shared/eden treaty<App> — the one typed HTTP client
81
- bahtui.json generator config (see below)
81
+ apps/web Angular (:4200): @20baht/angular app shell and navigator, one page calling
82
+ GET /api/hello, a not-found page
83
+ apps/server Elysia under /api (:3001); exports `type App`, emitted to dist/types for the web app
84
+ packages/kit typed ngx-eden client + error text, compiled into the app as @<name>/kit
85
+ bahtui.json { "frontend": "angular", "apps": { "web": "apps/web", ... } }
82
86
  ```
83
87
 
84
88
  ```sh
85
- bahtui create shop
89
+ 20baht create shop
86
90
  cd shop
87
- bun run dev # web on :5173, api on :3001
91
+ bun run dev # web on :4200, server on :3001
88
92
  ```
89
93
 
90
- ### `bahtui create <name> --angular`
94
+ `eslint.config.ts` adds the `angular()` and `bahtui()` presets, `.dependency-cruiser.mjs` "core/,
95
+ services/, shared/ know no page" and "packages know no app". The generated repo passes its own
96
+ `bun run check` (`bun run --filter @20baht/cli accept:angular` proves it: scaffold, install, first
97
+ commit, check). `g remote` and `g deploy` do not apply to it: they need the federation host below.
91
98
 
92
- Same flags. The `new` toolchain, plus microfrontends on
99
+ ### `20baht create <name> --federation`
100
+
101
+ Same flags and the same server and kit as `create`, with the web side as microfrontends on
93
102
  [Native Federation](https://www.npmjs.com/package/@angular-architects/native-federation):
94
103
 
95
104
  ```
96
- apps/shell host (:4200): @20baht/angular app shell, navigator built from the
97
- federation manifest, a fallback page for each remote that cannot load
105
+ apps/shell dynamic host (:4200): reads its remotes from a federation manifest at runtime
106
+ (a remote is added or repointed with no host build); @20baht/angular app
107
+ shell, navigator built from that manifest, a fallback page for each remote that cannot load
98
108
  apps/hello-web remote (:4201): one page calling GET /api/hello, exposed as ./Routes
99
109
  apps/server Elysia under /api; exports `type App`, emitted to dist/types for the web apps
100
110
  packages/kit typed ngx-eden client + error text, compiled into each app as @<name>/kit
@@ -104,8 +114,8 @@ bahtui.json { "frontend": "angular", "apps": { "web": "apps/shell", ... }
104
114
  `eslint.config.ts` adds the `angular()` and `bahtui()` presets for the web apps, `knip.ts` a
105
115
  workspace per app, `.dependency-cruiser.mjs` "apps never import each other", "core/, services/,
106
116
  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:angular` proves it: scaffold, install,
108
- `g remote`, check). What it gets right on purpose:
117
+ `bun run check` (`bun run --filter @20baht/cli accept:federation` proves it: scaffold, install,
118
+ `g remote`, `g deploy`, check, release). What it gets right on purpose:
109
119
 
110
120
  - `features.ignoreUnusedDeps: false` in every `federation.config.mjs` (its scan refuses the kit,
111
121
  which lives outside the app folder), so every dependency is shared and each app lists
@@ -115,18 +125,35 @@ shared/ know no page" and "packages know no app". The generated repo passes its
115
125
  extensionless (Angular's compiler rejects `./x.ts` specifiers).
116
126
  - A remote that is down at boot gets a fallback page under its URL prefix.
117
127
 
118
- ### `bahtui g remote <name>`
128
+ ### `20baht create <name> --react`
129
+
130
+ Same flags. Its own lighter toolchain, not `new`'s:
131
+
132
+ ```
133
+ apps/web React 19 + Vite on @20baht/ui (tokens, <baht-*> elements, dark toggle)
134
+ apps/api Elysia — exports `type App`, the Eden type anchor
135
+ libs/shared/eden treaty<App> — the one typed HTTP client
136
+ bahtui.json generator config (see below)
137
+ ```
119
138
 
120
- In a `create --angular` workspace: `apps/<name>-web` on the next free port, mounted at
139
+ ```sh
140
+ 20baht create shop --react
141
+ cd shop
142
+ bun run dev # web on :5173, api on :3001
143
+ ```
144
+
145
+ ### `20baht g remote <name>`
146
+
147
+ In a `create --federation` workspace: `apps/<name>-web` on the next free port, mounted at
121
148
  `/<name>`, plus a line in `eslint.config.ts`, `knip.ts`, `.dependency-cruiser.mjs`, the dev
122
149
  manifest (`apps/shell/src/environments/environment.development.ts`) and the deployed one
123
150
  (`apps/shell/public/federation.manifest.json`). The TS/JS files carry a `// bahtui:remotes` line
124
151
  the entry goes above; if one is gone, nothing is written and the error names the file. Run
125
152
  `bun install` afterwards.
126
153
 
127
- ### `bahtui g deploy [nginx]`
154
+ ### `20baht g deploy [nginx]`
128
155
 
129
- In a `create --angular` workspace, one web server for everything:
156
+ In a `create --federation` workspace, one web server for everything:
130
157
 
131
158
  ```
132
159
  deploy/nginx.conf host at /, remotes at /remotes/<app>/, /federation.manifest.json from
@@ -143,14 +170,39 @@ scripts/preview.ts bun run preview: serve .release/ like nginx does, on :8
143
170
  It adds the three scripts to `package.json` and `.release` to `.gitignore`, `.prettierignore` and
144
171
  the eslint ignores. It refuses an existing `deploy/` (or existing script names) without `--force`.
145
172
 
146
- ### `bahtui init`
173
+ ### `20baht update [version]`
174
+
175
+ At the root of any repo that uses the libraries (it needs no `bahtui.json`):
176
+
177
+ ```sh
178
+ 20baht update --dry-run # what would change
179
+ 20baht update # every @20baht/* dependency to its latest version, then bun install
180
+ 20baht update 0.2.1 # to 0.2.1 instead, for each library that has a 0.2.1
181
+ ```
182
+
183
+ It reads every `package.json` outside `node_modules`, build output and dot folders, asks the npm
184
+ registry about each `@20baht/*` package it finds there, and edits the dependency lines
185
+ (`dependencies`, `devDependencies`, `peerDependencies`, `optionalDependencies`):
186
+
187
+ - **No version:** each library goes to its own latest. Nothing is lowered.
188
+ - **A version:** each library that has that version is set to it, up or down, so it also rolls
189
+ back. The libraries do not all share one number (`@20baht/ui` and `@20baht/stickers` version
190
+ apart), so the ones without that version are left alone and named.
191
+ - A `^` or `~` is kept. A range it cannot read (`>=0.1.0 <0.2.0`, a tag) is left and reported;
192
+ `workspace:*` is left silently.
193
+
194
+ The files are edited as text, so their formatting stays. If the registry cannot be reached,
195
+ nothing is changed. It touches no other dependency and no source file: read the libraries'
196
+ changelogs for what changed, then run the repo's own check. Flags: `--dry-run`, `--no-install`.
197
+
198
+ ### `20baht init`
147
199
 
148
- Writes `bahtui.json` into the current directory so `bahtui g …` knows where things live.
200
+ Writes `bahtui.json` into the current directory so `20baht g …` knows where things live.
149
201
 
150
202
  ```sh
151
- bahtui init # frontend react, backend elysia
152
- bahtui init --frontend none # no React feature slices
153
- bahtui init --backend none # no Elysia plugins
203
+ 20baht init # frontend react, backend elysia
204
+ 20baht init --frontend none # no React feature slices
205
+ 20baht init --backend none # no Elysia plugins
154
206
  ```
155
207
 
156
208
  ```json
@@ -163,12 +215,12 @@ bahtui init --backend none # no Elysia plugins
163
215
  }
164
216
  ```
165
217
 
166
- ### `bahtui g model <domain>`
218
+ ### `20baht g model <domain>`
167
219
 
168
220
  Creates `<libsDir>/domain/<domain>/model` — a framework-free package for entities and form
169
221
  JSON. `<domain>` is kebab-case.
170
222
 
171
- ### `bahtui g form <domain>/<name> --fields "<dsl>"`
223
+ ### `20baht g form <domain>/<name> --fields "<dsl>"`
172
224
 
173
225
  Builds a `FormDefinition`, validates it with
174
226
  [`@20baht/validator`](https://www.npmjs.com/package/@20baht/validator) (the same
@@ -176,7 +228,7 @@ engine the browser components run), and writes
176
228
  `<libsDir>/domain/<domain>/model/src/<name>.form.json`.
177
229
 
178
230
  ```sh
179
- bahtui g form ticket/create \
231
+ 20baht g form ticket/create \
180
232
  --fields "title:text:required,priority:dropdown:options=low|medium|high,qty:number:min=1"
181
233
  ```
182
234
 
@@ -1,4 +1,4 @@
1
- import { ANGULAR_HOST, overlayTemplates, planCreate, PRESET_TEMPLATE_SETS, } from '../domain/create-plan.js';
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 === 'angular'
43
- ? withFirstRemote(planned, input.name, ANGULAR_HOST, deps.templates.load('remote'), render)
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
- 'bahtui g remote <name> # add another remote',
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 "bahtui init" (or create) first.');
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
- /** `bahtui init` (PRD P2): bahtui.json for an existing repo, paths detected. */
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 — `bahtui g model <domain>` is ready.');
94
+ deps.log.info('bahtui.json written — `20baht g model <domain>` is ready.');
95
95
  }
96
- /** `bahtui g model|form` (PRD P3). Engine-validates before any write. */
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 "bahtui g model ${domain}" first.`);
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
- * `bahtui g remote <name>` in an Angular workspace (`bahtui create --angular`): a new Native
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 config = loadConfig(input.root, deps.reader);
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
- * `bahtui g deploy [nginx]` in an Angular workspace: `deploy/` (nginx.conf, a systemd unit,
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 config = loadConfig(input.root, deps.reader);
223
- if (config.frontend !== 'angular' || config.apps.web === undefined) {
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
@@ -10,6 +10,9 @@ export const KNOWN_FLAGS = new Set([
10
10
  '--no-git',
11
11
  '--skip-install',
12
12
  '--skip-git',
13
+ '--federation',
14
+ '--react',
15
+ // No longer a choice (Angular is what `create` makes); kept known so `create` can say so.
13
16
  '--angular',
14
17
  ]);
15
18
  /**
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 = `bahtui — bun-workspace DDD scaffolding (React or Angular + Elysia + Eden)
15
+ const HELP = `20baht — scaffolding for apps on the @20baht libraries (Angular + Elysia)
14
16
 
15
17
  Usage:
16
- bahtui new <name> [options] bare bun workspace in ./<name> — toolchain only
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
- bahtui create <name> [options] full monorepo in ./<name> (React + Elysia + Eden)
19
- bahtui create <name> --angular Angular Native Federation host + one remote + Elysia
20
- server + shared web kit, on the new toolchain
21
- bahtui init [options] write bahtui.json into an existing repo
22
- bahtui g model <domain> libs/domain/<d>/model package
23
- bahtui g form <domain>/<name> --fields "key:type:mod,…"
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
- bahtui g remote <name> Angular workspace: apps/<name>-web remote, added to the
32
+ 20baht g remote <name> federation workspace: apps/<name>-web remote, added to the
26
33
  host manifests, eslint, knip and dependency-cruiser
27
- bahtui g deploy [nginx] Angular workspace: deploy/ (nginx, systemd, install.sh)
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
- --angular create: the Angular Native Federation scaffold instead of React
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
- return a.flags.has('--angular') ? 'angular' : 'full';
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: bahtui ${command} <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 — bahtui g model <domain> | g form <domain>/<name> | g remote <name> | g deploy.');
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: bahtui g ${name} <${name === 'model' ? 'domain' : 'domain/name'}>`);
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: bahtui g remote <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 ? err.message : String(err));
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
- process.exit(main(process.argv.slice(2)));
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 Angular preset's host app folder. */
9
- export const ANGULAR_HOST = 'apps/shell';
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.