@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
@@ -1,6 +1,6 @@
1
- import { parseSchema } from '@20baht/validator';
1
+ import { BUILT_IN_FIELD_TYPES, parseSchema } from '@20baht/validator';
2
2
  /**
3
- * Compact field DSL for `bahtui g form` (spec 04-adjacent, PRD P3):
3
+ * Compact field DSL for `20baht g form` (spec 04-adjacent, PRD P3):
4
4
  *
5
5
  * --fields "title:text:required,priority:dropdown:options=low|medium|high,qty:number"
6
6
  *
@@ -10,26 +10,10 @@ import { parseSchema } from '@20baht/validator';
10
10
  * The result is engine-validated (parseSchema) BEFORE any file is written —
11
11
  * an invalid spec exits 1 with zero files (the P1 guarantee, kept).
12
12
  */
13
- const FIELD_TYPES = new Set([
14
- 'text',
15
- 'textarea',
16
- 'markdown',
17
- 'number',
18
- 'currency',
19
- 'email',
20
- 'password',
21
- 'dropdown',
22
- 'multiselect',
23
- 'checkbox',
24
- 'radio',
25
- 'toggle',
26
- 'date',
27
- 'file',
28
- 'rating',
29
- 'range',
30
- 'reference',
31
- 'tags',
32
- ]);
13
+ /** Types the DSL has no way to fill in: a static block needs its text, a repeater its columns. */
14
+ const NOT_IN_DSL = new Set(['label', 'section', 'repeater']);
15
+ /** Every other built-in type, read from the engine's list so a new one is offered here too. */
16
+ const FIELD_TYPES = new Set(BUILT_IN_FIELD_TYPES.filter((type) => !NOT_IN_DSL.has(type)));
33
17
  const KEY_PATTERN = /^[a-z][a-z0-9_]*$/;
34
18
  const titleCase = (key) => key
35
19
  .split('_')
@@ -11,7 +11,7 @@ export function validateDomainName(domain) {
11
11
  ? []
12
12
  : [`"${domain}" is not a valid domain name — lowercase letters, digits, dashes.`];
13
13
  }
