@20baht/cli 0.0.0-stage → 0.1.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 (140) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +214 -2
  3. package/dist/application/create.js +72 -0
  4. package/dist/application/generate.js +239 -0
  5. package/dist/application/ports.js +1 -0
  6. package/dist/args.js +49 -0
  7. package/dist/cli.js +207 -0
  8. package/dist/domain/blueprint.js +6 -0
  9. package/dist/domain/create-plan.js +59 -0
  10. package/dist/domain/deploy-plan.js +82 -0
  11. package/dist/domain/form-dsl.js +120 -0
  12. package/dist/domain/generate-plan.js +60 -0
  13. package/dist/domain/naming.js +18 -0
  14. package/dist/domain/remote-plan.js +153 -0
  15. package/dist/domain/template-path.js +19 -0
  16. package/dist/infrastructure/fs-reader.js +19 -0
  17. package/dist/infrastructure/fs-writer.js +27 -0
  18. package/dist/infrastructure/shell-runner.js +32 -0
  19. package/dist/infrastructure/spawn-plan.js +35 -0
  20. package/dist/infrastructure/template-renderer.js +16 -0
  21. package/dist/infrastructure/template-source.js +28 -0
  22. package/package.json +53 -4
  23. package/templates/angular/README.md.hbs +46 -0
  24. package/templates/angular/_dependency-cruiser.mjs +51 -0
  25. package/templates/angular/apps/server/package.json +30 -0
  26. package/templates/angular/apps/server/src/app.ts +14 -0
  27. package/templates/angular/apps/server/src/index.ts +8 -0
  28. package/templates/angular/apps/server/test/app.test.ts +12 -0
  29. package/templates/angular/apps/server/tsconfig.json +7 -0
  30. package/templates/angular/apps/server/tsconfig.types.json +12 -0
  31. package/templates/angular/apps/shell/_editorconfig +17 -0
  32. package/templates/angular/apps/shell/angular.json +115 -0
  33. package/templates/angular/apps/shell/federation.config.mjs +44 -0
  34. package/templates/angular/apps/shell/package.json +43 -0
  35. package/templates/angular/apps/shell/public/federation.manifest.json +1 -0
  36. package/templates/angular/apps/shell/src/app/app.config.ts +20 -0
  37. package/templates/angular/apps/shell/src/app/app.css +4 -0
  38. package/templates/angular/apps/shell/src/app/app.html.hbs +16 -0
  39. package/templates/angular/apps/shell/src/app/app.routes.ts.hbs +39 -0
  40. package/templates/angular/apps/shell/src/app/app.ts +57 -0
  41. package/templates/angular/apps/shell/src/app/core/federation/load-remote.ts +31 -0
  42. package/templates/angular/apps/shell/src/app/core/federation/manifest.spec.ts +46 -0
  43. package/templates/angular/apps/shell/src/app/core/federation/manifest.ts +37 -0
  44. package/templates/angular/apps/shell/src/app/core/federation/remote-loader.ts +20 -0
  45. package/templates/angular/apps/shell/src/app/core/federation/timeout.ts +17 -0
  46. package/templates/angular/apps/shell/src/app/modules/home/home.component.ts.hbs +46 -0
  47. package/templates/angular/apps/shell/src/app/modules/unavailable/unavailable.component.ts +39 -0
  48. package/templates/angular/apps/shell/src/bootstrap.ts +25 -0
  49. package/templates/angular/apps/shell/src/environments/environment.development.ts +10 -0
  50. package/templates/angular/apps/shell/src/environments/environment.ts +10 -0
  51. package/templates/angular/apps/shell/src/index.html.hbs +12 -0
  52. package/templates/angular/apps/shell/src/main.ts +43 -0
  53. package/templates/angular/apps/shell/src/styles.css +19 -0
  54. package/templates/angular/apps/shell/tsconfig.app.json +10 -0
  55. package/templates/angular/apps/shell/tsconfig.federation.json +4 -0
  56. package/templates/angular/apps/shell/tsconfig.json.hbs +39 -0
  57. package/templates/angular/apps/shell/tsconfig.spec.json +9 -0
  58. package/templates/angular/bahtui.json +6 -0
  59. package/templates/angular/eslint.config.ts.hbs +28 -0
  60. package/templates/angular/knip.ts +30 -0
  61. package/templates/angular/package.json.hbs +52 -0
  62. package/templates/angular/packages/kit/package.json.hbs +27 -0
  63. package/templates/angular/packages/kit/src/api.ts +21 -0
  64. package/templates/angular/packages/kit/src/errors.ts +28 -0
  65. package/templates/angular/packages/kit/src/index.ts +2 -0
  66. package/templates/angular/packages/kit/test/errors.test.ts +28 -0
  67. package/templates/angular/packages/kit/tsconfig.json +9 -0
  68. package/templates/create/README.md.hbs +32 -0
  69. package/templates/create/_github/workflows/ci.yml +56 -0
  70. package/templates/create/_gitignore +6 -0
  71. package/templates/create/_husky/pre-commit +3 -0
  72. package/templates/create/_prettierignore +3 -0
  73. package/templates/create/_prettierrc.json +4 -0
  74. package/templates/create/apps/api/package.json.hbs +21 -0
  75. package/templates/create/apps/api/src/index.test.ts.hbs +10 -0
  76. package/templates/create/apps/api/src/index.ts.hbs +14 -0
  77. package/templates/create/apps/api/tsconfig.json +7 -0
  78. package/templates/create/apps/web/index.html.hbs +20 -0
  79. package/templates/create/apps/web/package.json.hbs +24 -0
  80. package/templates/create/apps/web/src/App.tsx.hbs +31 -0
  81. package/templates/create/apps/web/src/app.css +27 -0
  82. package/templates/create/apps/web/src/health.test.ts.hbs +28 -0
  83. package/templates/create/apps/web/src/health.ts.hbs +14 -0
  84. package/templates/create/apps/web/src/main.tsx.hbs +20 -0
  85. package/templates/create/apps/web/src/vite-env.d.ts.hbs +1 -0
  86. package/templates/create/apps/web/tsconfig.json +8 -0
  87. package/templates/create/apps/web/vite.config.ts.hbs +6 -0
  88. package/templates/create/bahtui.json.hbs +7 -0
  89. package/templates/create/eslint.config.js +30 -0
  90. package/templates/create/knip.json +9 -0
  91. package/templates/create/libs/shared/eden/index.ts.hbs +9 -0
  92. package/templates/create/libs/shared/eden/package.json.hbs +15 -0
  93. package/templates/create/libs/shared/eden/tsconfig.json +4 -0
  94. package/templates/create/package.json.hbs +47 -0
  95. package/templates/create/tsconfig.base.json +17 -0
  96. package/templates/deploy/deploy/__project__.service.hbs +23 -0
  97. package/templates/deploy/deploy/env.example.hbs +4 -0
  98. package/templates/deploy/deploy/install.sh.hbs +58 -0
  99. package/templates/deploy/deploy/nginx.conf.hbs +67 -0
  100. package/templates/deploy/scripts/deploy.ts.hbs +33 -0
  101. package/templates/deploy/scripts/preview.ts.hbs +57 -0
  102. package/templates/deploy/scripts/release.ts.hbs +48 -0
  103. package/templates/new/CLAUDE.md +3 -0
  104. package/templates/new/README.md.hbs +38 -0
  105. package/templates/new/_dependency-cruiser.mjs +9 -0
  106. package/templates/new/_github/actions/setup/action.yml +15 -0
  107. package/templates/new/_github/workflows/ci.yml +122 -0
  108. package/templates/new/_gitignore +12 -0
  109. package/templates/new/_gitleaks.toml +6 -0
  110. package/templates/new/_husky/commit-msg +1 -0
  111. package/templates/new/_husky/pre-commit +8 -0
  112. package/templates/new/_husky/pre-push +1 -0
  113. package/templates/new/_jscpd.json +20 -0
  114. package/templates/new/_mcp.json +9 -0
  115. package/templates/new/_prettierignore +5 -0
  116. package/templates/new/apps/_gitkeep +0 -0
  117. package/templates/new/commitlint.config.js +1 -0
  118. package/templates/new/eslint.config.ts.hbs +7 -0
  119. package/templates/new/knip.ts +7 -0
  120. package/templates/new/lint-staged.config.js +1 -0
  121. package/templates/new/package.json.hbs +51 -0
  122. package/templates/new/packages/_gitkeep +0 -0
  123. package/templates/new/renovate.json +23 -0
  124. package/templates/new/scripts/dev.ts +54 -0
  125. package/templates/new/scripts/each.ts +29 -0
  126. package/templates/new/scripts/workspaces.ts +24 -0
  127. package/templates/new/tsconfig.base.json +3 -0
  128. package/templates/new/tsconfig.json +7 -0
  129. package/templates/remote/_editorconfig +17 -0
  130. package/templates/remote/angular.json.hbs +95 -0
  131. package/templates/remote/federation.config.mjs.hbs +48 -0
  132. package/templates/remote/package.json.hbs +38 -0
  133. package/templates/remote/src/app/__name__.routes.ts.hbs +12 -0
  134. package/templates/remote/src/app/modules/__name__/__name__.component.ts.hbs +37 -0
  135. package/templates/remote/src/app/services/__name__.service.ts.hbs +14 -0
  136. package/templates/remote/src/index.html.hbs +11 -0
  137. package/templates/remote/src/main.ts.hbs +3 -0
  138. package/templates/remote/tsconfig.app.json +10 -0
  139. package/templates/remote/tsconfig.federation.json +4 -0
  140. package/templates/remote/tsconfig.json.hbs +36 -0
