@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.
- package/README.md +93 -41
- package/dist/application/create.js +8 -4
- package/dist/application/generate.js +27 -21
- package/dist/application/update.js +104 -0
- package/dist/args.js +3 -0
- package/dist/cli.js +56 -22
- package/dist/domain/create-plan.js +4 -3
- package/dist/domain/form-dsl.js +6 -22
- package/dist/domain/generate-plan.js +3 -3
- package/dist/domain/update-plan.js +93 -0
- package/dist/infrastructure/fs-reader.js +34 -2
- package/dist/infrastructure/npm-registry.js +28 -0
- package/package.json +10 -7
- package/templates/angular/package.json.hbs +1 -1
- package/templates/create/apps/web/package.json.hbs +1 -1
- package/templates/{angular → federation}/README.md.hbs +2 -2
- package/templates/{angular → federation}/_dependency-cruiser.mjs +1 -1
- package/templates/{angular → federation}/apps/shell/package.json +3 -3
- package/templates/{angular → federation}/apps/shell/src/app/modules/home/home.component.ts.hbs +1 -1
- package/templates/{angular → federation}/apps/shell/src/environments/environment.development.ts +1 -1
- package/templates/{angular → federation}/eslint.config.ts.hbs +1 -1
- package/templates/new/README.md.hbs +1 -1
- package/templates/new/package.json.hbs +1 -1
- package/templates/remote/package.json.hbs +3 -3
- package/templates/standalone/README.md.hbs +36 -0
- package/templates/standalone/_dependency-cruiser.mjs +29 -0
- package/templates/standalone/apps/web/_editorconfig +17 -0
- package/templates/standalone/apps/web/angular.json +72 -0
- package/templates/standalone/apps/web/package.json +39 -0
- package/templates/standalone/apps/web/src/app/app.config.ts +14 -0
- package/templates/standalone/apps/web/src/app/app.css +4 -0
- package/templates/standalone/apps/web/src/app/app.html.hbs +16 -0
- package/templates/standalone/apps/web/src/app/app.routes.ts.hbs +17 -0
- package/templates/standalone/apps/web/src/app/app.ts +43 -0
- package/templates/standalone/apps/web/src/app/core/navigation/navigation.spec.ts +26 -0
- package/templates/standalone/apps/web/src/app/core/navigation/navigation.ts +11 -0
- package/templates/standalone/apps/web/src/app/modules/home/home.component.ts.hbs +37 -0
- package/templates/standalone/apps/web/src/app/modules/not-found/not-found.component.ts +36 -0
- package/templates/standalone/apps/web/src/app/services/hello.service.ts.hbs +14 -0
- package/templates/standalone/apps/web/src/index.html.hbs +12 -0
- package/templates/standalone/apps/web/src/main.ts +10 -0
- package/templates/standalone/apps/web/src/styles.css +19 -0
- package/templates/standalone/apps/web/tsconfig.app.json +10 -0
- package/templates/standalone/apps/web/tsconfig.json.hbs +39 -0
- package/templates/standalone/apps/web/tsconfig.spec.json +9 -0
- package/templates/standalone/bahtui.json +6 -0
- package/templates/standalone/eslint.config.ts.hbs +24 -0
- package/templates/standalone/knip.ts +23 -0
- /package/templates/{angular → federation}/apps/shell/_editorconfig +0 -0
- /package/templates/{angular → federation}/apps/shell/angular.json +0 -0
- /package/templates/{angular → federation}/apps/shell/federation.config.mjs +0 -0
- /package/templates/{angular → federation}/apps/shell/public/federation.manifest.json +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/app.config.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/app.css +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/app.html.hbs +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/app.routes.ts.hbs +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/app.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/core/federation/load-remote.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/core/federation/manifest.spec.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/core/federation/manifest.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/core/federation/remote-loader.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/core/federation/timeout.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/app/modules/unavailable/unavailable.component.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/bootstrap.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/environments/environment.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/index.html.hbs +0 -0
- /package/templates/{angular → federation}/apps/shell/src/main.ts +0 -0
- /package/templates/{angular → federation}/apps/shell/src/styles.css +0 -0
- /package/templates/{angular → federation}/apps/shell/tsconfig.app.json +0 -0
- /package/templates/{angular → federation}/apps/shell/tsconfig.federation.json +0 -0
- /package/templates/{angular → federation}/apps/shell/tsconfig.json.hbs +0 -0
- /package/templates/{angular → federation}/apps/shell/tsconfig.spec.json +0 -0
- /package/templates/{angular → federation}/bahtui.json +0 -0
- /package/templates/{angular → federation}/knip.ts +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Routes } from '@angular/router'
|
|
2
|
+
|
|
3
|
+
/** One lazy page per route. A new page also gets a line in `core/navigation/navigation.ts`. */
|
|
4
|
+
export const routes: Routes = [
|
|
5
|
+
{
|
|
6
|
+
path: '',
|
|
7
|
+
pathMatch: 'full',
|
|
8
|
+
title: '{{name}}',
|
|
9
|
+
loadComponent: () => import('./modules/home/home.component').then((m) => m.HomeComponent),
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
path: '**',
|
|
13
|
+
title: 'Not found · {{name}}',
|
|
14
|
+
loadComponent: () =>
|
|
15
|
+
import('./modules/not-found/not-found.component').then((m) => m.NotFoundComponent),
|
|
16
|
+
},
|
|
17
|
+
]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ChangeDetectionStrategy, Component, computed, inject } from '@angular/core'
|
|
2
|
+
import { toSignal } from '@angular/core/rxjs-interop'
|
|
3
|
+
import { NavigationEnd, Router, RouterOutlet } from '@angular/router'
|
|
4
|
+
import { BAHT_UI } from '@20baht/angular'
|
|
5
|
+
import { filter, map } from 'rxjs'
|
|
6
|
+
import { NAV, currentKey } from './core/navigation/navigation'
|
|
7
|
+
|
|
8
|
+
/** The frame every page sits in: brand, the navigator, the page. */
|
|
9
|
+
@Component({
|
|
10
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
11
|
+
imports: [RouterOutlet, BAHT_UI],
|
|
12
|
+
selector: 'app-root',
|
|
13
|
+
templateUrl: './app.html',
|
|
14
|
+
styleUrl: './app.css',
|
|
15
|
+
})
|
|
16
|
+
export class App {
|
|
17
|
+
private readonly router = inject(Router)
|
|
18
|
+
|
|
19
|
+
private readonly url = toSignal(
|
|
20
|
+
this.router.events.pipe(
|
|
21
|
+
filter((event) => event instanceof NavigationEnd),
|
|
22
|
+
map((event) => event.urlAfterRedirects),
|
|
23
|
+
),
|
|
24
|
+
{ initialValue: this.router.url },
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
protected readonly items = NAV
|
|
28
|
+
|
|
29
|
+
protected readonly current = computed(() =>
|
|
30
|
+
currentKey(
|
|
31
|
+
this.url(),
|
|
32
|
+
NAV.map((item) => item.key),
|
|
33
|
+
),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
/** Route in place instead of letting the link reload the page. */
|
|
37
|
+
protected navigate(event: Event): void {
|
|
38
|
+
const { href } = (event as CustomEvent<{ href: string | undefined }>).detail
|
|
39
|
+
if (href === undefined) return
|
|
40
|
+
event.preventDefault()
|
|
41
|
+
void this.router.navigateByUrl(href)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { NAV, currentKey } from './navigation'
|
|
2
|
+
|
|
3
|
+
describe('currentKey', () => {
|
|
4
|
+
const keys = ['', 'orders', 'orders/archive', 'order']
|
|
5
|
+
|
|
6
|
+
it('is the entry the URL sits under', () => {
|
|
7
|
+
expect(currentKey('/orders', keys)).toBe('orders')
|
|
8
|
+
expect(currentKey('/orders/42?tab=lines#top', keys)).toBe('orders')
|
|
9
|
+
expect(currentKey('/order/1', keys)).toBe('order')
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('prefers the longest entry', () => {
|
|
13
|
+
expect(currentKey('/orders/archive/2024', keys)).toBe('orders/archive')
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('is Home for the root and for a URL no entry owns', () => {
|
|
17
|
+
expect(currentKey('/', keys)).toBe('')
|
|
18
|
+
expect(currentKey('/ordersx', keys)).toBe('')
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
describe('NAV', () => {
|
|
23
|
+
it('starts with Home at the root', () => {
|
|
24
|
+
expect(NAV[0]).toEqual({ key: '', label: 'Home', href: '/' })
|
|
25
|
+
})
|
|
26
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ShellNavItem } from '@20baht/ui'
|
|
2
|
+
|
|
3
|
+
/** The navigator: one entry per page. `key` is the page's path, without the leading slash. */
|
|
4
|
+
export const NAV: ShellNavItem[] = [{ key: '', label: 'Home', href: '/' }]
|
|
5
|
+
|
|
6
|
+
/** The key of the entry `url` sits under, the longest one first; `''` (Home) when none does. */
|
|
7
|
+
export const currentKey = (url: string, keys: string[]): string => {
|
|
8
|
+
const path = (url.split(/[?#]/)[0] ?? '').replace(/^\//, '')
|
|
9
|
+
const under = keys.filter((key) => key !== '' && (path === key || path.startsWith(`${key}/`)))
|
|
10
|
+
return under.sort((a, b) => b.length - a.length)[0] ?? ''
|
|
11
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ChangeDetectionStrategy, Component, inject } from '@angular/core'
|
|
2
|
+
import { describeError } from '@{{name}}/kit'
|
|
3
|
+
import { BAHT_UI } from '@20baht/angular'
|
|
4
|
+
import { HelloService } from '../../services/hello.service'
|
|
5
|
+
|
|
6
|
+
/** The landing page: what the server says at `GET /api/hello`. */
|
|
7
|
+
@Component({
|
|
8
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
9
|
+
imports: [BAHT_UI],
|
|
10
|
+
selector: 'web-home',
|
|
11
|
+
template: `
|
|
12
|
+
<div class="app-page">
|
|
13
|
+
<baht-page-header
|
|
14
|
+
heading="{{name}}"
|
|
15
|
+
description="An Angular app on @20baht/ui, talking to an Elysia server through a typed client."
|
|
16
|
+
></baht-page-header>
|
|
17
|
+
<baht-card heading="From the server">
|
|
18
|
+
@if (hello.error(); as error) {
|
|
19
|
+
<baht-error-state
|
|
20
|
+
heading="The server did not answer"
|
|
21
|
+
[message]="describeError(error)"
|
|
22
|
+
retry-label="Try again"
|
|
23
|
+
(bahtRetry)="hello.reload()"
|
|
24
|
+
></baht-error-state>
|
|
25
|
+
} @else if (hello.value(); as body) {
|
|
26
|
+
<p [textContent]="body.message"></p>
|
|
27
|
+
} @else {
|
|
28
|
+
<baht-skeleton variant="text"></baht-skeleton>
|
|
29
|
+
}
|
|
30
|
+
</baht-card>
|
|
31
|
+
</div>
|
|
32
|
+
`,
|
|
33
|
+
})
|
|
34
|
+
export class HomeComponent {
|
|
35
|
+
protected readonly hello = inject(HelloService).hello()
|
|
36
|
+
protected readonly describeError = describeError
|
|
37
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ChangeDetectionStrategy, Component, inject } from '@angular/core'
|
|
2
|
+
import { Router } from '@angular/router'
|
|
3
|
+
import { BAHT_UI } from '@20baht/angular'
|
|
4
|
+
|
|
5
|
+
/** Shown for a URL no route owns. */
|
|
6
|
+
@Component({
|
|
7
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
8
|
+
imports: [BAHT_UI],
|
|
9
|
+
selector: 'web-not-found',
|
|
10
|
+
styles: `
|
|
11
|
+
:host {
|
|
12
|
+
display: grid;
|
|
13
|
+
place-content: center;
|
|
14
|
+
min-height: 60dvh;
|
|
15
|
+
padding: var(--baht-space-4);
|
|
16
|
+
}
|
|
17
|
+
baht-error-state {
|
|
18
|
+
max-width: 440px;
|
|
19
|
+
}
|
|
20
|
+
`,
|
|
21
|
+
template: `
|
|
22
|
+
<baht-error-state
|
|
23
|
+
heading="Page not found"
|
|
24
|
+
message="Nothing lives at this address."
|
|
25
|
+
retry-label="Go home"
|
|
26
|
+
(bahtRetry)="home()"
|
|
27
|
+
></baht-error-state>
|
|
28
|
+
`,
|
|
29
|
+
})
|
|
30
|
+
export class NotFoundComponent {
|
|
31
|
+
private readonly router = inject(Router)
|
|
32
|
+
|
|
33
|
+
protected home(): void {
|
|
34
|
+
void this.router.navigateByUrl('/')
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Injectable, inject } from '@angular/core'
|
|
2
|
+
import { Api } from '@{{name}}/kit'
|
|
3
|
+
import { edenResource } from '@20baht/ngx-eden'
|
|
4
|
+
|
|
5
|
+
/** Everything the home page asks the server. */
|
|
6
|
+
@Injectable({ providedIn: 'root' })
|
|
7
|
+
export class HelloService {
|
|
8
|
+
private readonly api = inject(Api).client.api
|
|
9
|
+
|
|
10
|
+
/** `GET /api/hello` as a resource; create it in an injection context (a field initializer). */
|
|
11
|
+
hello() {
|
|
12
|
+
return edenResource(() => this.api.hello.get.$request())
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { bootstrapApplication } from '@angular/platform-browser'
|
|
2
|
+
import { App } from './app/app'
|
|
3
|
+
import { appConfig } from './app/app.config'
|
|
4
|
+
|
|
5
|
+
// Registers the <baht-*> custom elements in their own chunk; they upgrade in place once it lands.
|
|
6
|
+
void import('@20baht/ui')
|
|
7
|
+
|
|
8
|
+
bootstrapApplication(App, appConfig).catch((err: unknown) => {
|
|
9
|
+
console.error(err)
|
|
10
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* @20baht/ui's tokens.css comes first (angular.json); this file only sets the page up. */
|
|
2
|
+
html,
|
|
3
|
+
body {
|
|
4
|
+
margin: 0;
|
|
5
|
+
min-height: 100dvh;
|
|
6
|
+
background: var(--baht-color-bg);
|
|
7
|
+
color: var(--baht-color-text);
|
|
8
|
+
font-family: var(--baht-font-family);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* The width every routed page keeps to inside the shell. */
|
|
12
|
+
.app-page {
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
gap: var(--baht-space-5);
|
|
16
|
+
box-sizing: border-box;
|
|
17
|
+
max-width: 1200px;
|
|
18
|
+
padding: var(--baht-space-5);
|
|
19
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
+
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
+
{
|
|
4
|
+
"extends": "./tsconfig.json",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"types": []
|
|
7
|
+
},
|
|
8
|
+
"include": ["src/**/*.ts"],
|
|
9
|
+
"exclude": ["src/**/*.spec.ts"]
|
|
10
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
+
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
+
{
|
|
4
|
+
"compileOnSave": false,
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"strict": true,
|
|
7
|
+
"noUncheckedIndexedAccess": true,
|
|
8
|
+
"exactOptionalPropertyTypes": true,
|
|
9
|
+
"verbatimModuleSyntax": true,
|
|
10
|
+
"noImplicitOverride": true,
|
|
11
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
12
|
+
"noImplicitReturns": true,
|
|
13
|
+
"noFallthroughCasesInSwitch": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"experimentalDecorators": true,
|
|
17
|
+
"importHelpers": true,
|
|
18
|
+
"target": "ES2022",
|
|
19
|
+
"module": "preserve",
|
|
20
|
+
"paths": {
|
|
21
|
+
"@{{name}}/kit": ["../../packages/kit/src/index.ts"]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"angularCompilerOptions": {
|
|
25
|
+
"enableI18nLegacyMessageIdFormat": false,
|
|
26
|
+
"strictInjectionParameters": true,
|
|
27
|
+
"strictTemplates": true,
|
|
28
|
+
"strictInputAccessModifiers": true
|
|
29
|
+
},
|
|
30
|
+
"files": [],
|
|
31
|
+
"references": [
|
|
32
|
+
{
|
|
33
|
+
"path": "./tsconfig.app.json"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "./tsconfig.spec.json"
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* To learn more about Typescript configuration file: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html. */
|
|
2
|
+
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
|
|
3
|
+
{
|
|
4
|
+
"extends": "./tsconfig.json",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"types": ["vitest/globals"]
|
|
7
|
+
},
|
|
8
|
+
"include": ["src/**/*.d.ts", "src/**/*.spec.ts"]
|
|
9
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineConfig } from 'eslint/config'
|
|
2
|
+
|
|
3
|
+
import { angular, bahtui, base } from '@20baht/strict/eslint'
|
|
4
|
+
|
|
5
|
+
/** The web app and the kit it compiles in. */
|
|
6
|
+
const WEB = ['apps/web/src/**', 'packages/kit/src/**']
|
|
7
|
+
|
|
8
|
+
// Every rule is an error. Add app overrides below, each with a reason:
|
|
9
|
+
// // eslint-disable-next-line <rule> -- <why>
|
|
10
|
+
export default defineConfig([
|
|
11
|
+
...base,
|
|
12
|
+
...angular({
|
|
13
|
+
files: WEB,
|
|
14
|
+
restrictedImports: [
|
|
15
|
+
{
|
|
16
|
+
name: 'server',
|
|
17
|
+
allowTypeImports: true,
|
|
18
|
+
message:
|
|
19
|
+
'The web app shares the server only as types (the eden App type); no server runtime code in a bundle.',
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
}),
|
|
23
|
+
...bahtui({ files: WEB, tokenFiles: ['apps/web/src/styles.css'] }),
|
|
24
|
+
])
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { knip } from '@20baht/strict/knip'
|
|
2
|
+
|
|
3
|
+
const SRC = ['src/**/*.ts']
|
|
4
|
+
|
|
5
|
+
/** A workspace tested with `bun test`: the tests are its entries. */
|
|
6
|
+
const tested = { entry: ['test/**/*.test.ts'], project: [...SRC, 'test/**/*.ts'] }
|
|
7
|
+
|
|
8
|
+
export default knip({
|
|
9
|
+
ignoreDependencies: [
|
|
10
|
+
// Angular's compiler emits tslib helpers (importHelpers).
|
|
11
|
+
'tslib',
|
|
12
|
+
// Optional peers of @20baht/ui, which imports them on demand (date and markdown fields).
|
|
13
|
+
'dompurify',
|
|
14
|
+
'flatpickr',
|
|
15
|
+
'marked',
|
|
16
|
+
],
|
|
17
|
+
workspaces: {
|
|
18
|
+
'.': { entry: ['scripts/*.ts'], project: ['scripts/**/*.ts'] },
|
|
19
|
+
'apps/server': tested,
|
|
20
|
+
'apps/web': { project: SRC },
|
|
21
|
+
'packages/kit': tested,
|
|
22
|
+
},
|
|
23
|
+
})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/templates/{angular → federation}/apps/shell/src/app/core/federation/manifest.spec.ts
RENAMED
|
File without changes
|
|
File without changes
|
/package/templates/{angular → federation}/apps/shell/src/app/core/federation/remote-loader.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|