@xrystal/core 3.40.0 → 3.41.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 +7 -7
- package/package.json +1 -1
- package/x/bin/commands/doctor.mjs +4 -3
- package/x/bin/commands/hooks.mjs +2 -1
- package/x/bin/commands/release.mjs +2 -1
- package/x/bin/commands/tmp.mjs +2 -1
- package/x/bin/helpers/.generated/tmp-schema.mjs +68 -13
- package/x/bin/helpers/banner.mjs +2 -1
- package/x/bin/helpers/cli-help.mjs +3 -2
- package/x/bin/helpers/package-defaults.mjs +4 -7
- package/x/bin/helpers/project-artifacts.mjs +2 -2
- package/x/bin/helpers/project-root.mjs +4 -4
- package/x/bin/helpers/seed-from-tmp.mjs +61 -44
- package/x/bin/helpers/tmp-config.mjs +2 -1
- package/x/bin/helpers/tmp-layout.mjs +5 -5
- package/x/bin/helpers/toolchain-config.mjs +2 -2
- package/x/bin/main-cli.js +1 -1
- package/x/bin/scripts/install-git-hooks.mjs +2 -1
- package/x/bin/scripts/release-prepare.mjs +2 -2
- package/x/dist/utils/constants/index.d.ts +1 -2
- package/x/dist/utils/constants/index.js +1 -1
- package/x/dist/utils/helpers/core/tmp-layout.js +1 -1
- package/x/dist/utils/helpers/tmp/index.d.ts +1 -1
- package/x/dist/utils/helpers/tmp/index.js +1 -1
- package/x/dist/utils/helpers/tmp/path-normalize.d.ts +3 -5
- package/x/dist/utils/helpers/tmp/path-normalize.js +1 -1
- package/x/dist/utils/helpers/tmp/seed-from-tmp.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/seed-from-tmp.js +1 -1
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +0 -4
- package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -1
- package/x/dist/utils/models/classes/class.x.js +1 -1
package/README.md
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
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.41.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.41.0 / 3.41.0'da ne değişti
|
|
11
11
|
|
|
12
12
|
| Change / Değişiklik | EN | TR |
|
|
13
13
|
|---------------------|----|----|
|
|
14
|
-
| **
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
|
|
|
14
|
+
| **No layout hardcodes** | `source` / `dist` / `tests` / framework come from bundled `x/tmp.yml` seed | Layout + framework seed = `x/tmp.yml` |
|
|
15
|
+
| **Package name** | Errors, CLI copy, hooks use `defaults.packageName` (not a literal `@xrystal/core`) | Paket adı `defaults.packageName` |
|
|
16
|
+
| **`xry sync`** | Still syncs `tsconfig` paths from project `tmp.yml` | `tmp.yml` → tsconfig |
|
|
17
|
+
| **CLI** | Single bin `xry` (since 3.40.0) | Tek bin `xry` (3.40.0+) |
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
20
|
npx xry sync # apply tmp.yml → tsconfig / bunfig aliases
|
|
@@ -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.41.0",
|
|
85
85
|
"elysia": "^1.4.19"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
package/package.json
CHANGED
|
@@ -13,6 +13,7 @@ import { listRuntimeInventory, resolveRuntimeInfo } from '../helpers/runtime-inf
|
|
|
13
13
|
import { evaluateVersionBump, getVersionState, resolveCommitVersionHint, resolveVersionBaseline, VERSION_PATTERN } from '../scripts/version-check.mjs'
|
|
14
14
|
import { auditTsconfigAlignment, resolveToolchainPathsFromProject } from '../helpers/toolchain-config.mjs'
|
|
15
15
|
import { isGitHookInstalled } from '../scripts/install-git-hooks.mjs'
|
|
16
|
+
import { packageDefaults } from '../helpers/package-defaults.mjs'
|
|
16
17
|
|
|
17
18
|
function statusValue(value, okLabel = null) {
|
|
18
19
|
if (value == null || value === '') return chalk.gray('—')
|
|
@@ -26,7 +27,7 @@ function printSection(title) {
|
|
|
26
27
|
export function registerDoctorCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
27
28
|
cli
|
|
28
29
|
.command('doctor')
|
|
29
|
-
.description(
|
|
30
|
+
.description(`Check runtime, git, and ${packageDefaults.packageName} alignment`)
|
|
30
31
|
.action(async () => {
|
|
31
32
|
const root = getProjectRoot()
|
|
32
33
|
const cliPkg = readCliPackageJson()
|
|
@@ -80,7 +81,7 @@ export function registerDoctorCommand(cli, { cliName = CLI_PRIMARY_NAME } = {})
|
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
printSection('CLI (tool)')
|
|
83
|
-
console.log(` ${
|
|
84
|
+
console.log(` ${packageDefaults.packageName.padEnd(18)}${chalk.bold(`${cliPkg.name}@${cliPkg.version}`)}`)
|
|
84
85
|
|
|
85
86
|
printSection('Package')
|
|
86
87
|
console.log(` ${'name'.padEnd(18)}${chalk.bold(projectPkg.name)}`)
|
|
@@ -101,7 +102,7 @@ export function registerDoctorCommand(cli, { cliName = CLI_PRIMARY_NAME } = {})
|
|
|
101
102
|
console.log(chalk.bold.red(' ⚠ CLI / node_modules version mismatch'))
|
|
102
103
|
console.log(chalk.yellow(` CLI (this binary): ${cliPkg.version}`))
|
|
103
104
|
console.log(chalk.yellow(` node_modules installed: ${core.installed}`))
|
|
104
|
-
console.log(chalk.gray(` fix: bun add
|
|
105
|
+
console.log(chalk.gray(` fix: bun add ${packageDefaults.packageName}@${cliPkg.version}`))
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
printSection('Git')
|
package/x/bin/commands/hooks.mjs
CHANGED
|
@@ -5,6 +5,7 @@ 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
7
|
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
8
|
+
import { packageDefaults } from '../helpers/package-defaults.mjs'
|
|
8
9
|
|
|
9
10
|
export function registerHooksCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
10
11
|
const hooks = cli
|
|
@@ -45,7 +46,7 @@ export function registerHooksCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
45
46
|
|
|
46
47
|
hooks
|
|
47
48
|
.command('status')
|
|
48
|
-
.description(
|
|
49
|
+
.description(`Show whether ${packageDefaults.packageName} pre-commit hook is installed`)
|
|
49
50
|
.action(() => {
|
|
50
51
|
const root = getProjectRoot()
|
|
51
52
|
printCommandHeader({ cliName, command: 'hooks status', version: readCliPackageJson().version })
|
|
@@ -2,6 +2,7 @@ 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
4
|
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
5
|
+
import { packageDefaults } from '../helpers/package-defaults.mjs'
|
|
5
6
|
|
|
6
7
|
export function registerTagCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
7
8
|
cli
|
|
@@ -41,7 +42,7 @@ export function registerVersionCommand(cli, { cliName = CLI_PRIMARY_NAME } = {})
|
|
|
41
42
|
|
|
42
43
|
console.log(chalk.cyan(`\n${cliName} version\n`))
|
|
43
44
|
console.log(chalk.gray(' CLI (tool)'))
|
|
44
|
-
console.log(`
|
|
45
|
+
console.log(` ${packageDefaults.packageName}: ${chalk.bold(`${cliPkg.name}@${cliPkg.version}`)}`)
|
|
45
46
|
console.log('')
|
|
46
47
|
console.log(chalk.gray(' Project'))
|
|
47
48
|
console.log(` root: ${root}`)
|
package/x/bin/commands/tmp.mjs
CHANGED
|
@@ -13,11 +13,12 @@ import {
|
|
|
13
13
|
resolveTmpLayoutOrDefaults,
|
|
14
14
|
} from '../helpers/tmp-layout.mjs'
|
|
15
15
|
import { formatLoaderSummary, summarizeLoaders } from '../helpers/tmp-config.mjs'
|
|
16
|
+
import { packageDefaults } from '../helpers/package-defaults.mjs'
|
|
16
17
|
|
|
17
18
|
export function registerTmpCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
18
19
|
cli
|
|
19
20
|
.command('tmp')
|
|
20
|
-
.description(
|
|
21
|
+
.description(`Ensure tmp.yml exists (seed from ${packageDefaults.packageName})`)
|
|
21
22
|
.option('--dry-run', 'Show target path without writing')
|
|
22
23
|
.action((options) => {
|
|
23
24
|
const root = getProjectRoot()
|
|
@@ -28,18 +28,19 @@ var defaults_default = {
|
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
// source/utils/helpers/tmp/seed-from-tmp.ts
|
|
32
|
+
import fs from "node:fs";
|
|
33
|
+
import path from "node:path";
|
|
34
|
+
import { fileURLToPath } from "node:url";
|
|
35
|
+
import yaml from "yaml";
|
|
36
|
+
|
|
31
37
|
// source/utils/helpers/tmp/path-normalize.ts
|
|
32
|
-
|
|
33
|
-
tests: "tests",
|
|
34
|
-
environments: "environments",
|
|
35
|
-
dist: "dist"
|
|
36
|
-
});
|
|
37
|
-
function normalizeRootFolder(value, fallback = "x") {
|
|
38
|
+
function normalizeRootFolder(value, fallback) {
|
|
38
39
|
if (typeof value !== "string" || !value.trim())
|
|
39
40
|
return fallback;
|
|
40
41
|
return value.trim().replace(/^\.\/+/, "");
|
|
41
42
|
}
|
|
42
|
-
function normalizeSourceFolder(value, fallback
|
|
43
|
+
function normalizeSourceFolder(value, fallback) {
|
|
43
44
|
if (typeof value !== "string" || !value.trim())
|
|
44
45
|
return fallback;
|
|
45
46
|
const trimmed = value.trim();
|
|
@@ -47,7 +48,7 @@ function normalizeSourceFolder(value, fallback = "./source") {
|
|
|
47
48
|
return trimmed;
|
|
48
49
|
return `./${trimmed}`;
|
|
49
50
|
}
|
|
50
|
-
function normalizeLayoutPaths(special, fallback
|
|
51
|
+
function normalizeLayoutPaths(special, fallback) {
|
|
51
52
|
const block = special && typeof special === "object" && !Array.isArray(special) ? special : {};
|
|
52
53
|
const pick = (key) => {
|
|
53
54
|
const raw = block[key];
|
|
@@ -60,8 +61,62 @@ function normalizeLayoutPaths(special, fallback = DEFAULT_LAYOUT_PATHS) {
|
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
// source/utils/helpers/tmp/seed-from-tmp.ts
|
|
65
|
+
var here = path.dirname(fileURLToPath(import.meta.url));
|
|
66
|
+
var tmpFileName = `${defaults_default.tmpBaseName}${defaults_default.tmpExtension}`;
|
|
67
|
+
function requireString(value, label) {
|
|
68
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
69
|
+
throw new Error(`${defaults_default.packageName}: bundled tmp.yml missing ${label}`);
|
|
70
|
+
}
|
|
71
|
+
return value.trim();
|
|
72
|
+
}
|
|
73
|
+
function readLayoutFromSpecial(special) {
|
|
74
|
+
const block = special && typeof special === "object" && !Array.isArray(special) ? special : {};
|
|
75
|
+
return {
|
|
76
|
+
tests: requireString(block.tests, "configs.service.paths.special.tests"),
|
|
77
|
+
environments: requireString(block.environments, "configs.service.paths.special.environments"),
|
|
78
|
+
dist: requireString(block.dist, "configs.service.paths.special.dist")
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function findBundledTmpFile(explicit) {
|
|
82
|
+
if (explicit) {
|
|
83
|
+
if (!fs.existsSync(explicit)) {
|
|
84
|
+
throw new Error(`${defaults_default.packageName}: bundled tmp.yml missing at ${explicit}`);
|
|
85
|
+
}
|
|
86
|
+
return explicit;
|
|
87
|
+
}
|
|
88
|
+
const starts = [here, process.cwd()];
|
|
89
|
+
for (const start of starts) {
|
|
90
|
+
let dir = path.resolve(start);
|
|
91
|
+
for (;; ) {
|
|
92
|
+
const candidate = path.join(dir, defaults_default.packageRootFolder, tmpFileName);
|
|
93
|
+
if (fs.existsSync(candidate))
|
|
94
|
+
return candidate;
|
|
95
|
+
const parent = path.dirname(dir);
|
|
96
|
+
if (parent === dir)
|
|
97
|
+
break;
|
|
98
|
+
dir = parent;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
throw new Error(`${defaults_default.packageName}: bundled ${defaults_default.packageRootFolder}/${tmpFileName} not found from ${here}`);
|
|
102
|
+
}
|
|
103
|
+
function loadSeedFromBundledTmp(tmpFilePath) {
|
|
104
|
+
const file = findBundledTmpFile(tmpFilePath);
|
|
105
|
+
const doc = yaml.parse(fs.readFileSync(file, "utf8"));
|
|
106
|
+
const configs = doc?.configs && typeof doc.configs === "object" ? doc.configs : {};
|
|
107
|
+
const service = configs.service && typeof configs.service === "object" ? configs.service : {};
|
|
108
|
+
const paths = service.paths && typeof service.paths === "object" ? service.paths : {};
|
|
109
|
+
const sourceRaw = requireString(paths.source, "configs.service.paths.source");
|
|
110
|
+
return {
|
|
111
|
+
rootFolder: normalizeRootFolder(paths.root, defaults_default.packageRootFolder),
|
|
112
|
+
sourceFolder: normalizeSourceFolder(sourceRaw, sourceRaw),
|
|
113
|
+
framework: requireString(service.framework, "configs.service.framework"),
|
|
114
|
+
layout: readLayoutFromSpecial(paths.special)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
var seedFromTmp = loadSeedFromBundledTmp();
|
|
118
|
+
|
|
63
119
|
// source/utils/helpers/tmp/tmp-schema.ts
|
|
64
|
-
var BOOTSTRAP_SOURCE = "./source";
|
|
65
120
|
function isRecord(value) {
|
|
66
121
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
67
122
|
}
|
|
@@ -74,7 +129,7 @@ function normalizeRootFolder2(value) {
|
|
|
74
129
|
return normalizeRootFolder(value, defaults_default.packageRootFolder);
|
|
75
130
|
}
|
|
76
131
|
function normalizeSourceFolder2(value) {
|
|
77
|
-
return normalizeSourceFolder(value,
|
|
132
|
+
return normalizeSourceFolder(value, seedFromTmp.sourceFolder);
|
|
78
133
|
}
|
|
79
134
|
function readTmpCoreBlock(configs) {
|
|
80
135
|
const core = isRecord(configs?.core) ? configs.core : {};
|
|
@@ -116,16 +171,16 @@ function readTmpServiceBlock(configs) {
|
|
|
116
171
|
};
|
|
117
172
|
}
|
|
118
173
|
function resolveServiceLayoutPaths(service) {
|
|
119
|
-
return normalizeLayoutPaths(service.paths?.special,
|
|
174
|
+
return normalizeLayoutPaths(service.paths?.special, seedFromTmp.layout);
|
|
120
175
|
}
|
|
121
176
|
function buildNormalizedService(service) {
|
|
122
177
|
const layoutPaths = resolveServiceLayoutPaths(service);
|
|
123
178
|
return {
|
|
124
179
|
name: service.name,
|
|
125
|
-
framework: service.framework ??
|
|
180
|
+
framework: service.framework ?? seedFromTmp.framework,
|
|
126
181
|
paths: {
|
|
127
182
|
root: service.paths?.root ?? defaults_default.packageRootFolder,
|
|
128
|
-
source: service.paths?.source ??
|
|
183
|
+
source: service.paths?.source ?? seedFromTmp.sourceFolder,
|
|
129
184
|
special: layoutPaths
|
|
130
185
|
},
|
|
131
186
|
protocols: service.protocols,
|
package/x/bin/helpers/banner.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
2
|
|
|
3
3
|
import { CLI_BIN_NAMES, CLI_PRIMARY_NAME } from './cli-identity.mjs'
|
|
4
|
+
import { packageDefaults } from './package-defaults.mjs'
|
|
4
5
|
|
|
5
6
|
/** figlet standard — lowercase wordmark, split for two-tone print */
|
|
6
7
|
const XRYSTAL_LINES = [
|
|
@@ -50,7 +51,7 @@ export function printBanner({ version, runtimeName, invokedAs } = {}) {
|
|
|
50
51
|
|
|
51
52
|
console.log('')
|
|
52
53
|
console.log(
|
|
53
|
-
` ${chalk.bold.cyan(bin)} ${chalk.gray('·')} ${chalk.bold(
|
|
54
|
+
` ${chalk.bold.cyan(bin)} ${chalk.gray('·')} ${chalk.bold(packageDefaults.packageName)} ${versionLabel}${runtimeLabel ? ` ${chalk.gray('·')} ${runtimeLabel}` : ''}`,
|
|
54
55
|
)
|
|
55
56
|
console.log(chalk.bold.gray(' loaders · tmp.yml · dto · i18n · multi-protocol · scaffold'))
|
|
56
57
|
console.log(chalk.dim(` cli: ${BIN_ALIASES_LABEL}`))
|
|
@@ -4,6 +4,7 @@ import { CLI_BIN_NAMES, CLI_PRIMARY_NAME } from './cli-identity.mjs'
|
|
|
4
4
|
|
|
5
5
|
export const LIST_BULLET = chalk.cyan('◆')
|
|
6
6
|
import { brandTitle } from './banner.mjs'
|
|
7
|
+
import { packageDefaults } from './package-defaults.mjs'
|
|
7
8
|
|
|
8
9
|
const QUICK_COMMANDS = [
|
|
9
10
|
{ cmd: 'create', hint: '<name> [path]', desc: 'Scaffold service · path defaults to cwd' },
|
|
@@ -36,7 +37,7 @@ const COMMAND_GROUPS = [
|
|
|
36
37
|
{
|
|
37
38
|
title: 'Diagnostics',
|
|
38
39
|
items: [
|
|
39
|
-
{ cmd: 'doctor', desc:
|
|
40
|
+
{ cmd: 'doctor', desc: `Runtime · git · ${packageDefaults.packageName} version alignment` },
|
|
40
41
|
{ cmd: 'version', desc: 'CLI tool vs project package.json versions' },
|
|
41
42
|
],
|
|
42
43
|
},
|
|
@@ -85,7 +86,7 @@ export function printQuickStartGuide({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
85
86
|
|
|
86
87
|
function formatOptionsSection(cliName) {
|
|
87
88
|
const items = [
|
|
88
|
-
{ cmd: '-V, --version', desc:
|
|
89
|
+
{ cmd: '-V, --version', desc: `Show ${packageDefaults.packageName} CLI version` },
|
|
89
90
|
{ cmd: '-h, --help', desc: 'Show full command list' },
|
|
90
91
|
]
|
|
91
92
|
const lines = [
|
|
@@ -15,26 +15,23 @@ function loadRawDefaults() {
|
|
|
15
15
|
if (fs.existsSync(file)) return JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
16
16
|
}
|
|
17
17
|
throw new Error(
|
|
18
|
-
|
|
18
|
+
`package defaults.json not found. Expected ${AUTHORED_DEFAULTS} or ${PUBLISHED_DEFAULTS}`,
|
|
19
19
|
)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const raw = loadRawDefaults()
|
|
23
23
|
const seed = loadSeedLayoutFromBundledTmp(packageRoot, raw)
|
|
24
24
|
|
|
25
|
-
/**
|
|
26
|
-
* defaults.json → package identity + CLI + build flags
|
|
27
|
-
* helpers/seed-from-tmp → layout from bundled x/tmp.yml
|
|
28
|
-
*/
|
|
29
25
|
export const packageDefaults = Object.freeze({
|
|
30
26
|
...raw,
|
|
31
27
|
mainSourceFolder: seed.mainSourceFolder,
|
|
28
|
+
framework: seed.framework,
|
|
32
29
|
layoutPaths: seed.layoutPaths,
|
|
33
30
|
buildDefaults: Object.freeze({ ...(raw.buildDefaults ?? {}) }),
|
|
34
31
|
tmpWatchDefaults: Object.freeze({ ...(raw.tmpWatchDefaults ?? {}) }),
|
|
35
32
|
cliBinNames: Object.freeze([...(raw.cliBinNames ?? [raw.cliName])]),
|
|
36
|
-
pathAliasKey: raw.pathAliasKey
|
|
37
|
-
eslintRestrictedImportDepth: raw.eslintRestrictedImportDepth
|
|
33
|
+
pathAliasKey: raw.pathAliasKey,
|
|
34
|
+
eslintRestrictedImportDepth: raw.eslintRestrictedImportDepth,
|
|
38
35
|
})
|
|
39
36
|
|
|
40
37
|
export const coreVersionPattern = /^\d{2}\.\d{2}\.\d{2}-v\d+$/
|
|
@@ -103,7 +103,7 @@ export function syncCliTmpSchema(root = process.cwd(), { force = false } = {}) {
|
|
|
103
103
|
|
|
104
104
|
fs.mkdirSync(outDir, { recursive: true })
|
|
105
105
|
execSync(
|
|
106
|
-
`bun build "${srcAbs}" --outfile "${CLI_GENERATED_SCHEMA}" --target node --format esm`,
|
|
106
|
+
`bun build "${srcAbs}" --outfile "${CLI_GENERATED_SCHEMA}" --target node --format esm --external yaml`,
|
|
107
107
|
{ cwd: root, stdio: 'pipe' },
|
|
108
108
|
)
|
|
109
109
|
fs.writeFileSync(path.join(outDir, '.generated-from'), `${CLI_SCHEMA_SOURCE}\n`)
|
|
@@ -116,7 +116,7 @@ export function syncPackageManifest(root = process.cwd(), { write = true } = {})
|
|
|
116
116
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
117
117
|
|
|
118
118
|
if (!isCorePackageName(pkg.name)) {
|
|
119
|
-
return { synced: false, reason:
|
|
119
|
+
return { synced: false, reason: `not ${packageDefaults.packageName}` }
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
const { distPrefix, distRel } = resolveDistLayout(root)
|
|
@@ -14,10 +14,10 @@ export function resolveProjectRoot(startDir = process.cwd()) {
|
|
|
14
14
|
const pkgPath = path.join(dir, 'package.json')
|
|
15
15
|
if (fs.existsSync(pkgPath)) {
|
|
16
16
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
17
|
-
if (pkg.name ===
|
|
17
|
+
if (pkg.name === packageDefaults.packageName) return dir
|
|
18
18
|
|
|
19
19
|
const deps = { ...pkg.dependencies, ...pkg.devDependencies }
|
|
20
|
-
if (deps[
|
|
20
|
+
if (deps[packageDefaults.packageName]) return dir
|
|
21
21
|
}
|
|
22
22
|
dir = path.dirname(dir)
|
|
23
23
|
}
|
|
@@ -48,8 +48,8 @@ export function readProjectPackageJson(root = resolveProjectRoot()) {
|
|
|
48
48
|
export function getInstalledCoreVersion(root = resolveProjectRoot()) {
|
|
49
49
|
const project = readProjectPackageJson(root)
|
|
50
50
|
const declared =
|
|
51
|
-
project.dependencies?.[
|
|
52
|
-
?? project.devDependencies?.[
|
|
51
|
+
project.dependencies?.[packageDefaults.packageName]
|
|
52
|
+
?? project.devDependencies?.[packageDefaults.packageName]
|
|
53
53
|
?? null
|
|
54
54
|
|
|
55
55
|
const installedPath = path.join(root, 'node_modules', '@xrystal', 'core', 'package.json')
|
|
@@ -1,52 +1,69 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import path from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
3
4
|
import yaml from 'yaml'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
6
|
+
const here = path.dirname(fileURLToPath(import.meta.url))
|
|
7
|
+
|
|
8
|
+
function requireString(value, label) {
|
|
9
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
10
|
+
throw new Error(label)
|
|
11
|
+
}
|
|
12
|
+
return value.trim()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function normalizeRootFolder(value, fallback) {
|
|
16
|
+
if (typeof value !== 'string' || !value.trim()) return fallback
|
|
17
|
+
return value.trim().replace(/^\.\/+/, '')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function normalizeSourceFolder(value, packageName) {
|
|
21
|
+
const trimmed = requireString(value, `${packageName}: bundled tmp.yml missing configs.service.paths.source`)
|
|
22
|
+
if (trimmed.startsWith('./') || trimmed.startsWith('../')) return trimmed
|
|
23
|
+
return `./${trimmed}`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function readLayout(special, packageName) {
|
|
27
|
+
const block = special && typeof special === 'object' && !Array.isArray(special) ? special : {}
|
|
28
|
+
const miss = (field) => `${packageName}: bundled tmp.yml missing configs.service.paths.special.${field}`
|
|
29
|
+
return Object.freeze({
|
|
30
|
+
tests: requireString(block.tests, miss('tests')),
|
|
31
|
+
environments: requireString(block.environments, miss('environments')),
|
|
32
|
+
dist: requireString(block.dist, miss('dist')),
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function findBundledTmpFile(packageRoot, raw) {
|
|
37
|
+
const packageName = requireString(raw.packageName, 'defaults.packageName required')
|
|
38
|
+
const rootFolder = requireString(raw.packageRootFolder, `${packageName}: defaults.packageRootFolder required`)
|
|
39
|
+
const tmpBase = requireString(raw.tmpBaseName, `${packageName}: defaults.tmpBaseName required`)
|
|
40
|
+
const tmpExt = requireString(raw.tmpExtension, `${packageName}: defaults.tmpExtension required`)
|
|
41
|
+
const tmpFileName = `${tmpBase}${tmpExt}`
|
|
42
|
+
const direct = path.join(packageRoot, rootFolder, tmpFileName)
|
|
43
|
+
if (fs.existsSync(direct)) return { file: direct, rootFolder, packageName }
|
|
44
|
+
|
|
45
|
+
let dir = path.resolve(here)
|
|
46
|
+
for (;;) {
|
|
47
|
+
const candidate = path.join(dir, rootFolder, tmpFileName)
|
|
48
|
+
if (fs.existsSync(candidate)) return { file: candidate, rootFolder, packageName }
|
|
49
|
+
const parent = path.dirname(dir)
|
|
50
|
+
if (parent === dir) break
|
|
51
|
+
dir = parent
|
|
25
52
|
}
|
|
26
53
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
: rootFolder,
|
|
42
|
-
mainSourceFolder,
|
|
43
|
-
layoutPaths: Object.freeze({
|
|
44
|
-
tests: special.tests || 'tests',
|
|
45
|
-
environments: special.environments || 'environments',
|
|
46
|
-
dist: special.dist || 'dist',
|
|
47
|
-
}),
|
|
48
|
-
}
|
|
49
|
-
} catch {
|
|
50
|
-
return fallback
|
|
54
|
+
throw new Error(`${packageName}: bundled ${rootFolder}/${tmpFileName} not found`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function loadSeedLayoutFromBundledTmp(packageRoot, raw = {}) {
|
|
58
|
+
const { file, rootFolder, packageName } = findBundledTmpFile(packageRoot, raw)
|
|
59
|
+
const doc = yaml.parse(fs.readFileSync(file, 'utf8'))
|
|
60
|
+
const service = doc?.configs?.service ?? {}
|
|
61
|
+
const paths = service.paths ?? {}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
rootFolder: normalizeRootFolder(paths.root, rootFolder),
|
|
65
|
+
mainSourceFolder: normalizeSourceFolder(paths.source, packageName),
|
|
66
|
+
framework: requireString(service.framework, `${packageName}: bundled tmp.yml missing configs.service.framework`),
|
|
67
|
+
layoutPaths: readLayout(paths.special, packageName),
|
|
51
68
|
}
|
|
52
69
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readTmpServiceBlock } from './tmp-schema.mjs'
|
|
2
|
+
import { packageDefaults } from './package-defaults.mjs'
|
|
2
3
|
const PROTOCOL_ALIASES = {
|
|
3
4
|
http: 'http',
|
|
4
5
|
https: 'https',
|
|
@@ -26,7 +27,7 @@ export function summarizeLoaders(tmp = {}) {
|
|
|
26
27
|
const service = configs.service ?? readTmpServiceBlock(configs)
|
|
27
28
|
|
|
28
29
|
return {
|
|
29
|
-
framework: service.framework ??
|
|
30
|
+
framework: service.framework ?? packageDefaults.framework,
|
|
30
31
|
protocols: resolveProtocolsFromConfig(service),
|
|
31
32
|
service: service.name,
|
|
32
33
|
items: [
|
|
@@ -43,7 +43,7 @@ export function assertCoreTmpGuard(projectRoot, tmpFilePath) {
|
|
|
43
43
|
const canonical = coreCanonicalTmpPath(projectRoot)
|
|
44
44
|
if (path.resolve(tmpFilePath) !== path.resolve(canonical)) {
|
|
45
45
|
throw new Error(
|
|
46
|
-
|
|
46
|
+
`${packageDefaults.packageName}: tmp.yml must stay at ${packageDefaults.packageRootFolder}/tmp.yml (expected ${canonical}, got ${tmpFilePath})`,
|
|
47
47
|
)
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -58,7 +58,7 @@ function findStrayCoreTmpFiles(projectRoot, canonicalPath) {
|
|
|
58
58
|
export function ensureCoreTmpEntry(projectRoot = process.cwd(), options = {}) {
|
|
59
59
|
const resolvedRoot = path.resolve(projectRoot)
|
|
60
60
|
if (!isCorePackageRoot(resolvedRoot)) {
|
|
61
|
-
throw new Error(
|
|
61
|
+
throw new Error(`ensureCoreTmpEntry is only for ${packageDefaults.packageName} package root`)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
const canonical = coreCanonicalTmpPath(resolvedRoot)
|
|
@@ -66,7 +66,7 @@ export function ensureCoreTmpEntry(projectRoot = process.cwd(), options = {}) {
|
|
|
66
66
|
if (strays.length > 0) {
|
|
67
67
|
const rel = strays.map((p) => path.relative(resolvedRoot, p)).join(', ')
|
|
68
68
|
throw new Error(
|
|
69
|
-
|
|
69
|
+
`${packageDefaults.packageName}: tmp.yml must only exist under ${packageDefaults.packageRootFolder}/. Remove extra copies: ${rel}`,
|
|
70
70
|
)
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -207,7 +207,7 @@ export function ensureTmpFile(projectRoot = process.cwd(), { patchServiceName =
|
|
|
207
207
|
if (strays.length > 0) {
|
|
208
208
|
const rel = strays.map((p) => path.relative(resolvedRoot, p)).join(', ')
|
|
209
209
|
throw new Error(
|
|
210
|
-
|
|
210
|
+
`${packageDefaults.packageName}: tmp.yml must only exist under ${packageDefaults.packageRootFolder}/. Remove extra copies: ${rel}`,
|
|
211
211
|
)
|
|
212
212
|
}
|
|
213
213
|
|
|
@@ -237,7 +237,7 @@ export function ensureTmpFile(projectRoot = process.cwd(), { patchServiceName =
|
|
|
237
237
|
|
|
238
238
|
const templatePath = getBundledCoreTmpPath()
|
|
239
239
|
if (!fs.existsSync(templatePath)) {
|
|
240
|
-
throw new Error(
|
|
240
|
+
throw new Error(`${packageDefaults.packageName} bundled ${packageDefaults.packageRootFolder}/tmp.yml not found in package`)
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
const layout = buildTmpLayout(resolvedRoot, null, null)
|
|
@@ -33,7 +33,7 @@ export function resolveToolchainPaths(options = {}) {
|
|
|
33
33
|
outDir: `./${rootFolder}/${distSegment}`,
|
|
34
34
|
include: [mainFolder],
|
|
35
35
|
exclude: [`${rootFolder}/${testsSegment}`],
|
|
36
|
-
pathAliasKey: packageDefaults.pathAliasKey
|
|
36
|
+
pathAliasKey: packageDefaults.pathAliasKey,
|
|
37
37
|
pathAliasTarget: [`${mainFolder}/*`],
|
|
38
38
|
eslintFiles: [`${mainFolder}/**/*.ts`, `${mainFolder}/**/*.tsx`],
|
|
39
39
|
eslintIgnores: [
|
|
@@ -74,7 +74,7 @@ export function resolveRecommendedTsconfigFromProject(root = process.cwd()) {
|
|
|
74
74
|
export function resolveTsconfigExtends(root) {
|
|
75
75
|
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
|
|
76
76
|
if (pkg.name === packageDefaults.packageName) return './tsconfig.base.json'
|
|
77
|
-
return
|
|
77
|
+
return `${packageDefaults.packageName}/tsconfig.base.json`
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
export function mergeTsconfigWithLayout(recommended, existing = {}, extendsPath) {
|
package/x/bin/main-cli.js
CHANGED
|
@@ -51,7 +51,7 @@ const cli = new Command()
|
|
|
51
51
|
cli
|
|
52
52
|
.name(cliName)
|
|
53
53
|
.description('xrystal core — microservice runtime library')
|
|
54
|
-
.version(pkg.version, '-V, --version',
|
|
54
|
+
.version(pkg.version, '-V, --version', `Show ${pkg.name} CLI version`)
|
|
55
55
|
.configureHelp({
|
|
56
56
|
helpWidth: () => Math.min(100, Math.max(56, process.stdout.columns || 80)),
|
|
57
57
|
sortSubcommands: true,
|
|
@@ -5,9 +5,10 @@ import { fileURLToPath } from 'node:url'
|
|
|
5
5
|
|
|
6
6
|
import { resolveProjectRoot } from '../helpers/project-root.mjs'
|
|
7
7
|
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
8
|
+
import { packageDefaults } from '../helpers/package-defaults.mjs'
|
|
8
9
|
|
|
9
10
|
const verifyScriptPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'verify-version-bump.mjs')
|
|
10
|
-
const HOOK_MARKER =
|
|
11
|
+
const HOOK_MARKER = `${packageDefaults.packageName} version-bump pre-commit`
|
|
11
12
|
|
|
12
13
|
export function resolveVerifyScriptPath() {
|
|
13
14
|
return verifyScriptPath
|
|
@@ -34,12 +34,12 @@ export function isCorePackageProject(root) {
|
|
|
34
34
|
export function runReleasePrepare({ root = resolveProjectRoot(), dryRun = false, skipPrepare = false } = {}) {
|
|
35
35
|
if (skipPrepare || !isCorePackageProject(root)) {
|
|
36
36
|
if (!skipPrepare && !isCorePackageProject(root)) {
|
|
37
|
-
console.log(
|
|
37
|
+
console.log(`\nRelease prepare skipped (not ${packageDefaults.packageName}).\n`)
|
|
38
38
|
}
|
|
39
39
|
return { skipped: true }
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
console.log(
|
|
42
|
+
console.log(`\nRelease prepare (${packageDefaults.packageName}):\n`)
|
|
43
43
|
console.log(' (npm publish CI converts source → .js; git keeps TypeScript)\n')
|
|
44
44
|
|
|
45
45
|
for (const step of PREPARE_STEPS) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import defaults from './defaults.json';
|
|
2
2
|
export type PackageDefaults = typeof defaults & {
|
|
3
3
|
mainSourceFolder: string;
|
|
4
|
+
framework: string;
|
|
4
5
|
layoutPaths: {
|
|
5
6
|
tests: string;
|
|
6
7
|
environments: string;
|
|
@@ -22,7 +23,6 @@ export declare class Constants {
|
|
|
22
23
|
static readonly cliName: string;
|
|
23
24
|
static readonly cliBinNames: string[] & readonly string[];
|
|
24
25
|
static readonly pathAliasKey: string;
|
|
25
|
-
/** From bundled x/tmp.yml — used only when project tmp.yml omits paths */
|
|
26
26
|
static readonly mainSourceFolder: string;
|
|
27
27
|
static readonly layoutPaths: {
|
|
28
28
|
tests: string;
|
|
@@ -31,5 +31,4 @@ export declare class Constants {
|
|
|
31
31
|
};
|
|
32
32
|
static readonly bundledCoreTmpPath: string;
|
|
33
33
|
}
|
|
34
|
-
/** Stable public re-exports — implementation lives in helpers/tmp. */
|
|
35
34
|
export { seedFromTmp, loadSeedFromBundledTmp } from '../../utils/helpers/tmp/seed-from-tmp';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import n from"node:path";import{packageRootDir as q}from"../../utils/package-root";import b from"./defaults.json" with { type: 'json' };import{seedFromTmp as j}from"../../utils/helpers/tmp/seed-from-tmp";export const packageDefaults=Object.freeze({...b,mainSourceFolder:j.sourceFolder,layoutPaths:Object.freeze({...j.layout}),buildDefaults:Object.freeze({...b.buildDefaults}),tmpWatchDefaults:Object.freeze({...b.tmpWatchDefaults}),cliBinNames:Object.freeze([...b.cliBinNames??[b.cliName]])}),coreVersionPattern=/^\d{2}\.\d{2}\.\d{2}-v\d+$/,semverVersionPattern=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/;const v=`${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;export class Constants{static packageName=packageDefaults.packageName;static packageRootFolder=packageDefaults.packageRootFolder;static tmpBaseName=packageDefaults.tmpBaseName;static tmpExtension=packageDefaults.tmpExtension;static publicFolderName=packageDefaults.publicFolderName;static kafkaLogsTopic=packageDefaults.kafkaLogsTopic;static templateRepoUri=packageDefaults.templateRepoUri;static cliName=packageDefaults.cliName;static cliBinNames=packageDefaults.cliBinNames;static pathAliasKey=packageDefaults.pathAliasKey;static mainSourceFolder=packageDefaults.mainSourceFolder;static layoutPaths=packageDefaults.layoutPaths;static bundledCoreTmpPath=n.join(q,packageDefaults.packageRootFolder,v)}export{seedFromTmp,loadSeedFromBundledTmp}from"../../utils/helpers/tmp/seed-from-tmp";
|
|
1
|
+
import n from"node:path";import{packageRootDir as q}from"../../utils/package-root";import b from"./defaults.json" with { type: 'json' };import{seedFromTmp as j}from"../../utils/helpers/tmp/seed-from-tmp";export const packageDefaults=Object.freeze({...b,mainSourceFolder:j.sourceFolder,framework:j.framework,layoutPaths:Object.freeze({...j.layout}),buildDefaults:Object.freeze({...b.buildDefaults}),tmpWatchDefaults:Object.freeze({...b.tmpWatchDefaults}),cliBinNames:Object.freeze([...b.cliBinNames??[b.cliName]])}),coreVersionPattern=/^\d{2}\.\d{2}\.\d{2}-v\d+$/,semverVersionPattern=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/;const v=`${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;export class Constants{static packageName=packageDefaults.packageName;static packageRootFolder=packageDefaults.packageRootFolder;static tmpBaseName=packageDefaults.tmpBaseName;static tmpExtension=packageDefaults.tmpExtension;static publicFolderName=packageDefaults.publicFolderName;static kafkaLogsTopic=packageDefaults.kafkaLogsTopic;static templateRepoUri=packageDefaults.templateRepoUri;static cliName=packageDefaults.cliName;static cliBinNames=packageDefaults.cliBinNames;static pathAliasKey=packageDefaults.pathAliasKey;static mainSourceFolder=packageDefaults.mainSourceFolder;static layoutPaths=packageDefaults.layoutPaths;static bundledCoreTmpPath=n.join(q,packageDefaults.packageRootFolder,v)}export{seedFromTmp,loadSeedFromBundledTmp}from"../../utils/helpers/tmp/seed-from-tmp";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import U from"node:fs";import
|
|
1
|
+
import U from"node:fs";import J from"node:path";import z from"yaml";import{Constants as I}from"../../../utils/constants";import{findAllFilesRecursively as L,findFileRecursively as A}from"../../../utils/helpers/core/paths";import{normalizeTmpDocument as D,readTmpServiceBlock as B,normalizeRootFolder as b,normalizeSourceFolder as x,resolveServiceLayoutPaths as k}from"../../../utils/helpers/tmp/tmp-schema";function M(E,q){return`${E}${q.startsWith(".")?q:`.${q}`}`}export function coreCanonicalTmpPath(E=process.cwd()){return J.join(J.resolve(E),I.packageRootFolder,M(I.tmpBaseName,I.tmpExtension))}export function assertCoreTmpGuard(E,q){if(!isCorePackageRoot(E))return;const H=coreCanonicalTmpPath(E);if(J.resolve(q)!==J.resolve(H))throw Error(`${I.packageName}: tmp.yml must stay at ${I.packageRootFolder}/tmp.yml (expected ${H}, got ${q})`)}function N(E,q){const H=J.resolve(E),K=J.resolve(q);return L(H,I.tmpBaseName,I.tmpExtension).filter((Q)=>J.resolve(Q)!==K)}export function ensureCoreTmpEntry(E=process.cwd(),q={}){const H=J.resolve(E);if(!isCorePackageRoot(H))throw Error(`ensureCoreTmpEntry is only for ${I.packageName} package root`);const K=coreCanonicalTmpPath(H),Q=N(H,K);if(Q.length>0){const X=Q.map((W)=>J.relative(H,W)).join(", ");throw Error(`${I.packageName}: tmp.yml must only exist under ${I.packageRootFolder}/. Remove extra copies: ${X}`)}if(U.existsSync(K)){assertCoreTmpGuard(H,K);return{tmpFilePath:K,created:!1,layout:buildTmpLayout(H,_(K),K)}}return ensureTmpFile(H,{...q,patchServiceName:!1})}function S(E,q,H){const K=J.resolve(E);if(isCorePackageRoot(K)){const Q=coreCanonicalTmpPath(K);return U.existsSync(Q)?Q:null}return A(K,q,H)}function _(E){return z.parse(U.readFileSync(E,"utf8"))}export function isCorePackageRoot(E){const q=J.join(J.resolve(E),"package.json");if(!U.existsSync(q))return!1;try{return JSON.parse(U.readFileSync(q,"utf8")).name===I.packageName}catch{return!1}}export function resolveRootFolderPath(E,q,H){const K=D(E).configs,Q=B(K);if(Q.paths?.root?.trim())return b(Q.paths.root);const X=E.project;if(typeof X?.name==="string"&&X.name.trim())return X.name.trim();const W=J.relative(J.resolve(H),J.dirname(J.resolve(q)));if(W&&W!==".")return W;return I.packageRootFolder}export function resolveLayoutPaths(E){const q=B(E);return k(q)}export function resolveMainFolderPath(E){const q=B(E);if(q.paths?.source?.trim())return x(q.paths.source);return I.mainSourceFolder}export function buildTmpLayout(E,q,H){const K=J.resolve(E),Q=q?D(q).configs:void 0,X=q&&H&&!isCorePackageRoot(K)?resolveRootFolderPath(q,H,K):I.packageRootFolder,W=J.join(K,X),Y=resolveLayoutPaths(Q),V=resolveMainFolderPath(Q),Z={tests:J.join(W,Y.tests),environments:J.join(W,Y.environments),dist:J.join(W,Y.dist)};return{projectRoot:K,rootFolderPath:X,rootFolderAbs:W,tmpFilePath:H,mainFolderPath:V,paths:Y,pathsAbs:Z}}export function resolveTmpLayout(E=process.cwd(),q={}){const H=q.tmpFileName??I.tmpBaseName,K=q.ext??I.tmpExtension,Q=S(E,H,K);if(!Q)throw Error(`${M(H,K)} not found under ${J.resolve(E)}`);if(isCorePackageRoot(J.resolve(E)))assertCoreTmpGuard(E,Q);return buildTmpLayout(E,_(Q),Q)}export function resolveTmpLayoutOrDefaults(E=process.cwd()){const q=S(E,I.tmpBaseName,I.tmpExtension);if(!q)return buildTmpLayout(E,null,null);return buildTmpLayout(E,_(q),q)}export function resolveBundledCoreTmpPath(E=process.cwd()){if(U.existsSync(I.bundledCoreTmpPath))return I.bundledCoreTmpPath;let q=J.resolve(E);while(q!==J.dirname(q)){const H=J.join(q,"node_modules","@xrystal","core",I.packageRootFolder,M(I.tmpBaseName,I.tmpExtension));if(U.existsSync(H))return H;const K=J.join(q,"package.json");if(U.existsSync(K)){if(JSON.parse(U.readFileSync(K,"utf8")).name===I.packageName){const X=J.join(q,I.packageRootFolder,M(I.tmpBaseName,I.tmpExtension));if(U.existsSync(X))return X}}q=J.dirname(q)}throw Error(`${I.packageName} bundled ${I.packageRootFolder}/tmp.yml not found`)}export function ownerTmpFilePath(E=process.cwd(),q){const H=q??resolveTmpLayoutOrDefaults(E);return J.join(H.rootFolderAbs,M(I.tmpBaseName,I.tmpExtension))}export function ensureTmpFile(E=process.cwd(),q={}){const H=J.resolve(E),K=q.patchServiceName??!0;if(isCorePackageRoot(H)){const V=coreCanonicalTmpPath(H),Z=N(H,V);if(Z.length>0){const $=Z.map((w)=>J.relative(H,w)).join(", ");throw Error(`${I.packageName}: tmp.yml must only exist under ${I.packageRootFolder}/. Remove extra copies: ${$}`)}if(U.existsSync(V)){assertCoreTmpGuard(H,V);return{tmpFilePath:V,created:!1,layout:buildTmpLayout(H,_(V),V)}}}else{const V=A(H,I.tmpBaseName,I.tmpExtension);if(V)return{tmpFilePath:V,created:!1,layout:buildTmpLayout(H,_(V),V)}}const Q=q.templatePath??resolveBundledCoreTmpPath(H);if(!U.existsSync(Q))throw Error(`${I.packageName} bundled ${I.packageRootFolder}/tmp.yml not found`);const X=buildTmpLayout(H,null,null);U.mkdirSync(X.rootFolderAbs,{recursive:!0});const W=ownerTmpFilePath(H,X);let Y=U.readFileSync(Q,"utf8");if(K)try{const V=J.join(H,"package.json");if(U.existsSync(V)){const Z=JSON.parse(U.readFileSync(V,"utf8")),$=typeof Z.name==="string"?Z.name.replace(/^@/,"").replace(/\//g,"-"):null;if($){const w=z.parse(Y),G=w.configs??{},O=G.service;if(typeof O==="object"&&O!==null&&!Array.isArray(O))O.name=$;else G.service={name:$};w.configs=G;Y=z.stringify(w)}}}catch{}U.writeFileSync(W,Y);return{tmpFilePath:W,created:!0,layout:buildTmpLayout(H,_(W),W)}}export function resolveTmpLayoutEnsured(E=process.cwd()){return ensureTmpFile(E).layout}
|
|
@@ -4,4 +4,4 @@ export { bindLoaderTmpSync, type ITmpSyncLoader, } from '../../../utils/helpers/
|
|
|
4
4
|
export { resolveTmpWatchIntervalMs } from '../../../utils/helpers/tmp/tmp-watch';
|
|
5
5
|
export { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, readTmpCoreBlock, readTmpServiceBlock, resolveServiceLayoutPaths, resolveTmpRuntimeConfigs, } from '../../../utils/helpers/tmp/tmp-schema';
|
|
6
6
|
export { loadSeedFromBundledTmp, seedFromTmp, type SeedFromTmp, type SeedLayoutPaths, } from '../../../utils/helpers/tmp/seed-from-tmp';
|
|
7
|
-
export {
|
|
7
|
+
export { normalizeLayoutPaths, type LayoutPaths, } from '../../../utils/helpers/tmp/path-normalize';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{setRuntimeTmpConfigs,getRuntimeTmpConfigs,onRuntimeTmpChange,notifyRuntimeTmpChange,clearRuntimeTmpConfigs}from"../../../utils/helpers/tmp/runtime-tmp";export{getTmpLoader,getTmpLoaderPath,getTmpSnapshot,onTmpReload,resetTmpLoaderForTests,stopTmpLoader}from"../../../utils/helpers/tmp/tmp-loader";export{bindLoaderTmpSync}from"../../../utils/helpers/tmp/loader-tmp-sync";export{resolveTmpWatchIntervalMs}from"../../../utils/helpers/tmp/tmp-watch";export{normalizeTmpDocument,normalizeRootFolder,normalizeSourceFolder,readTmpCoreBlock,readTmpServiceBlock,resolveServiceLayoutPaths,resolveTmpRuntimeConfigs}from"../../../utils/helpers/tmp/tmp-schema";export{loadSeedFromBundledTmp,seedFromTmp}from"../../../utils/helpers/tmp/seed-from-tmp";export{
|
|
1
|
+
export{setRuntimeTmpConfigs,getRuntimeTmpConfigs,onRuntimeTmpChange,notifyRuntimeTmpChange,clearRuntimeTmpConfigs}from"../../../utils/helpers/tmp/runtime-tmp";export{getTmpLoader,getTmpLoaderPath,getTmpSnapshot,onTmpReload,resetTmpLoaderForTests,stopTmpLoader}from"../../../utils/helpers/tmp/tmp-loader";export{bindLoaderTmpSync}from"../../../utils/helpers/tmp/loader-tmp-sync";export{resolveTmpWatchIntervalMs}from"../../../utils/helpers/tmp/tmp-watch";export{normalizeTmpDocument,normalizeRootFolder,normalizeSourceFolder,readTmpCoreBlock,readTmpServiceBlock,resolveServiceLayoutPaths,resolveTmpRuntimeConfigs}from"../../../utils/helpers/tmp/tmp-schema";export{loadSeedFromBundledTmp,seedFromTmp}from"../../../utils/helpers/tmp/seed-from-tmp";export{normalizeLayoutPaths}from"../../../utils/helpers/tmp/path-normalize";
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
/** Pure path normalizers — no Constants / no I/O (shared by seed + schema). */
|
|
2
1
|
export type LayoutPaths = {
|
|
3
2
|
tests: string;
|
|
4
3
|
environments: string;
|
|
5
4
|
dist: string;
|
|
6
5
|
};
|
|
7
|
-
export declare
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function normalizeLayoutPaths(special: unknown, fallback?: LayoutPaths): LayoutPaths;
|
|
6
|
+
export declare function normalizeRootFolder(value: unknown, fallback: string): string;
|
|
7
|
+
export declare function normalizeSourceFolder(value: unknown, fallback: string): string;
|
|
8
|
+
export declare function normalizeLayoutPaths(special: unknown, fallback: LayoutPaths): LayoutPaths;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export function normalizeRootFolder(t,n){if(typeof t!=="string"||!t.trim())return n;return t.trim().replace(/^\.\/+/,"")}export function normalizeSourceFolder(t,n){if(typeof t!=="string"||!t.trim())return n;const r=t.trim();if(r.startsWith("./")||r.startsWith("../"))return r;return`./${r}`}export function normalizeLayoutPaths(t,n){const r=t&&typeof t==="object"&&!Array.isArray(t)?t:{},o=(e)=>{const i=r[e];return typeof i==="string"&&i.trim()?i.trim():n[e]};return{tests:o("tests"),environments:o("environments"),dist:o("dist")}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import K from"node:fs";import J from"node:path";import{fileURLToPath as V}from"node:url";import W from"yaml";import D from"../../../utils/constants/defaults.json" with { type: 'json' };import{normalizeRootFolder as X,normalizeSourceFolder as Y}from"../../../utils/helpers/tmp/path-normalize";const O=J.dirname(V(import.meta.url)),Q=`${D.tmpBaseName}${D.tmpExtension}`;function I(j,A){if(typeof j!=="string"||!j.trim())throw Error(`${D.packageName}: bundled tmp.yml missing ${A}`);return j.trim()}function Z(j){const A=j&&typeof j==="object"&&!Array.isArray(j)?j:{};return{tests:I(A.tests,"configs.service.paths.special.tests"),environments:I(A.environments,"configs.service.paths.special.environments"),dist:I(A.dist,"configs.service.paths.special.dist")}}function _(j){if(j){if(!K.existsSync(j))throw Error(`${D.packageName}: bundled tmp.yml missing at ${j}`);return j}const A=[O,process.cwd()];for(const H of A){let C=J.resolve(H);for(;;){const E=J.join(C,D.packageRootFolder,Q);if(K.existsSync(E))return E;const G=J.dirname(C);if(G===C)break;C=G}}throw Error(`${D.packageName}: bundled ${D.packageRootFolder}/${Q} not found from ${O}`)}export function loadSeedFromBundledTmp(j){const A=_(j),H=W.parse(K.readFileSync(A,"utf8")),C=H?.configs&&typeof H.configs==="object"?H.configs:{},E=C.service&&typeof C.service==="object"?C.service:{},G=E.paths&&typeof E.paths==="object"?E.paths:{},M=I(G.source,"configs.service.paths.source");return{rootFolder:X(G.root,D.packageRootFolder),sourceFolder:Y(M,M),framework:I(E.framework,"configs.service.framework"),layout:Z(G.special)}}export const seedFromTmp=loadSeedFromBundledTmp();
|
|
@@ -35,14 +35,10 @@ export type TmpRuntimeConfigs = {
|
|
|
35
35
|
core: TmpCoreBlock;
|
|
36
36
|
rootFolderPath: string;
|
|
37
37
|
};
|
|
38
|
-
/** `paths.root` → folder name under project root (`x`, `infra`). */
|
|
39
38
|
export declare function normalizeRootFolder(value?: string): string;
|
|
40
|
-
/** `paths.source` → dev/build source folder (`./source`, `./src`). */
|
|
41
39
|
export declare function normalizeSourceFolder(value?: string): string;
|
|
42
40
|
export declare function readTmpCoreBlock(configs?: Record<string, unknown>): TmpCoreBlock;
|
|
43
41
|
export declare function readTmpServiceBlock(configs?: Record<string, unknown>): TmpServiceBlock;
|
|
44
|
-
/** Project layout from tmp.yml; omitted specials → bootstrap layout (same as bundled x/tmp.yml). */
|
|
45
42
|
export declare function resolveServiceLayoutPaths(service: TmpServiceBlock): TmpLayoutPathsFlat;
|
|
46
|
-
/** Canonical tmp.yml shape — `service` + `core` + derived `rootFolderPath`. */
|
|
47
43
|
export declare function resolveTmpRuntimeConfigs(tmp?: Record<string, unknown> | null): TmpRuntimeConfigs;
|
|
48
44
|
export declare function normalizeTmpDocument(tmp: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import K from"../../../utils/constants/defaults.json" with { type: 'json' };import{seedFromTmp as G}from"../../../utils/helpers/tmp/seed-from-tmp";import{normalizeLayoutPaths as O,normalizeRootFolder as Q,normalizeSourceFolder as U}from"../../../utils/helpers/tmp/path-normalize";function A(j){return typeof j==="object"&&j!==null&&!Array.isArray(j)}function X(j){if(typeof j==="number"||typeof j==="string")return j;return}export function normalizeRootFolder(j){return Q(j,K.packageRootFolder)}export function normalizeSourceFolder(j){return U(j,G.sourceFolder)}export function readTmpCoreBlock(j){const q=A(j?.core)?j.core:{},x=A(q.tmp)?q.tmp:{};return{tmp:{fileWatchIntervalMs:X(x.fileWatchIntervalMs)}}}export function readTmpServiceBlock(j){const q=A(j?.service)?j.service:{},x=A(q.paths)?q.paths:{},D=A(x.special)?x.special:{};let E=A(q.loaders)?{...q.loaders}:void 0,H=A(q.build)?q.build:void 0;if(E&&A(E.build)){const{build:J,...M}=E;E=M;if(!H&&A(J))H=J}return{name:typeof q.name==="string"?q.name:void 0,framework:typeof q.framework==="string"?q.framework:void 0,paths:{root:typeof x.root==="string"?x.root:void 0,source:typeof x.source==="string"?x.source:void 0,special:{tests:typeof D.tests==="string"?D.tests:void 0,environments:typeof D.environments==="string"?D.environments:void 0,dist:typeof D.dist==="string"?D.dist:void 0}},protocols:q.protocols,loaders:E,build:H}}export function resolveServiceLayoutPaths(j){return O(j.paths?.special,G.layout)}function Y(j){const q=resolveServiceLayoutPaths(j);return{name:j.name,framework:j.framework??G.framework,paths:{root:j.paths?.root??K.packageRootFolder,source:j.paths?.source??G.sourceFolder,special:q},protocols:j.protocols,loaders:j.loaders,build:j.build}}function Z(j){return{tmp:{fileWatchIntervalMs:j.tmp?.fileWatchIntervalMs}}}export function resolveTmpRuntimeConfigs(j){const q=A(j?.configs)?j.configs:{},x=readTmpServiceBlock(q),D=readTmpCoreBlock(q),E=Y(x);return{service:E,core:Z(D),rootFolderPath:normalizeRootFolder(E.paths.root)}}export function normalizeTmpDocument(j){return{...j,configs:resolveTmpRuntimeConfigs(j)}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __filename="/home/runner/work/-xrystal-core/-xrystal-core/x/dist/utils/models/classes/class.x.js";import{createContainer as
|
|
1
|
+
var __filename="/home/runner/work/-xrystal-core/-xrystal-core/x/dist/utils/models/classes/class.x.js";import{createContainer as V,asClass as K,asValue as j,InjectionMode as N,listModules as X,Lifetime as Z}from"awilix";import R from"node:path";import{pathToFileURL as x}from"node:url";import C from"../../../utils/constants/defaults.json" with { type: 'json' };export const xSymbol=Symbol.for(`${C.packageName}/di-container`);class T{checkRegistration(q,A){return!!q.registrations[A]}}class U extends T{container;initializedNames=new Set;loadedPaths=new Set;registeredClasses=new Set;isInitializing=!1;constructor(){super();this.container=V({injectionMode:N.PROXY,strict:!0})}getName(q){if(typeof q==="string")return q.charAt(0).toLowerCase()+q.slice(1);if(typeof q==="function"&&q.name)return q.name.charAt(0).toLowerCase()+q.name.slice(1);return""}async load(q,A={}){const{verbose:H=!1,exclude:$=[],lifetime:E=Z.SINGLETON}=A,B=process.cwd(),G=(Array.isArray(q)?q:[q]).map((Q)=>{return(R.isAbsolute(Q)?Q:R.resolve(B,Q)).replace(/\\/g,"/").toLowerCase()});let O=[];try{O=X(G)}catch(Q){return this}for(const Q of O){const Y=Q.path.replace(/\\/g,"/").toLowerCase();if(this.loadedPaths.has(Y))continue;if(Y===__filename.replace(/\\/g,"/").toLowerCase()||Y.endsWith(".d.ts"))continue;try{const F=await import(x(Q.path).href);let J=F.default;if(!J)J=Object.values(F).find((W)=>typeof W==="function"&&!!W.prototype&&!!W.name);if(typeof J==="function"&&!!J.prototype&&!!J.name){if(this.registeredClasses.has(J))continue;const W=this.getName(J);if(W&&!this.checkRegistration(this.container,W)){this.container.register({[W]:K(J).setLifetime(E)});this.loadedPaths.add(Y);this.registeredClasses.add(J)}}}catch(w){if(H)console.error("[DI] Load Error:",w.message)}}return this}register(q,A=Z.SINGLETON){const H=this.getName(q);if(!H||this.registeredClasses.has(q))return this;if(this.checkRegistration(this.container,H))return this;this.container.register({[H]:K(q).setLifetime(A)});this.registeredClasses.add(q);return this}registerInstance(q,A){if(!q)return this;const H=this.getName(q);this.container.register({[H]:j(A)});return this}async initialize(q,A=!1){if(this.isInitializing)return this;this.isInitializing=!0;try{const H=q?Array.isArray(q)?q:[q]:[];for(const E of H){const B=this.getName(E.service);if(!B||this.initializedNames.has(B))continue;const G=this.container.registrations[B];if(!G||G.lifetime!==Z.SINGLETON)continue;try{const O=this.container.cradle[B];if(O&&typeof O.onInit==="function")await O.onInit(E.props||{});this.initializedNames.add(B)}catch(O){if(A)console.error(`[DI] Priority onInit Failed (${B}):`,O.message)}}const $=Object.keys(this.container.registrations);for(const E of $){if(this.initializedNames.has(E))continue;if(this.container.registrations[E].lifetime!==Z.SINGLETON)continue;try{const G=this.container.cradle[E];if(G&&typeof G.onInit==="function")await G.onInit({});this.initializedNames.add(E)}catch(G){if(A)console.error(`[DI] Auto onInit Failed (${E}):`,G.message)}}for(const E of this.initializedNames)try{const B=this.container.cradle[E];if(B&&typeof B.onAfterInit==="function")await B.onAfterInit()}catch(B){if(A)console.error(`[DI] onAfterInit Failed (${E}):`,B.message)}}finally{this.isInitializing=!1}return this}get(q){const A=this.getName(q);return this.container.resolve(A)}async shutdown(){for(const q of this.initializedNames)try{const A=this.container.cradle[q];if(A&&typeof A.onDispose==="function")await A.onDispose()}catch(A){console.error(`[DI] onDispose Failed (${q})`)}await this.container.dispose()}get cradle(){return this.container.cradle}}const _=globalThis;if(!_[xSymbol])_[xSymbol]=new U;export default _[xSymbol];
|