@xrystal/core 3.41.0 → 3.44.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 +28 -24
- package/package.json +1 -1
- package/x/bin/commands/project.mjs +23 -10
- package/x/bin/commands/sync.mjs +1 -1
- package/x/bin/helpers/.generated/.generated-from +1 -0
- package/x/bin/helpers/.generated/seed-from-tmp.mjs +115 -0
- package/x/bin/helpers/.generated/tmp-schema.mjs +98 -14
- package/x/bin/helpers/banner.mjs +27 -26
- package/x/bin/helpers/build-config.mjs +78 -23
- package/x/bin/helpers/cli-identity.mjs +1 -1
- package/x/bin/helpers/package-defaults.mjs +11 -5
- package/x/bin/helpers/project-artifacts.mjs +101 -38
- package/x/bin/helpers/project-root.mjs +1 -1
- package/x/bin/helpers/seed-from-tmp.mjs +12 -64
- package/x/bin/helpers/tmp-layout.mjs +8 -4
- package/x/bin/helpers/tmp-schema.mjs +5 -0
- package/x/bin/helpers/toolchain-config.mjs +3 -2
- package/x/bin/paths.mjs +13 -2
- package/x/bin/scripts/publish-guard.mjs +36 -15
- package/x/bin/scripts/sync-cli-defaults.mjs +10 -15
- package/x/dist/utils/constants/defaults.json +6 -0
- package/x/dist/utils/constants/index.d.ts +7 -0
- package/x/dist/utils/constants/index.js +1 -1
- package/x/dist/utils/helpers/tmp/index.d.ts +2 -1
- package/x/dist/utils/helpers/tmp/index.js +1 -1
- package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -1
- package/x/dist/utils/helpers/tmp/seed-from-tmp.d.ts +2 -0
- package/x/dist/utils/helpers/tmp/seed-from-tmp.js +1 -1
- package/x/dist/utils/helpers/tmp/tmp-interpolate.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/tmp-interpolate.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +12 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -1
- package/x/dist/utils/helpers/tmp/toolchain-heal.d.ts +46 -0
- package/x/dist/utils/helpers/tmp/toolchain-heal.js +2 -0
- package/x/dist/utils/models/enums/index.d.ts +10 -0
- package/x/dist/utils/models/enums/index.js +1 -1
- package/x/tmp.yml +7 -1
- package/x/bin/helpers/defaults.json +0 -28
package/README.md
CHANGED
|
@@ -3,26 +3,26 @@
|
|
|
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:** `xry` · **Version:** `3.
|
|
6
|
+
**CLI:** `xry` · **Version:** `3.44.0` · [npm](https://www.npmjs.com/package/@xrystal/core)
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
-
## What's new in 3.
|
|
10
|
+
## What's new in 3.44.0 / 3.44.0'da ne değişti
|
|
11
11
|
|
|
12
12
|
| Change / Değişiklik | EN | TR |
|
|
13
13
|
|---------------------|----|----|
|
|
14
|
-
| **
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
| **
|
|
14
|
+
| **Layout auto-sync** | Path changes in `tmp.yml` → tsconfig heals live (and on any `xry` entry) | Klasör/path değişince tsconfig otomatik |
|
|
15
|
+
| **`xry sync`** | Force / dry-run / CI — not a daily ritual | Elle force; günlük zorunluluk değil |
|
|
16
|
+
| **CLI banner** | Leads with `@xrystal/core` (bin still `xry`) | Banner paket adıyla açılır |
|
|
17
|
+
| **Runtime coverage** | bun + node runners / bundler `auto` tested | Her iki runtime doğrulandı |
|
|
18
|
+
|
|
19
|
+
Carried from **3.43.0:** `configs.global.runtime` (`bun`\|`node`), `configs.global.vars`, `build.bundler` (`auto`\|`bun`\|`tsc`\|`esbuild`).
|
|
18
20
|
|
|
19
21
|
```bash
|
|
20
|
-
npx xry sync # apply tmp.yml → tsconfig
|
|
22
|
+
npx xry sync # force-apply tmp.yml → tsconfig (usually auto)
|
|
21
23
|
npx xry sync --dry-run
|
|
22
24
|
```
|
|
23
25
|
|
|
24
|
-
**Breaking / Kırıcı:** replace scripts and docs that called `xcore`, `xrystal`, or the old `tmp` bin with `xry`.
|
|
25
|
-
|
|
26
26
|
---
|
|
27
27
|
|
|
28
28
|
## Why / Neden
|
|
@@ -35,7 +35,7 @@ npx xry sync --dry-run
|
|
|
35
35
|
# EN: existing project — kernel only · TR: mevcut proje — sadece kernel
|
|
36
36
|
bun add @xrystal/core
|
|
37
37
|
npx xry tmp # seed x/tmp.yml into YOUR layout
|
|
38
|
-
|
|
38
|
+
# tsconfig paths auto-heal from tmp.yml (xry sync = force / CI)
|
|
39
39
|
# wire coreLoader + dtoMiddleware in your entry file
|
|
40
40
|
```
|
|
41
41
|
|
|
@@ -73,7 +73,7 @@ mkdir my-api && cd my-api
|
|
|
73
73
|
bun init -y
|
|
74
74
|
bun add @xrystal/core elysia
|
|
75
75
|
npx xry tmp # EN: create x/tmp.yml from seed if missing · TR: yoksa seed'den oluşturur
|
|
76
|
-
npx xry
|
|
76
|
+
npx xry doctor # EN: optional health check · TR: isteğe bağlı sağlık kontrolü
|
|
77
77
|
```
|
|
78
78
|
|
|
79
79
|
`package.json`:
|
|
@@ -81,7 +81,7 @@ npx xry sync # EN: tsconfig from tmp.yml · TR: tmp.yml → tsconfig
|
|
|
81
81
|
```json
|
|
82
82
|
{
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@xrystal/core": "^3.
|
|
84
|
+
"@xrystal/core": "^3.44.0",
|
|
85
85
|
"elysia": "^1.4.19"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
@@ -115,14 +115,16 @@ my-api/
|
|
|
115
115
|
|
|
116
116
|
| File / Dosya | Owns / Sahip olduğu |
|
|
117
117
|
|--------------|---------------------|
|
|
118
|
-
| `x/tmp.yml` | Service paths, loaders, protocols,
|
|
119
|
-
| `tsconfig.json` | Compiler language options; path layout
|
|
120
|
-
| Package defaults (internal) | CLI
|
|
118
|
+
| `x/tmp.yml` | Service paths, loaders, protocols, runtime, bundler · layout seed |
|
|
119
|
+
| `tsconfig.json` | Compiler language options; path layout auto-heals from `tmp.yml` |
|
|
120
|
+
| Package defaults (internal) | Package identity (`@xrystal/core`) + CLI bin (`xry`) — not project layout |
|
|
121
121
|
|
|
122
122
|
### Minimal `x/tmp.yml`
|
|
123
123
|
|
|
124
124
|
```yaml
|
|
125
125
|
configs:
|
|
126
|
+
global:
|
|
127
|
+
runtime: bun # bun | node
|
|
126
128
|
service:
|
|
127
129
|
name: my-api
|
|
128
130
|
framework: elysia # express | elysia | node | fetch
|
|
@@ -130,6 +132,8 @@ configs:
|
|
|
130
132
|
root: ./x
|
|
131
133
|
source: ./source
|
|
132
134
|
protocols: [http]
|
|
135
|
+
build:
|
|
136
|
+
bundler: auto # auto | bun | tsc | esbuild
|
|
133
137
|
loaders:
|
|
134
138
|
dto: { withDefaultHeaders: true }
|
|
135
139
|
loggers: { logLevel: info }
|
|
@@ -174,7 +178,7 @@ bun run dev
|
|
|
174
178
|
|-----------------|----|----|
|
|
175
179
|
| `xry create [name] [path]` | Start project from template + `tmp.yml` | Template + `tmp.yml` ile proje başlat |
|
|
176
180
|
| `xry tmp` | Create `tmp.yml` from seed if missing | `tmp.yml` yoksa seed'den oluştur |
|
|
177
|
-
| `xry sync` |
|
|
181
|
+
| `xry sync` | Force-sync `tsconfig` from `tmp.yml` (auto-heals otherwise) | Force sync (normalde otomatik) |
|
|
178
182
|
| `xry dev` | Watch `source/index.ts` + dev env | `source/index.ts` watch + dev env |
|
|
179
183
|
| `xry build` | Output → `x/dist` | Çıktı → `x/dist` |
|
|
180
184
|
| `xry start` | Run `x/dist` + prod env | `x/dist` + prod env |
|
|
@@ -192,7 +196,7 @@ bun run dev
|
|
|
192
196
|
| Feature / Özellik | EN | TR | Example / Örnek |
|
|
193
197
|
|-------------------|----|----|-----------------|
|
|
194
198
|
| **Boot / DI** | Awilix loaders: System, Logger, Kafka, Dto, i18n, … | Awilix loader'lar | `await coreLoader({})` |
|
|
195
|
-
| **Live `tmp.yml`** | Edit file → loaders re-sync
|
|
199
|
+
| **Live `tmp.yml`** | Edit file → loaders re-sync; path changes heal tsconfig | Dosya → loader sync; path → tsconfig heal | `paths.source` rename → tsconfig updates |
|
|
196
200
|
| **`ctr()` pipeline** | `checks → logic → response`, no `res.json()` | Endpoint pipeline | `list = this.ctr({ logic: async () => ({ data: [] }) })` |
|
|
197
201
|
| **DTO responses** | Standard API shape via `@xrystal/dto` | Standart API cevabı | `return { data: [], message: '@successfully user' }` |
|
|
198
202
|
| **Trace** | `requestId` per request/job (ALS) | İstek/job trace id | `req.requestId` · `runWithTrace('job-1', fn)` |
|
|
@@ -542,13 +546,13 @@ Details / detay: [`@xrystal/dto`](https://www.npmjs.com/package/@xrystal/dto)
|
|
|
542
546
|
|
|
543
547
|
```
|
|
544
548
|
1. Your repo + bun add @xrystal/core + xry tmp (or xry create for greenfield)
|
|
545
|
-
2.
|
|
546
|
-
3.
|
|
547
|
-
4.
|
|
548
|
-
5.
|
|
549
|
-
6.
|
|
550
|
-
7. xry
|
|
551
|
-
8. xry
|
|
549
|
+
2. tmp.yml → framework, runtime, loaders, paths (tsconfig auto-heals)
|
|
550
|
+
3. coreLoader() → once at top of YOUR index.ts
|
|
551
|
+
4. Controller → ctr() per endpoint
|
|
552
|
+
5. Framework → dtoMiddleware + routes
|
|
553
|
+
6. xry dev → develop
|
|
554
|
+
7. xry build → start → production
|
|
555
|
+
8. xry sync → only when you need a force / dry-run / CI pin
|
|
552
556
|
```
|
|
553
557
|
|
|
554
558
|
### Express — end-to-end / uçtan uca
|
package/package.json
CHANGED
|
@@ -11,7 +11,10 @@ import {
|
|
|
11
11
|
resolveDevEntry,
|
|
12
12
|
resolveDistEntryAbs,
|
|
13
13
|
resolveEnvFiles,
|
|
14
|
+
resolvePackageScriptRunner,
|
|
15
|
+
resolveRuntimeRunner,
|
|
14
16
|
resolveServiceBuildSteps,
|
|
17
|
+
resolveTestCommand,
|
|
15
18
|
shouldDelegatePackageBuild,
|
|
16
19
|
summarizeBuildPlan,
|
|
17
20
|
} from '../helpers/build-config.mjs'
|
|
@@ -41,39 +44,45 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
|
|
|
41
44
|
.description('Watch source/index.ts with dev env files')
|
|
42
45
|
.action(() => {
|
|
43
46
|
const root = getProjectRoot()
|
|
44
|
-
const { layout } = readTmpBuildContext(root)
|
|
47
|
+
const { layout, runtime } = readTmpBuildContext(root)
|
|
45
48
|
const entry = resolveDevEntry(root, layout)
|
|
46
49
|
const envFiles = resolveEnvFiles(layout.pathsAbs.environments, ['.global.env', '.dev.env'])
|
|
47
50
|
const envArgs = envFiles.map((file) => `--env-file=${file}`).join(' ')
|
|
51
|
+
const runner = resolveRuntimeRunner(runtime)
|
|
48
52
|
|
|
49
53
|
printCommandHeader({ cliName, command: 'dev', version: readCliPackageJson().version })
|
|
50
54
|
console.log(chalk.gray(` root: ${root}`))
|
|
55
|
+
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
51
56
|
console.log(chalk.gray(` entry: ${entry} (.ts)\n`))
|
|
52
|
-
runInProject(root,
|
|
57
|
+
runInProject(root, `${runner} --watch ${envArgs} ${entry}`.trim())
|
|
53
58
|
})
|
|
54
59
|
|
|
55
60
|
cli
|
|
56
61
|
.command('build')
|
|
57
|
-
.description('Bundle to dist/ (
|
|
62
|
+
.description('Bundle to dist/ (bundler from tmp.yml)')
|
|
58
63
|
.action(() => {
|
|
59
64
|
const root = getProjectRoot()
|
|
60
65
|
ensureProjectArtifacts(root, { writeToolchain: true, writeManifest: true })
|
|
61
66
|
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
|
|
67
|
+
const { layout, build, runtime, bundler } = readTmpBuildContext(root)
|
|
62
68
|
|
|
63
69
|
printCommandHeader({ cliName, command: 'build', version: readCliPackageJson().version })
|
|
64
70
|
console.log(chalk.gray(` root: ${root}`))
|
|
65
71
|
|
|
66
72
|
if (shouldDelegatePackageBuild(pkg)) {
|
|
67
|
-
runInProject(root,
|
|
73
|
+
runInProject(root, `${resolvePackageScriptRunner(runtime)} build`)
|
|
68
74
|
return
|
|
69
75
|
}
|
|
70
76
|
|
|
71
|
-
const
|
|
72
|
-
const plan = summarizeBuildPlan(root, layout, build)
|
|
77
|
+
const plan = summarizeBuildPlan(root, layout, build, runtime)
|
|
73
78
|
const steps = isCorePackageName(pkg.name)
|
|
74
79
|
? resolveCoreBuildSteps(root, plan.distRel, build)
|
|
75
|
-
: resolveServiceBuildSteps(root, layout, build)
|
|
80
|
+
: resolveServiceBuildSteps(root, layout, build, runtime)
|
|
76
81
|
console.log(chalk.gray(` mode: ${isCorePackageName(pkg.name) ? 'core entries' : 'service tsconfig + tmp overrides'}`))
|
|
82
|
+
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
83
|
+
if (!isCorePackageName(pkg.name)) {
|
|
84
|
+
console.log(chalk.gray(` bundler: ${plan.bundler || bundler}`))
|
|
85
|
+
}
|
|
77
86
|
if (plan.tsconfigRel) {
|
|
78
87
|
console.log(chalk.gray(` tsconfig: ${plan.tsconfigRel}`))
|
|
79
88
|
}
|
|
@@ -94,7 +103,7 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
|
|
|
94
103
|
.description('Run dist/index.js with prod env files')
|
|
95
104
|
.action(() => {
|
|
96
105
|
const root = getProjectRoot()
|
|
97
|
-
const { layout, build } = readTmpBuildContext(root)
|
|
106
|
+
const { layout, build, runtime } = readTmpBuildContext(root)
|
|
98
107
|
const entryAbs = resolveDistEntryAbs(root, layout, build)
|
|
99
108
|
|
|
100
109
|
if (!fs.existsSync(entryAbs)) {
|
|
@@ -106,11 +115,13 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
|
|
|
106
115
|
const entry = relativeFromRoot(root, entryAbs)
|
|
107
116
|
const envFiles = resolveEnvFiles(layout.pathsAbs.environments, ['.global.env', '.prod.env'])
|
|
108
117
|
const envArgs = envFiles.map((file) => `--env-file=${file}`).join(' ')
|
|
118
|
+
const runner = resolveRuntimeRunner(runtime)
|
|
109
119
|
|
|
110
120
|
printCommandHeader({ cliName, command: 'start', version: readCliPackageJson().version })
|
|
111
121
|
console.log(chalk.gray(` root: ${root}`))
|
|
122
|
+
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
112
123
|
console.log(chalk.gray(` entry: ${entry} (.js)\n`))
|
|
113
|
-
runInProject(root,
|
|
124
|
+
runInProject(root, `${runner} ${envArgs} ${entry}`.trim())
|
|
114
125
|
})
|
|
115
126
|
|
|
116
127
|
cli
|
|
@@ -118,10 +129,12 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
|
|
|
118
129
|
.description('Run tests from tmp.yml paths')
|
|
119
130
|
.action(() => {
|
|
120
131
|
const root = getProjectRoot()
|
|
132
|
+
const { runtime } = readTmpBuildContext(root)
|
|
121
133
|
const target = resolveTestTarget(root)
|
|
122
134
|
|
|
123
135
|
printCommandHeader({ cliName, command: 'test', version: readCliPackageJson().version })
|
|
136
|
+
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
124
137
|
console.log(chalk.gray(` target: ${target}\n`))
|
|
125
|
-
runInProject(root,
|
|
138
|
+
runInProject(root, resolveTestCommand(runtime, target))
|
|
126
139
|
})
|
|
127
140
|
}
|
package/x/bin/commands/sync.mjs
CHANGED
|
@@ -42,7 +42,7 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
42
42
|
cli
|
|
43
43
|
.command('sync')
|
|
44
44
|
.alias('sync-toolchain')
|
|
45
|
-
.description('
|
|
45
|
+
.description('Force-sync tsconfig from tmp.yml (also auto-heals on layout path change / CLI entry)')
|
|
46
46
|
.option('--dry-run', 'Preview without writing')
|
|
47
47
|
.action(run)
|
|
48
48
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// source/utils/helpers/tmp/seed-from-tmp.ts
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import yaml from "yaml";
|
|
6
|
+
// source/utils/constants/defaults.json
|
|
7
|
+
var defaults_default = {
|
|
8
|
+
packageName: "@xrystal/core",
|
|
9
|
+
packageRootFolder: "x",
|
|
10
|
+
cliName: "xry",
|
|
11
|
+
cliBinNames: [
|
|
12
|
+
"xry"
|
|
13
|
+
],
|
|
14
|
+
tmpBaseName: "tmp",
|
|
15
|
+
tmpExtension: ".yml",
|
|
16
|
+
templateRepoUri: "https://github.com/xdloper/api-gpt-svc",
|
|
17
|
+
publicFolderName: "public",
|
|
18
|
+
kafkaLogsTopic: "log",
|
|
19
|
+
pathAliasKey: "@/*",
|
|
20
|
+
eslintRestrictedImportDepth: 2,
|
|
21
|
+
brand: {
|
|
22
|
+
primary: "xrystal",
|
|
23
|
+
secondary: "core",
|
|
24
|
+
tagline: "microservice runtime library",
|
|
25
|
+
capabilities: "loaders · tmp.yml · dto · i18n · multi-protocol · scaffold"
|
|
26
|
+
},
|
|
27
|
+
tmpWatchDefaults: {
|
|
28
|
+
intervalMs: 500,
|
|
29
|
+
minIntervalMs: 100,
|
|
30
|
+
maxIntervalMs: 1e4
|
|
31
|
+
},
|
|
32
|
+
buildDefaults: {
|
|
33
|
+
tsconfig: "tsconfig.json",
|
|
34
|
+
typecheck: false,
|
|
35
|
+
tscLenient: false,
|
|
36
|
+
declarations: false,
|
|
37
|
+
sourcemap: false,
|
|
38
|
+
minify: false
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// source/utils/helpers/tmp/path-normalize.ts
|
|
43
|
+
function normalizeRootFolder(value, fallback) {
|
|
44
|
+
if (typeof value !== "string" || !value.trim())
|
|
45
|
+
return fallback;
|
|
46
|
+
return value.trim().replace(/^\.\/+/, "");
|
|
47
|
+
}
|
|
48
|
+
function normalizeSourceFolder(value, fallback) {
|
|
49
|
+
if (typeof value !== "string" || !value.trim())
|
|
50
|
+
return fallback;
|
|
51
|
+
const trimmed = value.trim();
|
|
52
|
+
if (trimmed.startsWith("./") || trimmed.startsWith("../"))
|
|
53
|
+
return trimmed;
|
|
54
|
+
return `./${trimmed}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// source/utils/helpers/tmp/seed-from-tmp.ts
|
|
58
|
+
var here = path.dirname(fileURLToPath(import.meta.url));
|
|
59
|
+
var tmpFileName = `${defaults_default.tmpBaseName}${defaults_default.tmpExtension}`;
|
|
60
|
+
function requireString(value, label) {
|
|
61
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
62
|
+
throw new Error(`${defaults_default.packageName}: bundled tmp.yml missing ${label}`);
|
|
63
|
+
}
|
|
64
|
+
return value.trim();
|
|
65
|
+
}
|
|
66
|
+
function readLayoutFromSpecial(special) {
|
|
67
|
+
const block = special && typeof special === "object" && !Array.isArray(special) ? special : {};
|
|
68
|
+
return {
|
|
69
|
+
tests: requireString(block.tests, "configs.service.paths.special.tests"),
|
|
70
|
+
environments: requireString(block.environments, "configs.service.paths.special.environments"),
|
|
71
|
+
dist: requireString(block.dist, "configs.service.paths.special.dist")
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function findBundledTmpFile(explicit) {
|
|
75
|
+
if (explicit) {
|
|
76
|
+
if (!fs.existsSync(explicit)) {
|
|
77
|
+
throw new Error(`${defaults_default.packageName}: bundled tmp.yml missing at ${explicit}`);
|
|
78
|
+
}
|
|
79
|
+
return explicit;
|
|
80
|
+
}
|
|
81
|
+
const starts = [here, process.cwd()];
|
|
82
|
+
for (const start of starts) {
|
|
83
|
+
let dir = path.resolve(start);
|
|
84
|
+
for (;; ) {
|
|
85
|
+
const candidate = path.join(dir, defaults_default.packageRootFolder, tmpFileName);
|
|
86
|
+
if (fs.existsSync(candidate))
|
|
87
|
+
return candidate;
|
|
88
|
+
const parent = path.dirname(dir);
|
|
89
|
+
if (parent === dir)
|
|
90
|
+
break;
|
|
91
|
+
dir = parent;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
throw new Error(`${defaults_default.packageName}: bundled ${defaults_default.packageRootFolder}/${tmpFileName} not found from ${here}`);
|
|
95
|
+
}
|
|
96
|
+
function loadSeedFromBundledTmp(tmpFilePath) {
|
|
97
|
+
const file = findBundledTmpFile(tmpFilePath);
|
|
98
|
+
const doc = yaml.parse(fs.readFileSync(file, "utf8"));
|
|
99
|
+
const configs = doc?.configs && typeof doc.configs === "object" ? doc.configs : {};
|
|
100
|
+
const service = configs.service && typeof configs.service === "object" ? configs.service : {};
|
|
101
|
+
const paths = service.paths && typeof service.paths === "object" ? service.paths : {};
|
|
102
|
+
const sourceRaw = requireString(paths.source, "configs.service.paths.source");
|
|
103
|
+
return {
|
|
104
|
+
rootFolder: normalizeRootFolder(paths.root, defaults_default.packageRootFolder),
|
|
105
|
+
sourceFolder: normalizeSourceFolder(sourceRaw, sourceRaw),
|
|
106
|
+
framework: requireString(service.framework, "configs.service.framework"),
|
|
107
|
+
layout: readLayoutFromSpecial(paths.special)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
var seedFromTmp = loadSeedFromBundledTmp();
|
|
111
|
+
export {
|
|
112
|
+
seedFromTmp,
|
|
113
|
+
defaults_default as packageIdentityDefaults,
|
|
114
|
+
loadSeedFromBundledTmp
|
|
115
|
+
};
|
|
@@ -13,6 +13,12 @@ var defaults_default = {
|
|
|
13
13
|
kafkaLogsTopic: "log",
|
|
14
14
|
pathAliasKey: "@/*",
|
|
15
15
|
eslintRestrictedImportDepth: 2,
|
|
16
|
+
brand: {
|
|
17
|
+
primary: "xrystal",
|
|
18
|
+
secondary: "core",
|
|
19
|
+
tagline: "microservice runtime library",
|
|
20
|
+
capabilities: "loaders · tmp.yml · dto · i18n · multi-protocol · scaffold"
|
|
21
|
+
},
|
|
16
22
|
tmpWatchDefaults: {
|
|
17
23
|
intervalMs: 500,
|
|
18
24
|
minIntervalMs: 100,
|
|
@@ -116,24 +122,81 @@ function loadSeedFromBundledTmp(tmpFilePath) {
|
|
|
116
122
|
}
|
|
117
123
|
var seedFromTmp = loadSeedFromBundledTmp();
|
|
118
124
|
|
|
119
|
-
// source/utils/helpers/tmp/tmp-
|
|
125
|
+
// source/utils/helpers/tmp/tmp-interpolate.ts
|
|
126
|
+
import Handlebars from "handlebars";
|
|
120
127
|
function isRecord(value) {
|
|
121
128
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
122
129
|
}
|
|
130
|
+
function interpolateWithContext(value, context) {
|
|
131
|
+
if (typeof value === "string") {
|
|
132
|
+
if (!value.includes("{{"))
|
|
133
|
+
return value;
|
|
134
|
+
return Handlebars.compile(value)(context);
|
|
135
|
+
}
|
|
136
|
+
if (Array.isArray(value)) {
|
|
137
|
+
return value.map((item) => interpolateWithContext(item, context));
|
|
138
|
+
}
|
|
139
|
+
if (isRecord(value)) {
|
|
140
|
+
const next = {};
|
|
141
|
+
for (const [key, child] of Object.entries(value)) {
|
|
142
|
+
next[key] = interpolateWithContext(child, context);
|
|
143
|
+
}
|
|
144
|
+
return next;
|
|
145
|
+
}
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// source/utils/helpers/tmp/tmp-schema.ts
|
|
150
|
+
function isRecord2(value) {
|
|
151
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
152
|
+
}
|
|
123
153
|
function readWatchIntervalValue(raw) {
|
|
124
154
|
if (typeof raw === "number" || typeof raw === "string")
|
|
125
155
|
return raw;
|
|
126
156
|
return;
|
|
127
157
|
}
|
|
158
|
+
function normalizeRuntime(value) {
|
|
159
|
+
const raw = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
160
|
+
if (raw === "node" /* NODE */)
|
|
161
|
+
return "node" /* NODE */;
|
|
162
|
+
if (raw === "bun" /* BUN */)
|
|
163
|
+
return "bun" /* BUN */;
|
|
164
|
+
return "bun" /* BUN */;
|
|
165
|
+
}
|
|
166
|
+
function normalizeBundler(value) {
|
|
167
|
+
const raw = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
168
|
+
if (raw === "tsc" /* TSC */)
|
|
169
|
+
return "tsc" /* TSC */;
|
|
170
|
+
if (raw === "esbuild" /* ESBUILD */)
|
|
171
|
+
return "esbuild" /* ESBUILD */;
|
|
172
|
+
if (raw === "bun" /* BUN */)
|
|
173
|
+
return "bun" /* BUN */;
|
|
174
|
+
if (raw === "auto" /* AUTO */)
|
|
175
|
+
return "auto" /* AUTO */;
|
|
176
|
+
return "auto" /* AUTO */;
|
|
177
|
+
}
|
|
178
|
+
function resolveEffectiveBundler(bundler, runtime) {
|
|
179
|
+
if (bundler !== "auto" /* AUTO */)
|
|
180
|
+
return bundler;
|
|
181
|
+
return runtime === "node" /* NODE */ ? "tsc" /* TSC */ : "bun" /* BUN */;
|
|
182
|
+
}
|
|
128
183
|
function normalizeRootFolder2(value) {
|
|
129
184
|
return normalizeRootFolder(value, defaults_default.packageRootFolder);
|
|
130
185
|
}
|
|
131
186
|
function normalizeSourceFolder2(value) {
|
|
132
187
|
return normalizeSourceFolder(value, seedFromTmp.sourceFolder);
|
|
133
188
|
}
|
|
189
|
+
function readTmpGlobalBlock(configs) {
|
|
190
|
+
const global = isRecord2(configs?.global) ? configs.global : {};
|
|
191
|
+
const varsRaw = isRecord2(global.vars) ? global.vars : {};
|
|
192
|
+
return {
|
|
193
|
+
runtime: normalizeRuntime(global.runtime),
|
|
194
|
+
vars: { ...varsRaw }
|
|
195
|
+
};
|
|
196
|
+
}
|
|
134
197
|
function readTmpCoreBlock(configs) {
|
|
135
|
-
const core =
|
|
136
|
-
const tmp =
|
|
198
|
+
const core = isRecord2(configs?.core) ? configs.core : {};
|
|
199
|
+
const tmp = isRecord2(core.tmp) ? core.tmp : {};
|
|
137
200
|
return {
|
|
138
201
|
tmp: {
|
|
139
202
|
fileWatchIntervalMs: readWatchIntervalValue(tmp.fileWatchIntervalMs)
|
|
@@ -141,15 +204,15 @@ function readTmpCoreBlock(configs) {
|
|
|
141
204
|
};
|
|
142
205
|
}
|
|
143
206
|
function readTmpServiceBlock(configs) {
|
|
144
|
-
const service =
|
|
145
|
-
const pathsRaw =
|
|
146
|
-
const special =
|
|
147
|
-
let loaders =
|
|
148
|
-
let build =
|
|
149
|
-
if (loaders &&
|
|
207
|
+
const service = isRecord2(configs?.service) ? configs.service : {};
|
|
208
|
+
const pathsRaw = isRecord2(service.paths) ? service.paths : {};
|
|
209
|
+
const special = isRecord2(pathsRaw.special) ? pathsRaw.special : {};
|
|
210
|
+
let loaders = isRecord2(service.loaders) ? { ...service.loaders } : undefined;
|
|
211
|
+
let build = isRecord2(service.build) ? service.build : undefined;
|
|
212
|
+
if (loaders && isRecord2(loaders.build)) {
|
|
150
213
|
const { build: nestedBuild, ...rest } = loaders;
|
|
151
214
|
loaders = rest;
|
|
152
|
-
if (!build &&
|
|
215
|
+
if (!build && isRecord2(nestedBuild)) {
|
|
153
216
|
build = nestedBuild;
|
|
154
217
|
}
|
|
155
218
|
}
|
|
@@ -195,29 +258,50 @@ function buildNormalizedCore(core) {
|
|
|
195
258
|
}
|
|
196
259
|
};
|
|
197
260
|
}
|
|
261
|
+
function buildTmpVarContext(global) {
|
|
262
|
+
return {
|
|
263
|
+
...global.vars,
|
|
264
|
+
runtime: global.runtime,
|
|
265
|
+
global
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
function applyTmpGlobalVars(tmp) {
|
|
269
|
+
const configs = isRecord2(tmp.configs) ? tmp.configs : {};
|
|
270
|
+
const global = readTmpGlobalBlock(configs);
|
|
271
|
+
return interpolateWithContext(tmp, buildTmpVarContext(global));
|
|
272
|
+
}
|
|
198
273
|
function resolveTmpRuntimeConfigs(tmp) {
|
|
199
|
-
const configs =
|
|
274
|
+
const configs = isRecord2(tmp?.configs) ? tmp.configs : {};
|
|
275
|
+
const global = readTmpGlobalBlock(configs);
|
|
200
276
|
const service = readTmpServiceBlock(configs);
|
|
201
277
|
const core = readTmpCoreBlock(configs);
|
|
202
278
|
const normalizedService = buildNormalizedService(service);
|
|
203
279
|
return {
|
|
280
|
+
global,
|
|
204
281
|
service: normalizedService,
|
|
205
282
|
core: buildNormalizedCore(core),
|
|
206
283
|
rootFolderPath: normalizeRootFolder2(normalizedService.paths.root)
|
|
207
284
|
};
|
|
208
285
|
}
|
|
209
286
|
function normalizeTmpDocument(tmp) {
|
|
287
|
+
const interpolated = applyTmpGlobalVars(tmp);
|
|
210
288
|
return {
|
|
211
|
-
...
|
|
212
|
-
configs: resolveTmpRuntimeConfigs(
|
|
289
|
+
...interpolated,
|
|
290
|
+
configs: resolveTmpRuntimeConfigs(interpolated)
|
|
213
291
|
};
|
|
214
292
|
}
|
|
215
293
|
export {
|
|
216
294
|
resolveTmpRuntimeConfigs,
|
|
217
295
|
resolveServiceLayoutPaths,
|
|
296
|
+
resolveEffectiveBundler,
|
|
218
297
|
readTmpServiceBlock,
|
|
298
|
+
readTmpGlobalBlock,
|
|
219
299
|
readTmpCoreBlock,
|
|
220
300
|
normalizeTmpDocument,
|
|
221
301
|
normalizeSourceFolder2 as normalizeSourceFolder,
|
|
222
|
-
|
|
302
|
+
normalizeRuntime,
|
|
303
|
+
normalizeRootFolder2 as normalizeRootFolder,
|
|
304
|
+
normalizeBundler,
|
|
305
|
+
buildTmpVarContext,
|
|
306
|
+
applyTmpGlobalVars
|
|
223
307
|
};
|
package/x/bin/helpers/banner.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
CLI_BIN_NAMES,
|
|
5
|
+
packageDefaults,
|
|
6
|
+
} from './package-defaults.mjs'
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
const XRYSTAL_LINES = [
|
|
8
|
+
const WORDMARK_PRIMARY = [
|
|
8
9
|
' _ _ ',
|
|
9
10
|
' __ ___ __ _ _ ___| |_ __ _| |',
|
|
10
11
|
" \\ \\/ / '__| | | / __| __/ _` | |",
|
|
@@ -13,7 +14,7 @@ const XRYSTAL_LINES = [
|
|
|
13
14
|
' |___/ ',
|
|
14
15
|
]
|
|
15
16
|
|
|
16
|
-
const
|
|
17
|
+
const WORDMARK_SECONDARY = [
|
|
17
18
|
'',
|
|
18
19
|
' ___ ___ _ __ ___ ',
|
|
19
20
|
" / __/ _ \\| '__/ _ \\",
|
|
@@ -22,56 +23,56 @@ const CORE_LINES = [
|
|
|
22
23
|
'',
|
|
23
24
|
]
|
|
24
25
|
|
|
25
|
-
const WORDMARK_WIDTH = Math.max(...
|
|
26
|
+
const WORDMARK_WIDTH = Math.max(...WORDMARK_PRIMARY.map((line) => line.length))
|
|
26
27
|
const BIN_ALIASES_LABEL = CLI_BIN_NAMES.join(' · ')
|
|
28
|
+
|
|
29
|
+
function brand() {
|
|
30
|
+
return packageDefaults.brand
|
|
31
|
+
}
|
|
32
|
+
|
|
27
33
|
export function printWordmark() {
|
|
28
|
-
const rows = Math.max(
|
|
34
|
+
const rows = Math.max(WORDMARK_PRIMARY.length, WORDMARK_SECONDARY.length)
|
|
29
35
|
for (let i = 0; i < rows; i += 1) {
|
|
30
|
-
const left = (
|
|
31
|
-
const right =
|
|
36
|
+
const left = (WORDMARK_PRIMARY[i] ?? '').padEnd(WORDMARK_WIDTH)
|
|
37
|
+
const right = WORDMARK_SECONDARY[i] ?? ''
|
|
32
38
|
console.log(` ${chalk.bold.white(left)}${chalk.bold.magenta(right)}`)
|
|
33
39
|
}
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
export function brandTitle() {
|
|
37
|
-
|
|
43
|
+
const { primary, secondary } = brand()
|
|
44
|
+
return `${chalk.bold.white(`${primary} `)}${chalk.bold.magenta(secondary)}`
|
|
38
45
|
}
|
|
39
46
|
|
|
40
|
-
|
|
41
|
-
export function printBanner({ version, runtimeName, invokedAs } = {}) {
|
|
42
|
-
const bin = invokedAs && invokedAs !== 'main-cli.js' ? invokedAs : CLI_PRIMARY_NAME
|
|
47
|
+
export function printBanner({ version, runtimeName, invokedAs: _invokedAs } = {}) {
|
|
43
48
|
const versionLabel = version ? chalk.bold.green(`v${version}`) : chalk.gray('v?')
|
|
44
49
|
const runtimeLabel = runtimeName ? chalk.bold.white(runtimeName) : ''
|
|
50
|
+
const { tagline, capabilities } = brand()
|
|
45
51
|
|
|
46
52
|
console.log('')
|
|
47
|
-
|
|
48
53
|
printWordmark()
|
|
49
54
|
console.log('')
|
|
50
|
-
console.log(chalk.bold.gray(
|
|
51
|
-
|
|
55
|
+
console.log(chalk.bold.gray(` ${tagline}`))
|
|
52
56
|
console.log('')
|
|
53
57
|
console.log(
|
|
54
|
-
` ${chalk.bold.cyan(
|
|
58
|
+
` ${chalk.bold.cyan(packageDefaults.packageName)} ${versionLabel}${runtimeLabel ? ` ${chalk.gray('·')} ${runtimeLabel}` : ''}`,
|
|
55
59
|
)
|
|
56
|
-
console.log(chalk.bold.gray(
|
|
60
|
+
console.log(chalk.bold.gray(` ${capabilities}`))
|
|
57
61
|
console.log(chalk.dim(` cli: ${BIN_ALIASES_LABEL}`))
|
|
58
62
|
console.log('')
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
export function printCommandHeader({ cliName, command, version } = {}) {
|
|
63
|
-
const label = cliName || CLI_PRIMARY_NAME
|
|
65
|
+
export function printCommandHeader({ cliName: _cliName, command, version } = {}) {
|
|
64
66
|
const versionLabel = version ? chalk.green(`v${version}`) : ''
|
|
67
|
+
const title = command
|
|
68
|
+
? `${packageDefaults.packageName} ${command}`
|
|
69
|
+
: packageDefaults.packageName
|
|
65
70
|
console.log('')
|
|
66
71
|
console.log(
|
|
67
|
-
`${chalk.bold.cyan(
|
|
72
|
+
`${chalk.bold.cyan(title)} ${chalk.gray('·')} ${brandTitle()} ${versionLabel}`.trim(),
|
|
68
73
|
)
|
|
69
74
|
}
|
|
70
75
|
|
|
71
|
-
/**
|
|
72
|
-
* Root banner: bare CLI, or root-level -h / --help / help.
|
|
73
|
-
* Subcommands keep compact headers only.
|
|
74
|
-
*/
|
|
75
76
|
export function shouldShowBanner(argv = process.argv) {
|
|
76
77
|
const args = argv.slice(2)
|
|
77
78
|
if (!args.length) return true
|