14
- /** `bahtui init` — write bahtui.json into an existing repo (root = cwd). */
14
+ /** `20baht init` — write bahtui.json into an existing repo (root = cwd). */
15
15
  export function planInit(root, config) {
16
16
  return {
17
17
  root,
@@ -22,7 +22,7 @@ export function planInit(root, config) {
22
22
  export function modelDir(config, domain) {
23
23
  return `${config.libsDir}/domain/${domain}/model`;
24
24
  }
25
- /** `bahtui g model <domain>` — the framework-free domain model lib (PRD). */
25
+ /** `20baht g model <domain>` — the framework-free domain model lib (PRD). */
26
26
  export function planModel(root, config, domain) {
27
27
  const dir = modelDir(config, domain);
28
28
  const pkg = {
@@ -44,7 +44,7 @@ export function planModel(root, config, domain) {
44
44
  postCommands: [],
45
45
  };
46
46
  }
47
- /** `bahtui g form <domain>/<name>` — engine-validated FormDefinition JSON. */
47
+ /** `20baht g form <domain>/<name>` — engine-validated FormDefinition JSON. */
48
48
  export function planForm(root, config, domain, name, form) {
49
49
  const dir = modelDir(config, domain);
50
50
  return {
@@ -0,0 +1,93 @@
1
+ const SCOPE = '@20baht/';
2
+ const DEP_FIELDS = [
3
+ 'dependencies',
4
+ 'devDependencies',
5
+ 'peerDependencies',
6
+ 'optionalDependencies',
7
+ ];
8
+ /** `1.2.3`, with or without a prerelease tag: what a chosen version must look like. */
9
+ export const VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
10
+ /** `^1.2.3`, `~1.2.3` or `1.2.3`; anything else (a range, a tag, `workspace:*`) is not ours to move. */
11
+ const SIMPLE_SPEC = /^([\^~]?)(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/;
12
+ const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
13
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
14
+ export const isPackageJson = (path) => path === 'package.json' || path.endsWith('/package.json');
15
+ /** A version's three numbers, and whether it carries a prerelease tag. */
16
+ function parts(version) {
17
+ const dash = version.indexOf('-');
18
+ const core = dash === -1 ? version : version.slice(0, dash);
19
+ return { numbers: core.split('.').map(Number), prerelease: dash !== -1 };
20
+ }
21
+ /** Whether version `a` is below `b`, by their `x.y.z`; a prerelease is below its release. */
22
+ function below(a, b) {
23
+ const [pa, pb] = [parts(a), parts(b)];
24
+ for (let i = 0; i < 3; i += 1) {
25
+ const [x, y] = [pa.numbers[i] ?? 0, pb.numbers[i] ?? 0];
26
+ if (x !== y)
27
+ return x < y;
28
+ }
29
+ return pa.prerelease && !pb.prerelease;
30
+ }
31
+ /** The `@20baht/*` dependencies a package.json lists, by name, with the range as written. */
32
+ export function familyDependencies(contents) {
33
+ let json;
34
+ try {
35
+ json = JSON.parse(contents);
36
+ }
37
+ catch {
38
+ return null;
39
+ }
40
+ const found = new Map();
41
+ if (!isRecord(json))
42
+ return found;
43
+ for (const field of DEP_FIELDS) {
44
+ const deps = json[field];
45
+ if (!isRecord(deps))
46
+ continue;
47
+ for (const [name, spec] of Object.entries(deps)) {
48
+ if (name.startsWith(SCOPE) && typeof spec === 'string')
49
+ found.set(name, spec);
50
+ }
51
+ }
52
+ return found;
53
+ }
54
+ /**
55
+ * One package.json. Its dependency lines are edited as text, so the file keeps its formatting
56
+ * (`JSON.stringify` would re-wrap arrays and fail the repo's own format check).
57
+ */
58
+ function planFile(file, options, plan) {
59
+ const deps = familyDependencies(file.contents);
60
+ if (deps === null) {
61
+ plan.notes.push(`${file.path}: not valid JSON, left as it is.`);
62
+ return;
63
+ }
64
+ let contents = file.contents;
65
+ for (const [name, spec] of deps) {
66
+ const target = options.targets.get(name);
67
+ if (target === undefined)
68
+ continue;
69
+ const simple = SIMPLE_SPEC.exec(spec);
70
+ if (simple === null) {
71
+ if (!spec.startsWith('workspace:')) {
72
+ plan.notes.push(`${file.path}: ${name} "${spec}" is not a plain version, left as it is.`);
73
+ }
74
+ continue;
75
+ }
76
+ const [, prefix = '', current = ''] = simple;
77
+ if (current === target || (!options.lower && !below(current, target)))
78
+ continue;
79
+ const next = `${prefix}${target}`;
80
+ const line = new RegExp(`"${escapeRegExp(name)}"(\\s*:\\s*)"${escapeRegExp(spec)}"`, 'g');
81
+ contents = contents.replace(line, `"${name}"$1"${next}"`);
82
+ plan.changes.push(`${file.path}: ${name} ${spec} → ${next}`);
83
+ }
84
+ if (contents !== file.contents)
85
+ plan.files.push({ path: file.path, contents });
86
+ }
87
+ export function planUpdate(files, options) {
88
+ const plan = { files: [], changes: [], notes: [] };
89
+ for (const file of files)
90
+ if (isPackageJson(file.path))
91
+ planFile(file, options, plan);
92
+ return plan;
93
+ }
@@ -1,4 +1,5 @@
1
- import { existsSync, readFileSync } from 'node:fs';
1
+ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
2
+ import { join } from 'node:path';
2
3
  export class DiskFileReader {
3
4
  exists(path) {
4
5
  return existsSync(path);
@@ -9,7 +10,7 @@ export class DiskFileReader {
9
10
  }
10
11
  catch (err) {
11
12
  // null strictly means "not there" — callers use it to decide the file is
12
- // absent (e.g. "run bahtui init first"). A permission or IO error must
13
+ // absent (e.g. "run 20baht init first"). A permission or IO error must
13
14
  // surface, not masquerade as a missing file.
14
15
  if (err.code === 'ENOENT')
15
16
  return null;
@@ -17,3 +18,34 @@ export class DiskFileReader {
17
18
  }
18
19
  }
19
20
  }
21
+ /** Folders that hold what was installed or built, never what a person wrote. */
22
+ const SKIPPED_DIRS = new Set(['node_modules', 'dist', 'build', 'coverage', 'out']);
23
+ /** Source and config files: what a command that edits across a repo may read. */
24
+ const TEXT_FILE = /\.(?:[cm]?[jt]sx?|json|s?css|html|astro|vue|svelte)$/;
25
+ const SKIPPED_FILES = new Set(['package-lock.json']);
26
+ /** Past this a file is data or a bundle, not source. */
27
+ const MAX_BYTES = 1_000_000;
28
+ export class DiskFileWalker {
29
+ list(root) {
30
+ const found = [];
31
+ const walk = (dir, prefix) => {
32
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
33
+ const rel = `${prefix}${entry.name}`;
34
+ if (entry.isDirectory()) {
35
+ // Dot folders are caches, VCS and tool state; dot files (`.dependency-cruiser.mjs`) are config.
36
+ if (!entry.name.startsWith('.') && !SKIPPED_DIRS.has(entry.name)) {
37
+ walk(join(dir, entry.name), `${rel}/`);
38
+ }
39
+ }
40
+ else if (entry.isFile() &&
41
+ TEXT_FILE.test(entry.name) &&
42
+ !SKIPPED_FILES.has(entry.name) &&
43
+ statSync(join(dir, entry.name)).size <= MAX_BYTES) {
44
+ found.push(rel);
45
+ }
46
+ }
47
+ };
48
+ walk(root, '');
49
+ return found.sort((a, b) => (a < b ? -1 : 1));
50
+ }
51
+ }
@@ -0,0 +1,28 @@
1
+ const REGISTRY = 'https://registry.npmjs.org';
2
+ const TIMEOUT_MS = 15_000;
3
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
4
+ /** The public npm registry, read over HTTP: no npm on PATH needed, and only a package name is sent. */
5
+ export class NpmRegistry {
6
+ constructor(request = fetch) {
7
+ this.request = request;
8
+ }
9
+ async info(name) {
10
+ const response = await this.request(`${REGISTRY}/${name.replace('/', '%2F')}`, {
11
+ // The abbreviated document: versions and dist-tags without every readme.
12
+ headers: { accept: 'application/vnd.npm.install-v1+json' },
13
+ signal: AbortSignal.timeout(TIMEOUT_MS),
14
+ });
15
+ if (response.status === 404)
16
+ return null;
17
+ if (!response.ok)
18
+ throw new Error(`${name}: HTTP ${String(response.status)}`);
19
+ const body = await response.json();
20
+ const tags = isRecord(body) ? body['dist-tags'] : undefined;
21
+ const latest = isRecord(tags) ? tags.latest : undefined;
22
+ const versions = isRecord(body) ? body.versions : undefined;
23
+ if (typeof latest !== 'string' || !isRecord(versions)) {
24
+ throw new Error(`${name}: the registry's answer has no latest version`);
25
+ }
26
+ return { latest, versions: Object.keys(versions) };
27
+ }
28
+ }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@20baht/cli",
3
- "version": "0.1.2",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
- "description": "Scaffold bun workspaces (bahtui new) and DDD monorepos (React + Elysia + Eden, bahtui create) plus bahtui generators.",
5
+ "description": "Scaffold apps on the @20baht libraries: Angular + Elysia (20baht create), optionally as Native Federation microfrontends, a bare bun workspace (20baht new), plus bahtui generators.",
6
6
  "license": "MIT",
7
7
  "author": "Nattapong Promthong",
8
8
  "repository": {
@@ -22,7 +22,9 @@
22
22
  "bun",
23
23
  "elysia",
24
24
  "eden",
25
- "react"
25
+ "react",
26
+ "angular",
27
+ "native-federation"
26
28
  ],
27
29
  "publishConfig": {
28
30
  "access": "public"
@@ -31,7 +33,7 @@
31
33
  "node": ">=20.12"
32
34
  },
33
35
  "bin": {
34
- "bahtui": "./dist/cli.js"
36
+ "20baht": "./dist/cli.js"
35
37
  },
36
38
  "files": [
37
39
  "dist",
@@ -42,14 +44,15 @@
42
44
  "test": "vitest run",
43
45
  "test:watch": "vitest",
44
46
  "test:coverage": "vitest run --coverage",
45
- "accept:angular": "bun scripts/accept-angular.ts"
47
+ "accept:angular": "bun scripts/accept-angular.ts",
48
+ "accept:federation": "bun scripts/accept-angular.ts federation"
46
49
  },
47
50
  "dependencies": {
48
- "@20baht/validator": ">=0.1.0 <0.2.0"
51
+ "@20baht/validator": ">=0.3.0 <0.4.0"
49
52
  },
50
53
  "devDependencies": {
51
54
  "@types/node": "^22",
52
- "typescript": "^5.8.3",
55
+ "typescript": "^5.9.3",
53
56
  "vitest": "^3.2.4"
54
57
  }
55
58
  }
@@ -34,7 +34,7 @@
34
34
  "@eslint/js": "^10.0.1",
35
35
  "@types/bun": "^1.3.0",
36
36
  "angular-eslint": "22.5.0",
37
- "@20baht/strict": "0.1.2",
37
+ "@20baht/strict": "0.3.0",
38
38
  "dependency-cruiser": "^18.3.1",
39
39
  "eslint": "^10.10.0",
40
40
  "eslint-config-prettier": "^10.1.8",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "@{{name}}/eden": "workspace:*",
12
- "@20baht/ui": "^0.1.0",
12
+ "@20baht/ui": "^0.3.0",
13
13
  "react": "^19.1.0",
14
14
  "react-dom": "^19.1.0"
15
15
  },
@@ -1,7 +1,7 @@
1
1
  # {{name}}
2
2
 
3
3
  Angular microfrontends on Native Federation, scaffolded by
4
- [`@20baht/cli`](https://github.com/bank20baht/20baht) (`bahtui create --angular`).
4
+ [`@20baht/cli`](https://github.com/bank20baht/20baht) (`20baht create --federation`).
5
5
 
6
6
  ```
7
7
  apps/shell the host (:4200): navigator from the federation manifest, a fallback page per remote
@@ -21,7 +21,7 @@ bun run check # lint, format, typecheck, madge, boundaries, knip, dup, buil
21
21
  ## Add a remote
22
22
 
23
23
  ```sh
24
- bahtui g remote orders # apps/orders-web on the next port, mounted at /orders
24
+ 20baht g remote orders # apps/orders-web on the next port, mounted at /orders
25
25
  bun install
26
26
  ```
27
27
 
@@ -8,7 +8,7 @@ import { makeConfig } from '@20baht/strict/depcruise'
8
8
 
9
9
  const HOST = 'shell'
10
10
 
11
- /** `bahtui g remote` adds a line. */
11
+ /** `20baht g remote` adds a line. */
12
12
  const REMOTES = [
13
13
  // bahtui:remotes
14
14
  ]
@@ -19,9 +19,9 @@
19
19
  "@angular/core": "^22.2.0",
20
20
  "@angular/platform-browser": "^22.2.0",
21
21
  "@angular/router": "^22.2.0",
22
- "@20baht/engine": "0.1.2",
23
- "@20baht/ui": "0.1.2",
24
- "@20baht/angular": "0.1.2",
22
+ "@20baht/engine": "0.3.0",
23
+ "@20baht/ui": "0.3.0",
24
+ "@20baht/angular": "0.3.0",
25
25
  "dompurify": "3.4.17",
26
26
  "es-module-shims": "^2.8.0",
27
27
  "flatpickr": "4.6.13",
@@ -29,7 +29,7 @@ import { MANIFEST } from '../../core/federation/remote-loader'
29
29
  } @empty {
30
30
  <baht-empty-state
31
31
  message="No remotes yet"
32
- hint="Add one with bahtui g remote, then restart bun run dev."
32
+ hint="Add one with 20baht g remote, then restart bun run dev."
33
33
  ></baht-empty-state>
34
34
  }
35
35
  </div>
@@ -1,6 +1,6 @@
1
1
  import type { Manifest } from '../app/core/federation/manifest'
2
2
 
3
- /** The remotes on their dev servers (`bun run dev`). `bahtui g remote` adds an entry. */
3
+ /** The remotes on their dev servers (`bun run dev`). `20baht g remote` adds an entry. */
4
4
  const remotes: Manifest = {
5
5
  // bahtui:remotes
6
6
  }
@@ -2,7 +2,7 @@ import { defineConfig } from 'eslint/config'
2
2
 
3
3
  import { angular, bahtui, base } from '@20baht/strict/eslint'
4
4
 
5
- /** The host, its remotes, and the kit they all compile in. `bahtui g remote` adds a line. */
5
+ /** The host, its remotes, and the kit they all compile in. `20baht g remote` adds a line. */
6
6
  const WEB = [
7
7
  'apps/shell/src/**',
8
8
  'packages/kit/src/**',
@@ -1,7 +1,7 @@
1
1
  # {{name}}
2
2
 
3
3
  Bun-workspace monorepo scaffolded by [`@20baht/cli`](https://github.com/bank20baht/20baht)
4
- (`bahtui new`). Toolchain only — add your own apps under `apps/*` and shared
4
+ (`20baht new`). Toolchain only — add your own apps under `apps/*` and shared
5
5
  libraries under `packages/*`.
6
6
 
7
7
  ## Quickstart
@@ -33,7 +33,7 @@
33
33
  "@eslint/css": "^2.0.0",
34
34
  "@eslint/js": "^10.0.1",
35
35
  "@types/bun": "^1.3.0",
36
- "@20baht/strict": "0.1.2",
36
+ "@20baht/strict": "0.3.0",
37
37
  "dependency-cruiser": "^18.3.1",
38
38
  "eslint": "^10.10.0",
39
39
  "eslint-config-prettier": "^10.1.8",
@@ -17,9 +17,9 @@
17
17
  "@angular/core": "^22.2.0",
18
18
  "@angular/platform-browser": "^22.2.0",
19
19
  "@angular/router": "^22.2.0",
20
- "@20baht/engine": "0.1.2",
21
- "@20baht/ui": "0.1.2",
22
- "@20baht/angular": "0.1.2",
20
+ "@20baht/engine": "0.3.0",
21
+ "@20baht/ui": "0.3.0",
22
+ "@20baht/angular": "0.3.0",
23
23
  "dompurify": "3.4.17",
24
24
  "es-module-shims": "^2.8.0",
25
25
  "flatpickr": "4.6.13",
@@ -0,0 +1,36 @@
1
+ # {{name}}
2
+
3
+ An Angular app and an Elysia server on the `@20baht` libraries, scaffolded by
4
+ [`@20baht/cli`](https://github.com/bank20baht/20baht) (`20baht create`).
5
+
6
+ ```
7
+ apps/web the Angular app (:4200): @20baht/ui app shell, one page calling one API route
8
+ apps/server Elysia API (:3001) under /api; exports `type App` as built declarations
9
+ packages/kit the typed ngx-eden client and error text, compiled into the app as @{{name}}/kit
10
+ ```
11
+
12
+ ## Quickstart
13
+
14
+ ```sh
15
+ bun install
16
+ bun run dev # every apps/* dev script in parallel
17
+ bun run check # lint, format, typecheck, madge, boundaries, knip, dup, build, test
18
+ ```
19
+
20
+ ## Add a page
21
+
22
+ A component under `apps/web/src/app/modules/<page>/`, a route in `app.routes.ts`, an entry in
23
+ `core/navigation/navigation.ts`. What a page asks the server goes in a service under `services/`,
24
+ through the kit's `Api`.
25
+
26
+ ## Things that are this way on purpose
27
+
28
+ - The web app sees the server only as types, from `apps/server/dist/types` (`build:types` runs
29
+ before every web build and typecheck). Keep the server's imports extensionless: Angular's
30
+ compiler rejects `./x.ts` specifiers in sources it follows.
31
+ - `apps/web` lists `marked`, `dompurify` and `flatpickr`: they are optional peers of @20baht/ui,
32
+ which imports them when a markdown or date field renders.
33
+ - In dev the app calls the server on `:3001`; in production it calls `/api` on its own origin, so
34
+ serve both behind one web server.
35
+ - This is one app. Microfrontends on Native Federation (a host that reads its remotes from a
36
+ manifest at runtime) are another scaffold: `20baht create <name> --federation`.
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Architecture boundaries, checked with `bun run deps`. `generic` gives no-circular and
3
+ * production-not-tests. The rules below keep the web app's layers and the packages in order.
4
+ * Every rule is `error`: a violation is a decision, not a warning.
5
+ */
6
+ import { makeConfig } from '@20baht/strict/depcruise'
7
+
8
+ const base = makeConfig({ generic: true })
9
+
10
+ export default {
11
+ ...base,
12
+ forbidden: [
13
+ ...base.forbidden,
14
+ {
15
+ name: 'web-lower-layers-know-no-page',
16
+ severity: 'error',
17
+ comment: 'core/, services/ and shared/ know no page; pages are reached through the router.',
18
+ from: { path: '^apps/web/src/app/(core|services|shared)/' },
19
+ to: { path: '^apps/web/src/app/modules/' },
20
+ },
21
+ {
22
+ name: 'packages-know-no-app',
23
+ severity: 'error',
24
+ comment: 'packages/ are below the apps; the server reaches them only as built types.',
25
+ from: { path: '^packages/' },
26
+ to: { path: '^apps/', pathNot: '^apps/server/dist/types/' },
27
+ },
28
+ ],
29
+ }
@@ -0,0 +1,17 @@
1
+ # Editor configuration, see https://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ charset = utf-8
6
+ indent_style = space
7
+ indent_size = 2
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+
11
+ [*.ts]
12
+ quote_type = single
13
+ ij_typescript_use_double_quotes = false
14
+
15
+ [*.md]
16
+ max_line_length = off
17
+ trim_trailing_whitespace = false
@@ -0,0 +1,72 @@
1
+ {
2
+ "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3
+ "version": 1,
4
+ "cli": {
5
+ "packageManager": "bun"
6
+ },
7
+ "newProjectRoot": "projects",
8
+ "projects": {
9
+ "web": {
10
+ "projectType": "application",
11
+ "schematics": {},
12
+ "root": "",
13
+ "sourceRoot": "src",
14
+ "prefix": "app",
15
+ "architect": {
16
+ "build": {
17
+ "builder": "@angular/build:application",
18
+ "options": {
19
+ "browser": "src/main.ts",
20
+ "tsConfig": "tsconfig.app.json",
21
+ "styles": ["node_modules/@20baht/ui/dist/tokens.css", "src/styles.css"]
22
+ },
23
+ "configurations": {
24
+ "production": {
25
+ "budgets": [
26
+ {
27
+ "type": "initial",
28
+ "maximumWarning": "500kB",
29
+ "maximumError": "1MB"
30
+ },
31
+ {
32
+ "type": "anyComponentStyle",
33
+ "maximumWarning": "4kB",
34
+ "maximumError": "8kB"
35
+ }
36
+ ],
37
+ "outputHashing": "all"
38
+ },
39
+ "development": {
40
+ "optimization": false,
41
+ "extractLicenses": false,
42
+ "sourceMap": true
43
+ }
44
+ },
45
+ "defaultConfiguration": "production"
46
+ },
47
+ "serve": {
48
+ "builder": "@angular/build:dev-server",
49
+ "configurations": {
50
+ "production": {
51
+ "buildTarget": "web:build:production"
52
+ },
53
+ "development": {
54
+ "buildTarget": "web:build:development"
55
+ }
56
+ },
57
+ "defaultConfiguration": "development",
58
+ "options": {
59
+ "port": 4200
60
+ }
61
+ },
62
+ "test": {
63
+ "builder": "@angular/build:unit-test",
64
+ "options": {
65
+ "coverageReporters": ["text", "lcov"],
66
+ "coverageExclude": ["src/main.ts"]
67
+ }
68
+ }
69
+ }
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "web",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "ng": "ng",
7
+ "dev": "ng serve",
8
+ "build": "ng build",
9
+ "test": "ng test",
10
+ "test:coverage": "ng test --watch=false --coverage",
11
+ "typecheck": "tsc -b --noEmit",
12
+ "pretypecheck": "bun run --filter server build:types",
13
+ "prebuild": "bun run --filter server build:types"
14
+ },
15
+ "dependencies": {
16
+ "@angular/common": "^22.2.0",
17
+ "@angular/compiler": "^22.2.0",
18
+ "@angular/core": "^22.2.0",
19
+ "@angular/platform-browser": "^22.2.0",
20
+ "@angular/router": "^22.2.0",
21
+ "@20baht/ui": "0.3.0",
22
+ "@20baht/angular": "0.3.0",
23
+ "dompurify": "3.4.17",
24
+ "flatpickr": "4.6.13",
25
+ "marked": "18.1.3",
26
+ "@20baht/ngx-eden": "^0.1.0",
27
+ "rxjs": "~7.8.0",
28
+ "tslib": "^2.3.0"
29
+ },
30
+ "devDependencies": {
31
+ "@angular/build": "^22.2.0",
32
+ "@angular/cli": "^22.2.0",
33
+ "@angular/compiler-cli": "^22.2.0",
34
+ "@vitest/coverage-v8": "^4.0.8",
35
+ "jsdom": "^30.0.0",
36
+ "typescript": "~6.0.2",
37
+ "vitest": "^4.0.8"
38
+ }
39
+ }
@@ -0,0 +1,14 @@
1
+ import type { ApplicationConfig } from '@angular/core'
2
+ import { provideBrowserGlobalErrorListeners } from '@angular/core'
3
+ import { provideHttpClient } from '@angular/common/http'
4
+ import { provideRouter, withComponentInputBinding } from '@angular/router'
5
+ import { routes } from './app.routes'
6
+
7
+ /** The router and the `HttpClient` the kit's typed API client (`Api`) sends through. */
8
+ export const appConfig: ApplicationConfig = {
9
+ providers: [
10
+ provideBrowserGlobalErrorListeners(),
11
+ provideRouter(routes, withComponentInputBinding()),
12
+ provideHttpClient(),
13
+ ],
14
+ }
@@ -0,0 +1,4 @@
1
+ .shell-main {
2
+ display: block;
3
+ min-width: 0;
4
+ }
@@ -0,0 +1,16 @@
1
+ <baht-app-shell
2
+ brand="{{name}}"
3
+ brand-href="/"
4
+ label="{{name}}"
5
+ [items]="items"
6
+ [value]="current()"
7
+ (baht-nav)="navigate($event)"
8
+ >
9
+ <div data-slot="actions">
10
+ <baht-theme-toggle default="system"></baht-theme-toggle>
11
+ </div>
12
+ <main class="shell-main">
13
+ <router-outlet />
14
+ </main>
15
+ </baht-app-shell>
16
+ <baht-toast></baht-toast>