@@ -0,0 +1,28 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import { describeHealth, healthTone } from './health';
3
+
4
+ const service = '{{name}}-api';
5
+
6
+ describe('describeHealth', () => {
7
+ it('formats a healthy response', () => {
8
+ expect(describeHealth({ status: 'ok', service })).toBe(`${service} is ok`);
9
+ });
10
+
11
+ it('handles a missing response', () => {
12
+ expect(describeHealth(null)).toBe('no response from api');
13
+ });
14
+ });
15
+
16
+ describe('healthTone', () => {
17
+ it('is success when the api says ok', () => {
18
+ expect(healthTone({ status: 'ok', service })).toBe('success');
19
+ });
20
+
21
+ it('is warning for any other status', () => {
22
+ expect(healthTone({ status: 'degraded', service })).toBe('warning');
23
+ });
24
+
25
+ it('is danger with no response', () => {
26
+ expect(healthTone(null)).toBe('danger');
27
+ });
28
+ });
@@ -0,0 +1,14 @@
1
+ export type Health = { status: string; service: string } | null;
2
+
3
+ /** `<baht-badge>` status tones the health line uses. */
4
+ export type HealthTone = 'success' | 'danger' | 'warning';
5
+
6
+ export function describeHealth(health: Health): string {
7
+ if (!health) return 'no response from api';
8
+ return `${health.service} is ${health.status}`;
9
+ }
10
+
11
+ export function healthTone(health: Health): HealthTone {
12
+ if (!health) return 'danger';
13
+ return health.status === 'ok' ? 'success' : 'warning';
14
+ }
@@ -0,0 +1,20 @@
1
+ import { StrictMode } from 'react';
2
+ import { createRoot } from 'react-dom/client';
3
+ // Register only the <baht-*> elements this app renders (one subpath per tag).
4
+ // `import '@20baht/ui'` registers all of them, at ~4x the bundle.
5
+ import '@20baht/ui/components/badge';
6
+ import '@20baht/ui/components/card';
7
+ import '@20baht/ui/components/theme-toggle';
8
+ import '@20baht/ui/react'; // JSX typings for every <baht-*>
9
+ import '@20baht/ui/tokens.css';
10
+ import './app.css';
11
+ import App from './App';
12
+
13
+ const root = document.getElementById('root');
14
+ if (!root) throw new Error('#root missing from index.html');
15
+
16
+ createRoot(root).render(
17
+ <StrictMode>
18
+ <App />
19
+ </StrictMode>,
20
+ );
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "jsx": "react-jsx",
5
+ "types": ["vite/client", "bun"]
6
+ },
7
+ "include": ["src", "vite.config.ts"]
8
+ }
@@ -0,0 +1,6 @@
1
+ import { defineConfig } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+
4
+ export default defineConfig({
5
+ plugins: [react()],
6
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "apps": { "web": "apps/web", "api": "apps/api" },
3
+ "libsDir": "libs",
4
+ "frontend": "react",
5
+ "backend": "elysia",
6
+ "edenClient": "libs/shared/eden"
7
+ }
@@ -0,0 +1,30 @@
1
+ import js from '@eslint/js';
2
+ import tseslint from 'typescript-eslint';
3
+ import reactHooks from 'eslint-plugin-react-hooks';
4
+ import prettier from 'eslint-config-prettier';
5
+ import globals from 'globals';
6
+
7
+ export default tseslint.config(
8
+ { ignores: ['**/dist/**', '**/node_modules/**'] },
9
+ js.configs.recommended,
10
+ ...tseslint.configs.recommended,
11
+ {
12
+ languageOptions: {
13
+ globals: { ...globals.browser, ...globals.node },
14
+ },
15
+ rules: {
16
+ '@typescript-eslint/no-unused-vars': [
17
+ 'error',
18
+ { argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
19
+ ],
20
+ '@typescript-eslint/consistent-type-imports': 'error',
21
+ },
22
+ },
23
+ {
24
+ files: ['apps/web/**/*.{ts,tsx}'],
25
+ plugins: { 'react-hooks': reactHooks },
26
+ rules: reactHooks.configs.recommended.rules,
27
+ },
28
+ // must come last — disables rules that fight Prettier
29
+ prettier,
30
+ );
@@ -0,0 +1,9 @@
1
+ {
2
+ "$schema": "https://unpkg.com/knip@6/schema.json",
3
+ "workspaces": {
4
+ ".": {},
5
+ "apps/web": {},
6
+ "apps/api": {},
7
+ "libs/shared/eden": {}
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ import { treaty } from '@elysiajs/eden';
2
+ import type { App } from '@{{name}}/api';
3
+
4
+ /**
5
+ * The ONE http client of the monorepo. Fully typed end-to-end: every route,
6
+ * body and response comes from apps/api's `App` type — no codegen, no drift.
7
+ * Point it elsewhere per environment by editing this single spot.
8
+ */
9
+ export const api = treaty<App>('http://localhost:3001');
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@{{name}}/eden",
3
+ "private": true,
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./index.ts"
7
+ },
8
+ "dependencies": {
9
+ "@elysiajs/eden": "^1.3.0"
10
+ },
11
+ "devDependencies": {
12
+ "@{{name}}/api": "workspace:*",
13
+ "typescript": "^5.8.3"
14
+ }
15
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.base.json",
3
+ "include": ["index.ts"]
4
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "{{name}}-monorepo",
3
+ "private": true,
4
+ "type": "module",
5
+ "workspaces": [
6
+ "apps/*",
7
+ "libs/**"
8
+ ],
9
+ "scripts": {
10
+ "dev": "bun run --filter './apps/*' dev",
11
+ "build": "bun run --filter './apps/*' build",
12
+ "test": "bun run --filter './apps/*' test",
13
+ "lint": "eslint .",
14
+ "lint:fix": "eslint . --fix",
15
+ "format": "prettier --write .",
16
+ "format:check": "prettier --check .",
17
+ "knip": "knip",
18
+ "deps:circular": "madge --circular --extensions ts,tsx --exclude '(^|/)(dist|node_modules)/' apps libs",
19
+ "prepare": "husky"
20
+ },
21
+ "lint-staged": {
22
+ "*.{ts,tsx}": [
23
+ "eslint --fix",
24
+ "prettier --write"
25
+ ],
26
+ "*.{css,json,js,mjs}": [
27
+ "prettier --write"
28
+ ]
29
+ },
30
+ "trustedDependencies": [
31
+ "esbuild"
32
+ ],
33
+ "devDependencies": {
34
+ "@eslint/js": "^10.0.1",
35
+ "eslint": "^10.6.0",
36
+ "eslint-config-prettier": "^10.1.8",
37
+ "eslint-plugin-react-hooks": "^7.1.1",
38
+ "globals": "^17.7.0",
39
+ "husky": "^9.1.7",
40
+ "knip": "^6.24.0",
41
+ "lint-staged": "^17.0.8",
42
+ "madge": "^8.0.0",
43
+ "prettier": "^3.9.4",
44
+ "typescript": "^5.8.3",
45
+ "typescript-eslint": "^8.62.1"
46
+ }
47
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "strict": true,
8
+ "noUncheckedIndexedAccess": true,
9
+ "noImplicitOverride": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "skipLibCheck": true,
12
+ "isolatedModules": true,
13
+ "verbatimModuleSyntax": true,
14
+ "resolveJsonModule": true,
15
+ "noEmit": true
16
+ }
17
+ }
@@ -0,0 +1,23 @@
1
+ [Unit]
2
+ Description={{project}} API server
3
+ After=network-online.target
4
+ Wants=network-online.target
5
+
6
+ [Service]
7
+ User={{project}}
8
+ Group={{project}}
9
+ WorkingDirectory=/var/lib/{{project}}
10
+ EnvironmentFile=/etc/{{project}}/env
11
+ ExecStart=/usr/local/bin/bun /opt/{{project}}/server/index.js
12
+ Restart=on-failure
13
+ RestartSec=3
14
+
15
+ # It only needs its own folder and the network.
16
+ NoNewPrivileges=true
17
+ ProtectSystem=strict
18
+ ProtectHome=true
19
+ PrivateTmp=true
20
+ ReadWritePaths=/var/lib/{{project}}
21
+
22
+ [Install]
23
+ WantedBy=multi-user.target
@@ -0,0 +1,4 @@
1
+ # /etc/{{project}}/env, read by {{project}}.service. Created once by install.sh; edit it there.
2
+
3
+ # nginx is in front on the same machine and proxies /api/ here.
4
+ PORT={{apiPort}}
@@ -0,0 +1,58 @@
1
+ #!/bin/sh
2
+ # Runs on the target, as root, from the unpacked release (scripts/deploy.ts does that).
3
+ # Safe to run again: the first run sets the machine up, every run installs the release.
4
+ set -eu
5
+
6
+ RELEASE=$(cd "$(dirname "$0")" && pwd)
7
+ APP={{project}}
8
+
9
+ if ! command -v nginx >/dev/null 2>&1 || ! command -v curl >/dev/null 2>&1; then
10
+ export DEBIAN_FRONTEND=noninteractive
11
+ apt-get update -qq
12
+ apt-get install -y -qq nginx curl unzip ca-certificates
13
+ fi
14
+
15
+ if [ ! -x /usr/local/bin/bun ]; then
16
+ # bun's installer is a bash script (dash, Debian's sh, refuses its `set -o pipefail`).
17
+ curl -fsSL https://bun.sh/install | BUN_INSTALL=/usr/local bash >/dev/null
18
+ fi
19
+
20
+ id "$APP" >/dev/null 2>&1 || useradd --system --home "/var/lib/$APP" --shell /usr/sbin/nologin "$APP"
21
+ install -d -o "$APP" -g "$APP" "/var/lib/$APP"
22
+ install -d "/etc/$APP" "/opt/$APP" "/var/www/$APP"
23
+
24
+ # Settings are written once and never overwritten: they hold what was set on this machine.
25
+ if [ ! -f "/etc/$APP/env" ]; then
26
+ install -m 640 -o root -g "$APP" "$RELEASE/env.example" "/etc/$APP/env"
27
+ echo "created /etc/$APP/env"
28
+ fi
29
+ if [ ! -f "/etc/$APP/federation.manifest.json" ]; then
30
+ install -m 644 "$RELEASE/federation.manifest.json" "/etc/$APP/federation.manifest.json"
31
+ fi
32
+
33
+ # The release itself: swap whole folders so a half-copied one is never served.
34
+ for part in server www; do
35
+ rm -rf "/opt/$APP/$part.new"
36
+ cp -R "$RELEASE/$part" "/opt/$APP/$part.new"
37
+ done
38
+ rm -rf "/opt/$APP/server.old" && { [ ! -d "/opt/$APP/server" ] || mv "/opt/$APP/server" "/opt/$APP/server.old"; }
39
+ mv "/opt/$APP/server.new" "/opt/$APP/server"
40
+ rm -rf "/var/www/$APP.old" && mv "/var/www/$APP" "/var/www/$APP.old"
41
+ mv "/opt/$APP/www.new" "/var/www/$APP"
42
+ rm -rf "/var/www/$APP.old" "/opt/$APP/server.old"
43
+
44
+ install -m 644 "$RELEASE/$APP.service" "/etc/systemd/system/$APP.service"
45
+ install -m 644 "$RELEASE/nginx.conf" "/etc/nginx/sites-available/$APP"
46
+ ln -sf "/etc/nginx/sites-available/$APP" "/etc/nginx/sites-enabled/$APP"
47
+ rm -f /etc/nginx/sites-enabled/default
48
+
49
+ systemctl daemon-reload
50
+ systemctl enable "$APP" >/dev/null 2>&1
51
+ systemctl restart "$APP"
52
+ nginx -t
53
+ systemctl reload nginx || systemctl restart nginx
54
+
55
+ sleep 2
56
+ systemctl is-active "$APP"
57
+ curl -sS -o /dev/null -w 'api %{http_code}\n' http://127.0.0.1:{{apiPort}}/api/
58
+ curl -fsS -o /dev/null -w 'host %{http_code}\n' http://127.0.0.1/
@@ -0,0 +1,67 @@
1
+ # {{project}}: the web apps and their API behind one origin.
2
+ #
3
+ # / the host ({{host}})
4
+ # /remotes/<app>/ each remote, loaded by the host over Native Federation
5
+ # /federation.manifest.json which remotes exist; edit it to add or repoint one, no rebuild
6
+ # /api/ the Elysia server
7
+ #
8
+ # Installed as /etc/nginx/sites-available/{{project}} by deploy/install.sh.
9
+
10
+ upstream {{project}}_api {
11
+ server 127.0.0.1:{{apiPort}};
12
+ keepalive 16;
13
+ }
14
+
15
+ server {
16
+ listen 80 default_server;
17
+ listen [::]:80 default_server;
18
+ server_name _;
19
+
20
+ root /var/www/{{project}}/{{host}};
21
+ index index.html;
22
+
23
+ gzip on;
24
+ gzip_types text/css application/javascript application/json image/svg+xml;
25
+
26
+ client_max_body_size 1m;
27
+
28
+ location = /federation.manifest.json {
29
+ alias /etc/{{project}}/federation.manifest.json;
30
+ add_header Cache-Control no-store;
31
+ # Repeated in every location that sets a header: nginx drops the inherited ones there.
32
+ add_header X-Content-Type-Options nosniff always;
33
+ add_header X-Frame-Options SAMEORIGIN always;
34
+ add_header Referrer-Policy same-origin always;
35
+ }
36
+
37
+ # Entry points are re-checked on every load, so a new release shows up at once; the hashed
38
+ # chunks they point to never change and may be kept.
39
+ location /remotes/ {
40
+ root /var/www/{{project}};
41
+ try_files $uri =404;
42
+ add_header Cache-Control no-cache;
43
+ add_header X-Content-Type-Options nosniff always;
44
+ add_header X-Frame-Options SAMEORIGIN always;
45
+ add_header Referrer-Policy same-origin always;
46
+ }
47
+
48
+ location /api/ {
49
+ proxy_pass http://{{project}}_api;
50
+ proxy_http_version 1.1;
51
+ proxy_set_header Connection "";
52
+ proxy_set_header Host $host;
53
+ proxy_set_header X-Real-IP $remote_addr;
54
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
55
+ proxy_set_header X-Forwarded-Proto $scheme;
56
+ add_header X-Content-Type-Options nosniff always;
57
+ }
58
+
59
+ # The host is a single-page app: any other path is its router's business.
60
+ location / {
61
+ try_files $uri $uri/ /index.html;
62
+ add_header Cache-Control no-cache;
63
+ add_header X-Content-Type-Options nosniff always;
64
+ add_header X-Frame-Options SAMEORIGIN always;
65
+ add_header Referrer-Policy same-origin always;
66
+ }
67
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * `bun run deploy root@host` builds a release, copies it to the machine and installs it
3
+ * (deploy/install.sh: nginx, bun and the {{project}} user on the first run; the files and a
4
+ * restart on every run). The target is a Debian or Ubuntu machine you can SSH into as root.
5
+ * Pass `--no-build` to ship the `.release/` that is already there.
6
+ */
7
+ import { RELEASE, buildRelease } from './release.ts'
8
+
9
+ const args = process.argv.slice(2)
10
+ const target = args.find((arg) => !arg.startsWith('--'))
11
+ if (target === undefined) {
12
+ console.error('usage: bun run deploy <user@host> [--no-build]')
13
+ process.exit(1)
14
+ }
15
+
16
+ const run = (command: string[]): void => {
17
+ console.log(`\x1b[36m$\x1b[0m ${command.join(' ')}`)
18
+ const result = Bun.spawnSync(command, { stdio: ['inherit', 'inherit', 'inherit'] })
19
+ if (result.exitCode !== 0) process.exit(result.exitCode)
20
+ }
21
+
22
+ if (!args.includes('--no-build')) buildRelease()
23
+
24
+ const REMOTE_DIR = '/opt/{{project}}-release'
25
+ // tar over ssh: the target needs nothing installed yet, not even rsync. Without macOS's extended
26
+ // attributes, which GNU tar on the other side only warns about.
27
+ run([
28
+ 'sh',
29
+ '-c',
30
+ `COPYFILE_DISABLE=1 tar --no-xattrs -czf - -C ${RELEASE} . | ssh ${target} 'rm -rf ${REMOTE_DIR} && mkdir -p ${REMOTE_DIR} && tar -xzf - -C ${REMOTE_DIR}'`,
31
+ ])
32
+ run(['ssh', target, `sh ${REMOTE_DIR}/install.sh`])
33
+ console.log(`deployed: http://${target.split('@').pop() ?? target}/`)
@@ -0,0 +1,57 @@
1
+ /**
2
+ * `bun run preview` serves `.release/` the way deploy/nginx.conf does, on http://localhost:8080,
3
+ * with the API server started beside it: the production layout without a web server to install.
4
+ * Run `bun run release` first.
5
+ */
6
+ import { existsSync } from 'node:fs'
7
+ import { join } from 'node:path'
8
+
9
+ import { RELEASE } from './release.ts'
10
+
11
+ const PORT = 8080
12
+ const API_PORT = 3019
13
+ const API = `http://127.0.0.1:${String(API_PORT)}`
14
+ const WWW = join(RELEASE, 'www')
15
+
16
+ if (!existsSync(join(WWW, '{{host}}/index.html'))) {
17
+ console.error(`no ${RELEASE}/ yet: run \`bun run release\` first`)
18
+ process.exit(1)
19
+ }
20
+
21
+ const api = Bun.spawn(['bun', join(RELEASE, 'server/index.js')], {
22
+ env: { ...process.env, PORT: String(API_PORT) },
23
+ stdio: ['ignore', 'inherit', 'inherit'],
24
+ })
25
+ process.on('SIGINT', () => {
26
+ api.kill()
27
+ process.exit(0)
28
+ })
29
+
30
+ const file = async (path: string, cache: string): Promise<Response | undefined> => {
31
+ const found = Bun.file(path)
32
+ return (await found.exists())
33
+ ? new Response(found, { headers: { 'cache-control': cache } })
34
+ : undefined
35
+ }
36
+
37
+ const notFound = () => new Response('', { status: 404 })
38
+
39
+ Bun.serve({
40
+ port: PORT,
41
+ async fetch(request) {
42
+ const url = new URL(request.url)
43
+ const path = decodeURIComponent(url.pathname)
44
+ if (path.startsWith('/api/')) return fetch(new Request(`${API}${path}${url.search}`, request))
45
+ if (path.includes('..')) return new Response('bad path', { status: 400 })
46
+ if (path === '/federation.manifest.json') {
47
+ return (await file(join(RELEASE, 'federation.manifest.json'), 'no-store')) ?? notFound()
48
+ }
49
+ if (path.startsWith('/remotes/')) return (await file(join(WWW, path), 'no-cache')) ?? notFound()
50
+ return (
51
+ (path === '/' ? undefined : await file(join(WWW, '{{host}}', path), 'no-cache')) ??
52
+ (await file(join(WWW, '{{host}}/index.html'), 'no-cache')) ??
53
+ notFound()
54
+ )
55
+ },
56
+ })
57
+ console.log(`preview on http://localhost:${String(PORT)} (api on ${API})`)
@@ -0,0 +1,48 @@
1
+ /**
2
+ * `bun run release` builds everything and lays it out the way the web server serves it, in
3
+ * `.release/`:
4
+ *
5
+ * server/index.js the API, one bundled file
6
+ * www/{{host}}/ the host
7
+ * www/remotes/<app>/ each remote in the host's federation manifest
8
+ * federation.manifest.json which remotes the host loads (installed once, then edited there)
9
+ * nginx.conf {{project}}.service env.example install.sh
10
+ *
11
+ * `scripts/deploy.ts` ships that folder; `scripts/preview.ts` serves it locally.
12
+ */
13
+ import { cpSync, mkdirSync, readFileSync, rmSync } from 'node:fs'
14
+ import { join } from 'node:path'
15
+
16
+ export const RELEASE = '.release'
17
+ const HOST = 'apps/{{host}}'
18
+ const MANIFEST = join(HOST, 'public/federation.manifest.json')
19
+
20
+ const run = (command: string[]): void => {
21
+ console.log(`\x1b[36m$\x1b[0m ${command.join(' ')}`)
22
+ const result = Bun.spawnSync(command, { stdio: ['inherit', 'inherit', 'inherit'] })
23
+ if (result.exitCode !== 0) process.exit(result.exitCode)
24
+ }
25
+
26
+ export const buildRelease = (): void => {
27
+ run(['bun', 'run', 'build'])
28
+
29
+ rmSync(RELEASE, { recursive: true, force: true })
30
+ mkdirSync(join(RELEASE, 'www/remotes'), { recursive: true })
31
+ mkdirSync(join(RELEASE, 'server'), { recursive: true })
32
+
33
+ cpSync('apps/server/dist/index.js', join(RELEASE, 'server/index.js'))
34
+ cpSync(join(HOST, 'dist/{{host}}/browser'), join(RELEASE, 'www/{{host}}'), { recursive: true })
35
+ const remotes = Object.keys(JSON.parse(readFileSync(MANIFEST, 'utf8')) as Record<string, unknown>)
36
+ for (const app of remotes) {
37
+ cpSync(`apps/${app}/dist/${app}/browser`, join(RELEASE, 'www/remotes', app), {
38
+ recursive: true,
39
+ })
40
+ }
41
+ cpSync(MANIFEST, join(RELEASE, 'federation.manifest.json'))
42
+ for (const file of ['nginx.conf', '{{project}}.service', 'env.example', 'install.sh']) {
43
+ cpSync(join('deploy', file), join(RELEASE, file))
44
+ }
45
+ console.log(`release ready in ${RELEASE}/`)
46
+ }
47
+
48
+ if (import.meta.main) buildRelease()
@@ -0,0 +1,3 @@
1
+ # Search tool
2
+
3
+ Use the `zvec_grep` MCP tool for code search in this repo instead of Grep/Glob/`grep`/`rg`.
@@ -0,0 +1,38 @@
1
+ # {{name}}
2
+
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
5
+ libraries under `packages/*`.
6
+
7
+ ## Quickstart
8
+
9
+ ```sh
10
+ bun install
11
+ bun run dev # runs every apps/*/package.json "dev" script in parallel
12
+ bun run check # lint + format:check + knip + typecheck (also the pre-push hook)
13
+ ```
14
+
15
+ ## Layout
16
+
17
+ ```
18
+ apps/<name> runnable applications (each with its own package.json)
19
+ packages/<name> shared libraries consumed by apps via workspace:*
20
+ scripts/dev.ts parallel dev runner with prefixed output (apps/* only)
21
+ scripts/each.ts `bun run scripts/each.ts <script>` in every workspace that has it
22
+ ```
23
+
24
+ Add a workspace by creating `apps/<name>/package.json` (or `packages/<name>`)
25
+ with `dev`, `build` and `typecheck` scripts, then extend `knip.ts` with a
26
+ matching workspace entry so dead-code checks cover it.
27
+
28
+ ## Toolchain
29
+
30
+ - **ESLint 10 + typescript-eslint** (`eslint.config.ts`), **Prettier** (no semi,
31
+ single quotes, width 100), **knip** — all run by `bun run check`. Their config comes from
32
+ `@20baht/strict`: bump it to take rule updates (Renovate does this); put app overrides
33
+ last, each with a reason.
34
+ - **husky** hooks: `pre-commit` → lint-staged, `commit-msg` → commitlint
35
+ (Conventional Commits), `pre-push` → `bun run check`.
36
+ - `tsconfig.base.json` — extends `@20baht/strict/tsconfig/base.json` (strict,
37
+ `verbatimModuleSyntax`, `noUncheckedIndexedAccess`, `exactOptionalPropertyTypes`, ...).
38
+ Extend it from each workspace's `tsconfig.json`.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Architecture boundaries, checked with `bun run deps`. `generic` gives no-circular and
3
+ * production-not-tests for apps/* and packages/*; add layer rules (features may not import
4
+ * each other, shared/ knows no feature, ...) as your structure grows. Every rule is `error`:
5
+ * a violation is a decision, not a warning.
6
+ */
7
+ import { makeConfig } from '@20baht/strict/depcruise'
8
+
9
+ export default makeConfig({ generic: true })
@@ -0,0 +1,15 @@
1
+ name: Setup
2
+ description: Bun at the version pinned in package.json, with the install cache restored, and dependencies installed.
3
+ runs:
4
+ using: composite
5
+ steps:
6
+ - uses: oven-sh/setup-bun@v2
7
+ with:
8
+ bun-version-file: package.json
9
+ - uses: actions/cache@v4
10
+ with:
11
+ path: ~/.bun/install/cache
12
+ key: bun-${{ runner.os }}-${{ hashFiles('bun.lock') }}
13
+ restore-keys: bun-${{ runner.os }}-
14
+ - run: bun install --frozen-lockfile
15
+ shell: bash