@xrystal/core 3.39.0 → 3.40.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 +65 -34
- package/package.json +2 -4
- package/x/bin/commands/create.mjs +2 -1
- package/x/bin/commands/doctor.mjs +5 -4
- package/x/bin/commands/hooks.mjs +2 -1
- package/x/bin/commands/project.mjs +2 -1
- package/x/bin/commands/release.mjs +3 -2
- package/x/bin/commands/sync.mjs +51 -0
- package/x/bin/commands/tmp.mjs +2 -1
- package/x/bin/helpers/.generated/tmp-schema.mjs +54 -85
- package/x/bin/helpers/banner.mjs +2 -2
- package/x/bin/helpers/build-config.mjs +11 -2
- package/x/bin/helpers/cli-help.mjs +9 -9
- package/x/bin/helpers/cli-identity.mjs +7 -17
- package/x/bin/helpers/defaults.json +14 -30
- package/x/bin/helpers/package-defaults.mjs +46 -12
- package/x/bin/helpers/project-artifacts.mjs +7 -0
- package/x/bin/helpers/seed-from-tmp.mjs +52 -0
- package/x/bin/helpers/toolchain-config.mjs +6 -12
- package/x/bin/main-cli.js +2 -2
- package/x/bin/scripts/install-git-hooks.mjs +3 -2
- package/x/bin/scripts/sync-cli-defaults.mjs +7 -2
- package/x/dist/utils/constants/defaults.json +14 -30
- package/x/dist/utils/constants/index.d.ts +20 -12
- package/x/dist/utils/constants/index.js +1 -1
- package/x/dist/utils/helpers/tmp/index.d.ts +2 -0
- package/x/dist/utils/helpers/tmp/index.js +1 -1
- package/x/dist/utils/helpers/tmp/path-normalize.d.ts +10 -0
- package/x/dist/utils/helpers/tmp/path-normalize.js +1 -0
- package/x/dist/utils/helpers/tmp/seed-from-tmp.d.ts +9 -0
- package/x/dist/utils/helpers/tmp/seed-from-tmp.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -1
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -1
- package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -1
- package/x/bin/commands/sync-toolchain.mjs +0 -43
package/README.md
CHANGED
|
@@ -3,20 +3,39 @@
|
|
|
3
3
|
> **EN** — Microservice runtime: Express or Elysia HTTP, DI loaders, live `tmp.yml`, standardized API responses.
|
|
4
4
|
> **TR** — Microservice runtime: Express veya Elysia HTTP, DI loader'lar, canlı `tmp.yml`, standart API cevapları.
|
|
5
5
|
|
|
6
|
-
**CLI:** `
|
|
6
|
+
**CLI:** `xry` · **Version:** `3.40.0` · [npm](https://www.npmjs.com/package/@xrystal/core)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## What's new in 3.40.0 / 3.40.0'da ne değişti
|
|
11
|
+
|
|
12
|
+
| Change / Değişiklik | EN | TR |
|
|
13
|
+
|---------------------|----|----|
|
|
14
|
+
| **Single CLI** | Bin is only `xry` (`xcore` / `xrystal` / `tmp` removed) | Tek bin: `xry` (eski isimler kalktı) |
|
|
15
|
+
| **`xry sync`** | Writes `tsconfig` `include` / `outDir` / `@/*` from project `tmp.yml` | `tmp.yml` → tsconfig path sync |
|
|
16
|
+
| **Config SSOT** | Layout seed from bundled `x/tmp.yml` — not `defaults.json` | Layout seed = `x/tmp.yml`, `defaults.json` değil |
|
|
17
|
+
| **`defaults.json`** | Package identity + CLI + build flags only | Sadece kimlik, CLI, build flag'leri |
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx xry sync # apply tmp.yml → tsconfig / bunfig aliases
|
|
21
|
+
npx xry sync --dry-run
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**Breaking / Kırıcı:** replace scripts and docs that called `xcore`, `xrystal`, or the old `tmp` bin with `xry`.
|
|
7
25
|
|
|
8
26
|
---
|
|
9
27
|
|
|
10
28
|
## Why / Neden
|
|
11
29
|
|
|
12
|
-
**EN:** `@xrystal/core` is a **kernel**, not only a GitHub template. Most teams already have their own repo layout, CI, Docker, or monorepo — they only need the runtime: DI, `tmp.yml`, `ctr()`, DTO, logger, i18n, trace. Use `
|
|
30
|
+
**EN:** `@xrystal/core` is a **kernel**, not only a GitHub template. Most teams already have their own repo layout, CI, Docker, or monorepo — they only need the runtime: DI, `tmp.yml`, `ctr()`, DTO, logger, i18n, trace. Use `xry create` if you want a starter; otherwise add the package to **your** project and seed `x/tmp.yml`.
|
|
13
31
|
|
|
14
|
-
**TR:** `@xrystal/core` bir **kernel** — sadece GitHub template değil. Çoğu ekipte zaten kendi repo düzeni, CI, Docker veya monorepo vardır; ihtiyaç duyulan şey runtime: DI, `tmp.yml`, `ctr()`, DTO, logger, i18n, trace. Sıfırdan başlıyorsan `
|
|
32
|
+
**TR:** `@xrystal/core` bir **kernel** — sadece GitHub template değil. Çoğu ekipte zaten kendi repo düzeni, CI, Docker veya monorepo vardır; ihtiyaç duyulan şey runtime: DI, `tmp.yml`, `ctr()`, DTO, logger, i18n, trace. Sıfırdan başlıyorsan `xry create`; mevcut projende sadece paketi kur + `xry tmp` yeter.
|
|
15
33
|
|
|
16
34
|
```bash
|
|
17
35
|
# EN: existing project — kernel only · TR: mevcut proje — sadece kernel
|
|
18
36
|
bun add @xrystal/core
|
|
19
|
-
npx
|
|
37
|
+
npx xry tmp # seed x/tmp.yml into YOUR layout
|
|
38
|
+
npx xry sync # align tsconfig paths with tmp.yml
|
|
20
39
|
# wire coreLoader + dtoMiddleware in your entry file
|
|
21
40
|
```
|
|
22
41
|
|
|
@@ -34,13 +53,13 @@ npx xcore tmp # seed x/tmp.yml into YOUR layout
|
|
|
34
53
|
mkdir my-api && cd my-api
|
|
35
54
|
bun init -y
|
|
36
55
|
bun add @xrystal/core
|
|
37
|
-
npx
|
|
56
|
+
npx xry create my-api .
|
|
38
57
|
```
|
|
39
58
|
|
|
40
59
|
```bash
|
|
41
60
|
bun add elysia # EN: or express · TR: veya express
|
|
42
61
|
bun run dev
|
|
43
|
-
npx
|
|
62
|
+
npx xry doctor # EN: setup check · TR: kurulum kontrolü
|
|
44
63
|
```
|
|
45
64
|
|
|
46
65
|
### Path B — Your project + kernel (most common / en yaygın)
|
|
@@ -53,7 +72,8 @@ npx xcore doctor # EN: setup check · TR: kurulum kontrolü
|
|
|
53
72
|
mkdir my-api && cd my-api
|
|
54
73
|
bun init -y
|
|
55
74
|
bun add @xrystal/core elysia
|
|
56
|
-
npx
|
|
75
|
+
npx xry tmp # EN: create x/tmp.yml from seed if missing · TR: yoksa seed'den oluşturur
|
|
76
|
+
npx xry sync # EN: tsconfig from tmp.yml · TR: tmp.yml → tsconfig
|
|
57
77
|
```
|
|
58
78
|
|
|
59
79
|
`package.json`:
|
|
@@ -61,22 +81,23 @@ npx xcore tmp # EN: create x/tmp.yml from seed if missing · TR: yoksa
|
|
|
61
81
|
```json
|
|
62
82
|
{
|
|
63
83
|
"dependencies": {
|
|
64
|
-
"@xrystal/core": "^3.
|
|
84
|
+
"@xrystal/core": "^3.40.0",
|
|
65
85
|
"elysia": "^1.4.19"
|
|
66
86
|
},
|
|
67
87
|
"scripts": {
|
|
68
|
-
"dev": "
|
|
69
|
-
"build": "
|
|
70
|
-
"start": "
|
|
71
|
-
"test": "
|
|
72
|
-
"
|
|
88
|
+
"dev": "xry dev",
|
|
89
|
+
"build": "xry build",
|
|
90
|
+
"start": "xry start",
|
|
91
|
+
"test": "xry test",
|
|
92
|
+
"sync": "xry sync",
|
|
93
|
+
"doctor": "xry doctor"
|
|
73
94
|
}
|
|
74
95
|
}
|
|
75
96
|
```
|
|
76
97
|
|
|
77
|
-
**EN:** No global `
|
|
98
|
+
**EN:** No global `xry` install — runs via `node_modules/.bin` after `bun add @xrystal/core`.
|
|
78
99
|
|
|
79
|
-
**TR:** Global `
|
|
100
|
+
**TR:** Global `xry` gerekmez — `@xrystal/core` kurulunca `node_modules/.bin` üzerinden çalışır.
|
|
80
101
|
|
|
81
102
|
### Project layout / Proje düzeni
|
|
82
103
|
|
|
@@ -84,12 +105,20 @@ npx xcore tmp # EN: create x/tmp.yml from seed if missing · TR: yoksa
|
|
|
84
105
|
my-api/
|
|
85
106
|
├── package.json
|
|
86
107
|
├── source/
|
|
87
|
-
│ ├── index.ts # EN: dev entry (
|
|
108
|
+
│ ├── index.ts # EN: dev entry (xry dev) · TR: dev girişi
|
|
88
109
|
│ └── controllers/
|
|
89
110
|
└── x/
|
|
90
|
-
|
|
111
|
+
└── tmp.yml # EN: runtime + path SSOT · TR: runtime + path tek kaynak
|
|
91
112
|
```
|
|
92
113
|
|
|
114
|
+
### Config sources / Config kaynakları
|
|
115
|
+
|
|
116
|
+
| File / Dosya | Owns / Sahip olduğu |
|
|
117
|
+
|--------------|---------------------|
|
|
118
|
+
| `x/tmp.yml` | Service paths, loaders, protocols, build flags · layout seed |
|
|
119
|
+
| `tsconfig.json` | Compiler language options; path layout via `xry sync` |
|
|
120
|
+
| Package defaults (internal) | CLI name (`xry`), package identity — not project layout |
|
|
121
|
+
|
|
93
122
|
### Minimal `x/tmp.yml`
|
|
94
123
|
|
|
95
124
|
```yaml
|
|
@@ -143,13 +172,14 @@ bun run dev
|
|
|
143
172
|
|
|
144
173
|
| Command / Komut | EN | TR |
|
|
145
174
|
|-----------------|----|----|
|
|
146
|
-
| `
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
149
|
-
| `
|
|
150
|
-
| `
|
|
151
|
-
| `
|
|
152
|
-
| `
|
|
175
|
+
| `xry create [name] [path]` | Start project from template + `tmp.yml` | Template + `tmp.yml` ile proje başlat |
|
|
176
|
+
| `xry tmp` | Create `tmp.yml` from seed if missing | `tmp.yml` yoksa seed'den oluştur |
|
|
177
|
+
| `xry sync` | Sync `tsconfig` / aliases from `tmp.yml` | `tmp.yml` → `tsconfig` / alias |
|
|
178
|
+
| `xry dev` | Watch `source/index.ts` + dev env | `source/index.ts` watch + dev env |
|
|
179
|
+
| `xry build` | Output → `x/dist` | Çıktı → `x/dist` |
|
|
180
|
+
| `xry start` | Run `x/dist` + prod env | `x/dist` + prod env |
|
|
181
|
+
| `xry test` | Run `x/tests` | `x/tests` çalıştır |
|
|
182
|
+
| `xry doctor` | CLI, runtime, package health | CLI, runtime, paket uyumu |
|
|
153
183
|
|
|
154
184
|
---
|
|
155
185
|
|
|
@@ -173,7 +203,7 @@ bun run dev
|
|
|
173
203
|
| **HTTP client** | Retries + circuit breaker + trace header | Dayanıklı outbound HTTP | extend `BaseApiClient` from loader/clients |
|
|
174
204
|
| **Scope validate** | OAuth-style `resource:permission` check | Scope doğrulama | `validateScopes({ scopes, resources, permissions })` |
|
|
175
205
|
| **Realtime** | Same `ctr()` for ws / socket.io | HTTP + ws aynı kalıp | `ctr({ logic }, { protocol: 'ws' })` — [guide](#realtime--websocket--socketio) |
|
|
176
|
-
| **CLI** | dev, build, start, test, doctor
|
|
206
|
+
| **CLI (`xry`)** | create, tmp, sync, dev, build, start, test, doctor | Servis toolchain | `"dev": "xry dev"` · `"sync": "xry sync"` |
|
|
177
207
|
| **Shutdown** | Graceful cleanup on SIGTERM | Temiz kapanış | auto via `registerGracefulShutdown()` on boot |
|
|
178
208
|
|
|
179
209
|
```typescript
|
|
@@ -511,13 +541,14 @@ Details / detay: [`@xrystal/dto`](https://www.npmjs.com/package/@xrystal/dto)
|
|
|
511
541
|
**TR:** Servis yazarken tipik akış.
|
|
512
542
|
|
|
513
543
|
```
|
|
514
|
-
1. Your repo + bun add @xrystal/core +
|
|
515
|
-
2.
|
|
516
|
-
3.
|
|
517
|
-
4.
|
|
518
|
-
5.
|
|
519
|
-
6.
|
|
520
|
-
7.
|
|
544
|
+
1. Your repo + bun add @xrystal/core + xry tmp (or xry create for greenfield)
|
|
545
|
+
2. xry sync → tsconfig include / outDir / @/* from tmp.yml
|
|
546
|
+
3. tmp.yml → framework, loaders, paths
|
|
547
|
+
4. coreLoader() → once at top of YOUR index.ts
|
|
548
|
+
5. Controller → ctr() per endpoint
|
|
549
|
+
6. Framework → dtoMiddleware + routes
|
|
550
|
+
7. xry dev → develop
|
|
551
|
+
8. xry build → start → production
|
|
521
552
|
```
|
|
522
553
|
|
|
523
554
|
### Express — end-to-end / uçtan uca
|
|
@@ -757,6 +788,6 @@ class ChatController extends Controller {
|
|
|
757
788
|
|
|
758
789
|
## Maintainer note / Geliştirici notu
|
|
759
790
|
|
|
760
|
-
**EN:** This repo is the `@xrystal/core` source.
|
|
791
|
+
**EN:** This repo is the `@xrystal/core` source. Bump `package.json` → commit → `xry tag` (runs prepare + pushes `vX.Y.Z`; GitHub Publish workflow releases to npm). Consumers only need `bun add @xrystal/core`.
|
|
761
792
|
|
|
762
|
-
**TR:** Bu repo `@xrystal/core`
|
|
793
|
+
**TR:** Bu repo `@xrystal/core` kaynağıdır. `package.json` bump → commit → `xry tag` (prepare + `vX.Y.Z` push; GitHub Publish → npm). Tüketici için sadece `bun add @xrystal/core` yeter.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Yusuf Yasir KAYGUSUZ",
|
|
3
3
|
"name": "@xrystal/core",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.40.0",
|
|
5
5
|
"description": "Project core for xrystal",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public",
|
|
@@ -50,9 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"type": "module",
|
|
52
52
|
"bin": {
|
|
53
|
-
"
|
|
54
|
-
"xrystal": "./x/bin/main-cli.js",
|
|
55
|
-
"tmp": "./x/bin/main-cli.js"
|
|
53
|
+
"xry": "./x/bin/main-cli.js"
|
|
56
54
|
},
|
|
57
55
|
"scripts": {
|
|
58
56
|
"dev": "node x/bin/main-cli.js dev",
|
|
@@ -15,8 +15,9 @@ import {
|
|
|
15
15
|
import { formatLoaderSummary, summarizeLoaders } from '../helpers/tmp-config.mjs'
|
|
16
16
|
import { formatCreateHelp, formatCreateCommandHelp, LIST_BULLET } from '../helpers/cli-help.mjs'
|
|
17
17
|
import { setupProjectGitHooks } from '../scripts/install-git-hooks.mjs'
|
|
18
|
+
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
18
19
|
|
|
19
|
-
export function registerCreateCommand(cli, { cliName =
|
|
20
|
+
export function registerCreateCommand(cli, { cliName = CLI_PRIMARY_NAME, runtimeName, packageManager, installCommand, devCommand }) {
|
|
20
21
|
cli
|
|
21
22
|
.command('create <project-name> [target-path]')
|
|
22
23
|
.description('Scaffold new service from GitHub template')
|
|
@@ -2,6 +2,7 @@ import chalk from 'chalk'
|
|
|
2
2
|
|
|
3
3
|
import { printCommandHeader } from '../helpers/banner.mjs'
|
|
4
4
|
import { resolveDistLayout } from '../helpers/project-artifacts.mjs'
|
|
5
|
+
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
5
6
|
import {
|
|
6
7
|
getInstalledCoreVersion,
|
|
7
8
|
getProjectRoot,
|
|
@@ -22,7 +23,7 @@ function printSection(title) {
|
|
|
22
23
|
console.log(chalk.bold.cyan(`\n ${title}`))
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
export function registerDoctorCommand(cli, { cliName =
|
|
26
|
+
export function registerDoctorCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
26
27
|
cli
|
|
27
28
|
.command('doctor')
|
|
28
29
|
.description('Check runtime, git, and @xrystal/core alignment')
|
|
@@ -75,7 +76,7 @@ export function registerDoctorCommand(cli, { cliName = 'xcore' } = {}) {
|
|
|
75
76
|
console.log(` ${'source'.padEnd(18)}${chalk.bold(distLayout.layout.mainFolderPath)} ${chalk.gray('(paths.source)')}`)
|
|
76
77
|
console.log(` ${'dist'.padEnd(18)}${chalk.bold(distLayout.distPrefix)} ${chalk.gray('(paths.special.dist)')}`)
|
|
77
78
|
} else {
|
|
78
|
-
console.log(chalk.yellow(
|
|
79
|
+
console.log(chalk.yellow(` layout: tmp.yml not resolved — run ${CLI_PRIMARY_NAME} tmp`))
|
|
79
80
|
}
|
|
80
81
|
|
|
81
82
|
printSection('CLI (tool)')
|
|
@@ -134,7 +135,7 @@ export function registerDoctorCommand(cli, { cliName = 'xcore' } = {}) {
|
|
|
134
135
|
}
|
|
135
136
|
console.log(` ${'working tree'.padEnd(18)}${state.isClean ? chalk.green('clean') : chalk.yellow('dirty')}`)
|
|
136
137
|
const hookOk = isGitHookInstalled(root)
|
|
137
|
-
console.log(` ${'pre-commit hook'.padEnd(18)}${hookOk ? chalk.green('installed') : chalk.yellow('missing')} ${chalk.gray(
|
|
138
|
+
console.log(` ${'pre-commit hook'.padEnd(18)}${hookOk ? chalk.green('installed') : chalk.yellow('missing')} ${chalk.gray(`· ${CLI_PRIMARY_NAME} hooks install`)}`)
|
|
138
139
|
} catch (error) {
|
|
139
140
|
console.log(chalk.yellow(` git: ${error.message}`))
|
|
140
141
|
}
|
|
@@ -145,7 +146,7 @@ export function registerDoctorCommand(cli, { cliName = 'xcore' } = {}) {
|
|
|
145
146
|
console.log(` ${'outDir'.padEnd(18)}${chalk.bold(toolchain.outDir)}`)
|
|
146
147
|
const tsAudit = auditTsconfigAlignment(root)
|
|
147
148
|
if (tsAudit.missing) {
|
|
148
|
-
console.log(chalk.yellow(` ${'tsconfig'.padEnd(18)}missing · run
|
|
149
|
+
console.log(chalk.yellow(` ${'tsconfig'.padEnd(18)}missing · run ${CLI_PRIMARY_NAME} sync`))
|
|
149
150
|
} else if (tsAudit.ok) {
|
|
150
151
|
console.log(chalk.green(` ${'tsconfig'.padEnd(18)}aligned with tmp.yml`))
|
|
151
152
|
} else {
|
package/x/bin/commands/hooks.mjs
CHANGED
|
@@ -4,8 +4,9 @@ import { printCommandHeader } from '../helpers/banner.mjs'
|
|
|
4
4
|
import { readCliPackageJson } from '../helpers/project-root.mjs'
|
|
5
5
|
import { installGitHooks, isGitHookInstalled } from '../scripts/install-git-hooks.mjs'
|
|
6
6
|
import { getProjectRoot } from '../helpers/project-root.mjs'
|
|
7
|
+
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
7
8
|
|
|
8
|
-
export function registerHooksCommand(cli, { cliName =
|
|
9
|
+
export function registerHooksCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
9
10
|
const hooks = cli
|
|
10
11
|
.command('hooks')
|
|
11
12
|
.description('Install git hooks for version bump checks')
|
|
@@ -3,6 +3,7 @@ import fs from 'node:fs'
|
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import chalk from 'chalk'
|
|
5
5
|
|
|
6
|
+
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
6
7
|
import {
|
|
7
8
|
isCorePackageName,
|
|
8
9
|
readTmpBuildContext,
|
|
@@ -34,7 +35,7 @@ function resolveTestTarget(root) {
|
|
|
34
35
|
)
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
export function registerProjectCommands(cli, { cliName =
|
|
38
|
+
export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
38
39
|
cli
|
|
39
40
|
.command('dev')
|
|
40
41
|
.description('Watch source/index.ts with dev env files')
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
2
|
import { readCliPackageJson, readProjectPackageJson, getProjectRoot } from '../helpers/project-root.mjs'
|
|
3
3
|
import { compareSemver, getVersionState, resolveVersionBaseline, runTagRelease } from '../scripts/version-check.mjs'
|
|
4
|
+
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
4
5
|
|
|
5
|
-
export function registerTagCommand(cli, { cliName =
|
|
6
|
+
export function registerTagCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
6
7
|
cli
|
|
7
8
|
.command('tag')
|
|
8
9
|
.description('Git tag from package.json (+ npm publish for core)')
|
|
@@ -27,7 +28,7 @@ export function registerTagCommand(cli, { cliName = 'xcore' } = {}) {
|
|
|
27
28
|
})
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
export function registerVersionCommand(cli, { cliName =
|
|
31
|
+
export function registerVersionCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
31
32
|
cli
|
|
32
33
|
.command('version')
|
|
33
34
|
.description('Show CLI and project package versions')
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
|
|
3
|
+
import { printCommandHeader } from '../helpers/banner.mjs'
|
|
4
|
+
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
5
|
+
import { getProjectRoot, readCliPackageJson } from '../helpers/project-root.mjs'
|
|
6
|
+
import { auditTsconfigAlignment, syncProjectToolchain } from '../helpers/toolchain-config.mjs'
|
|
7
|
+
|
|
8
|
+
/** Sync tsconfig include/outDir/@/* from project tmp.yml. */
|
|
9
|
+
export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
10
|
+
const run = (options) => {
|
|
11
|
+
const root = getProjectRoot()
|
|
12
|
+
const auditBefore = auditTsconfigAlignment(root)
|
|
13
|
+
|
|
14
|
+
printCommandHeader({ cliName, command: 'sync', version: readCliPackageJson().version })
|
|
15
|
+
console.log(chalk.gray(` root: ${root}`))
|
|
16
|
+
|
|
17
|
+
const lo = auditBefore.layoutOptions ?? {}
|
|
18
|
+
console.log(chalk.gray(' from tmp.yml:'))
|
|
19
|
+
console.log(chalk.gray(` paths.root: ${lo.rootFolderPath ?? '—'}`))
|
|
20
|
+
console.log(chalk.gray(` paths.source: ${lo.mainFolderPath ?? '—'}`))
|
|
21
|
+
console.log(chalk.gray(` paths.dist: ${lo.pathsDist ?? '—'}`))
|
|
22
|
+
|
|
23
|
+
if (options.dryRun) {
|
|
24
|
+
const preview = syncProjectToolchain(root, { write: false })
|
|
25
|
+
console.log(chalk.gray('\n would write tsconfig.json:'))
|
|
26
|
+
console.log(chalk.gray(` include: ${JSON.stringify(preview.merged.include)}`))
|
|
27
|
+
console.log(chalk.gray(` outDir: ${preview.merged.compilerOptions.outDir}`))
|
|
28
|
+
console.log(chalk.gray(` paths: ${JSON.stringify(preview.merged.compilerOptions.paths)}`))
|
|
29
|
+
console.log(chalk.gray(`\n bunfig → ${preview.paths.bunfigAliasLine}\n`))
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const result = syncProjectToolchain(root, { write: true })
|
|
34
|
+
console.log(result.created
|
|
35
|
+
? chalk.green(` created ${result.tsconfigRel}`)
|
|
36
|
+
: chalk.green(` updated ${result.tsconfigRel}`))
|
|
37
|
+
console.log(chalk.gray(` include → ${JSON.stringify(result.merged.include)}`))
|
|
38
|
+
console.log(chalk.gray(` outDir → ${result.merged.compilerOptions.outDir}`))
|
|
39
|
+
console.log(chalk.yellow(`\n bunfig.toml [resolve.alias]: ${result.paths.bunfigAliasLine}\n`))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
cli
|
|
43
|
+
.command('sync')
|
|
44
|
+
.alias('sync-toolchain')
|
|
45
|
+
.description('Sync tsconfig paths from tmp.yml')
|
|
46
|
+
.option('--dry-run', 'Preview without writing')
|
|
47
|
+
.action(run)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** @deprecated use registerSyncCommand */
|
|
51
|
+
export const registerSyncToolchainCommand = registerSyncCommand
|
package/x/bin/commands/tmp.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import yaml from 'yaml'
|
|
|
5
5
|
import { printCommandHeader } from '../helpers/banner.mjs'
|
|
6
6
|
import { resolveObjWithHandlebars } from '../helpers/index.mjs'
|
|
7
7
|
import { getProjectRoot, readCliPackageJson } from '../helpers/project-root.mjs'
|
|
8
|
+
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
8
9
|
import {
|
|
9
10
|
ensureTmpFile,
|
|
10
11
|
ownerTmpFilePath,
|
|
@@ -13,7 +14,7 @@ import {
|
|
|
13
14
|
} from '../helpers/tmp-layout.mjs'
|
|
14
15
|
import { formatLoaderSummary, summarizeLoaders } from '../helpers/tmp-config.mjs'
|
|
15
16
|
|
|
16
|
-
export function registerTmpCommand(cli, { cliName =
|
|
17
|
+
export function registerTmpCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
17
18
|
cli
|
|
18
19
|
.command('tmp')
|
|
19
20
|
.description('Ensure tmp.yml exists (seed from @xrystal/core)')
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
// source/utils/constants/index.ts
|
|
2
|
-
import path2 from "node:path";
|
|
3
|
-
|
|
4
|
-
// source/utils/package-root.ts
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
var utilsDir = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
var sourceDir = path.resolve(utilsDir, "..");
|
|
9
|
-
var packageRootDir = path.resolve(utilsDir, "..", "..");
|
|
10
1
|
// source/utils/constants/defaults.json
|
|
11
2
|
var defaults_default = {
|
|
12
3
|
packageName: "@xrystal/core",
|
|
13
4
|
packageRootFolder: "x",
|
|
5
|
+
cliName: "xry",
|
|
6
|
+
cliBinNames: [
|
|
7
|
+
"xry"
|
|
8
|
+
],
|
|
14
9
|
tmpBaseName: "tmp",
|
|
15
10
|
tmpExtension: ".yml",
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
templateRepoUri: "https://github.com/xdloper/api-gpt-svc",
|
|
12
|
+
publicFolderName: "public",
|
|
13
|
+
kafkaLogsTopic: "log",
|
|
14
|
+
pathAliasKey: "@/*",
|
|
15
|
+
eslintRestrictedImportDepth: 2,
|
|
16
|
+
tmpWatchDefaults: {
|
|
17
|
+
intervalMs: 500,
|
|
18
|
+
minIntervalMs: 100,
|
|
19
|
+
maxIntervalMs: 1e4
|
|
21
20
|
},
|
|
22
21
|
buildDefaults: {
|
|
23
22
|
tsconfig: "tsconfig.json",
|
|
@@ -26,61 +25,43 @@ var defaults_default = {
|
|
|
26
25
|
declarations: false,
|
|
27
26
|
sourcemap: false,
|
|
28
27
|
minify: false
|
|
29
|
-
}
|
|
30
|
-
tsconfigDefaults: {
|
|
31
|
-
pathAliasKey: "@/*",
|
|
32
|
-
compilerOptions: {
|
|
33
|
-
noEmit: false,
|
|
34
|
-
noEmitOnError: false,
|
|
35
|
-
declaration: true,
|
|
36
|
-
emitDeclarationOnly: false,
|
|
37
|
-
sourceMap: false,
|
|
38
|
-
declarationMap: false,
|
|
39
|
-
strict: true,
|
|
40
|
-
noImplicitAny: true
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
eslintDefaults: {
|
|
44
|
-
restrictedImportDepth: 2
|
|
45
|
-
},
|
|
46
|
-
tmpWatchDefaults: {
|
|
47
|
-
intervalMs: 500,
|
|
48
|
-
minIntervalMs: 100,
|
|
49
|
-
maxIntervalMs: 1e4
|
|
50
|
-
},
|
|
51
|
-
publicFolderName: "public",
|
|
52
|
-
kafkaLogsTopic: "log",
|
|
53
|
-
templateRepoUri: "https://github.com/xdloper/api-gpt-svc"
|
|
28
|
+
}
|
|
54
29
|
};
|
|
55
30
|
|
|
56
|
-
// source/utils/
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
tsconfigDefaults: Object.freeze({
|
|
62
|
-
...defaults_default.tsconfigDefaults,
|
|
63
|
-
compilerOptions: Object.freeze({ ...defaults_default.tsconfigDefaults.compilerOptions })
|
|
64
|
-
}),
|
|
65
|
-
eslintDefaults: Object.freeze({ ...defaults_default.eslintDefaults }),
|
|
66
|
-
tmpWatchDefaults: Object.freeze({ ...defaults_default.tmpWatchDefaults })
|
|
31
|
+
// source/utils/helpers/tmp/path-normalize.ts
|
|
32
|
+
var DEFAULT_LAYOUT_PATHS = Object.freeze({
|
|
33
|
+
tests: "tests",
|
|
34
|
+
environments: "environments",
|
|
35
|
+
dist: "dist"
|
|
67
36
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
37
|
+
function normalizeRootFolder(value, fallback = "x") {
|
|
38
|
+
if (typeof value !== "string" || !value.trim())
|
|
39
|
+
return fallback;
|
|
40
|
+
return value.trim().replace(/^\.\/+/, "");
|
|
41
|
+
}
|
|
42
|
+
function normalizeSourceFolder(value, fallback = "./source") {
|
|
43
|
+
if (typeof value !== "string" || !value.trim())
|
|
44
|
+
return fallback;
|
|
45
|
+
const trimmed = value.trim();
|
|
46
|
+
if (trimmed.startsWith("./") || trimmed.startsWith("../"))
|
|
47
|
+
return trimmed;
|
|
48
|
+
return `./${trimmed}`;
|
|
49
|
+
}
|
|
50
|
+
function normalizeLayoutPaths(special, fallback = DEFAULT_LAYOUT_PATHS) {
|
|
51
|
+
const block = special && typeof special === "object" && !Array.isArray(special) ? special : {};
|
|
52
|
+
const pick = (key) => {
|
|
53
|
+
const raw = block[key];
|
|
54
|
+
return typeof raw === "string" && raw.trim() ? raw.trim() : fallback[key];
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
tests: pick("tests"),
|
|
58
|
+
environments: pick("environments"),
|
|
59
|
+
dist: pick("dist")
|
|
60
|
+
};
|
|
81
61
|
}
|
|
82
62
|
|
|
83
63
|
// source/utils/helpers/tmp/tmp-schema.ts
|
|
64
|
+
var BOOTSTRAP_SOURCE = "./source";
|
|
84
65
|
function isRecord(value) {
|
|
85
66
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
86
67
|
}
|
|
@@ -89,18 +70,11 @@ function readWatchIntervalValue(raw) {
|
|
|
89
70
|
return raw;
|
|
90
71
|
return;
|
|
91
72
|
}
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
return Constants.packageRootFolder;
|
|
95
|
-
return value.trim().replace(/^\.\/+/, "");
|
|
73
|
+
function normalizeRootFolder2(value) {
|
|
74
|
+
return normalizeRootFolder(value, defaults_default.packageRootFolder);
|
|
96
75
|
}
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
return Constants.mainSourceFolder;
|
|
100
|
-
const trimmed = value.trim();
|
|
101
|
-
if (trimmed.startsWith("./") || trimmed.startsWith("../"))
|
|
102
|
-
return trimmed;
|
|
103
|
-
return `./${trimmed}`;
|
|
76
|
+
function normalizeSourceFolder2(value) {
|
|
77
|
+
return normalizeSourceFolder(value, BOOTSTRAP_SOURCE);
|
|
104
78
|
}
|
|
105
79
|
function readTmpCoreBlock(configs) {
|
|
106
80
|
const core = isRecord(configs?.core) ? configs.core : {};
|
|
@@ -142,12 +116,7 @@ function readTmpServiceBlock(configs) {
|
|
|
142
116
|
};
|
|
143
117
|
}
|
|
144
118
|
function resolveServiceLayoutPaths(service) {
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
tests: special.tests?.trim() || Constants.layoutPaths.tests,
|
|
148
|
-
environments: special.environments?.trim() || Constants.layoutPaths.environments,
|
|
149
|
-
dist: special.dist?.trim() || Constants.layoutPaths.dist
|
|
150
|
-
};
|
|
119
|
+
return normalizeLayoutPaths(service.paths?.special, DEFAULT_LAYOUT_PATHS);
|
|
151
120
|
}
|
|
152
121
|
function buildNormalizedService(service) {
|
|
153
122
|
const layoutPaths = resolveServiceLayoutPaths(service);
|
|
@@ -155,8 +124,8 @@ function buildNormalizedService(service) {
|
|
|
155
124
|
name: service.name,
|
|
156
125
|
framework: service.framework ?? "elysia",
|
|
157
126
|
paths: {
|
|
158
|
-
root: service.paths?.root ??
|
|
159
|
-
source: service.paths?.source ??
|
|
127
|
+
root: service.paths?.root ?? defaults_default.packageRootFolder,
|
|
128
|
+
source: service.paths?.source ?? BOOTSTRAP_SOURCE,
|
|
160
129
|
special: layoutPaths
|
|
161
130
|
},
|
|
162
131
|
protocols: service.protocols,
|
|
@@ -179,7 +148,7 @@ function resolveTmpRuntimeConfigs(tmp) {
|
|
|
179
148
|
return {
|
|
180
149
|
service: normalizedService,
|
|
181
150
|
core: buildNormalizedCore(core),
|
|
182
|
-
rootFolderPath:
|
|
151
|
+
rootFolderPath: normalizeRootFolder2(normalizedService.paths.root)
|
|
183
152
|
};
|
|
184
153
|
}
|
|
185
154
|
function normalizeTmpDocument(tmp) {
|
|
@@ -194,6 +163,6 @@ export {
|
|
|
194
163
|
readTmpServiceBlock,
|
|
195
164
|
readTmpCoreBlock,
|
|
196
165
|
normalizeTmpDocument,
|
|
197
|
-
normalizeSourceFolder,
|
|
198
|
-
normalizeRootFolder
|
|
166
|
+
normalizeSourceFolder2 as normalizeSourceFolder,
|
|
167
|
+
normalizeRootFolder2 as normalizeRootFolder
|
|
199
168
|
};
|
package/x/bin/helpers/banner.mjs
CHANGED
|
@@ -36,7 +36,7 @@ export function brandTitle() {
|
|
|
36
36
|
return `${chalk.bold.white('xrystal ')}${chalk.bold.magenta('core')}`
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
/** Full banner — bare `
|
|
39
|
+
/** Full banner — bare `xry` / `xry -h` (root help). */
|
|
40
40
|
export function printBanner({ version, runtimeName, invokedAs } = {}) {
|
|
41
41
|
const bin = invokedAs && invokedAs !== 'main-cli.js' ? invokedAs : CLI_PRIMARY_NAME
|
|
42
42
|
const versionLabel = version ? chalk.bold.green(`v${version}`) : chalk.gray('v?')
|
|
@@ -53,7 +53,7 @@ export function printBanner({ version, runtimeName, invokedAs } = {}) {
|
|
|
53
53
|
` ${chalk.bold.cyan(bin)} ${chalk.gray('·')} ${chalk.bold('@xrystal/core')} ${versionLabel}${runtimeLabel ? ` ${chalk.gray('·')} ${runtimeLabel}` : ''}`,
|
|
54
54
|
)
|
|
55
55
|
console.log(chalk.bold.gray(' loaders · tmp.yml · dto · i18n · multi-protocol · scaffold'))
|
|
56
|
-
console.log(chalk.dim(`
|
|
56
|
+
console.log(chalk.dim(` cli: ${BIN_ALIASES_LABEL}`))
|
|
57
57
|
console.log('')
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -6,7 +6,16 @@ import { packageDefaults } from '../paths.mjs'
|
|
|
6
6
|
import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
|
|
7
7
|
import { normalizeTmpDocument, readTmpServiceBlock } from './tmp-schema.mjs'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
import { CLI_BIN_NAMES, CLI_PRIMARY_NAME } from './cli-identity.mjs'
|
|
10
|
+
|
|
11
|
+
function escapeRegExp(value) {
|
|
12
|
+
return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const CLI_BUILD_SCRIPT_RE = new RegExp(
|
|
16
|
+
`^(${CLI_BIN_NAMES.map(escapeRegExp).join('|')})\\s+build\\b`,
|
|
17
|
+
)
|
|
18
|
+
|
|
10
19
|
|
|
11
20
|
const BUILD_DEFAULTS = packageDefaults.buildDefaults ?? {}
|
|
12
21
|
|
|
@@ -331,7 +340,7 @@ export function resolveDevEntry(root, layout) {
|
|
|
331
340
|
const tsEntry = path.join(path.resolve(root, layout.mainFolderPath), 'index.ts')
|
|
332
341
|
if (!fs.existsSync(tsEntry)) {
|
|
333
342
|
throw new Error(
|
|
334
|
-
`No index.ts for dev (expected ${path.relative(root, tsEntry)}). Prod: ${layout.rootFolderPath}/${layout.paths.dist}/index.js via
|
|
343
|
+
`No index.ts for dev (expected ${path.relative(root, tsEntry)}). Prod: ${layout.rootFolderPath}/${layout.paths.dist}/index.js via ${CLI_PRIMARY_NAME} start.`,
|
|
335
344
|
)
|
|
336
345
|
}
|
|
337
346
|
return relativeFromRoot(root, tsEntry)
|