@xrystal/core 3.28.3 → 3.37.3
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 +2331 -21
- package/package.json +66 -24
- package/tsconfig.base.json +15 -0
- package/x/bin/commands/create.mjs +136 -0
- package/x/bin/commands/doctor.mjs +149 -0
- package/x/bin/commands/hooks.mjs +55 -0
- package/x/bin/commands/project.mjs +126 -0
- package/x/bin/commands/release.mjs +66 -0
- package/x/bin/commands/sync-toolchain.mjs +43 -0
- package/x/bin/commands/tmp.mjs +57 -0
- package/x/bin/constants/index.mjs +6 -0
- package/x/bin/helpers/.generated/.generated-from +1 -0
- package/x/bin/helpers/.generated/tmp-schema.mjs +192 -0
- package/x/bin/helpers/banner.mjs +80 -0
- package/x/bin/helpers/build-config.mjs +342 -0
- package/x/bin/helpers/cli-help.mjs +164 -0
- package/x/bin/helpers/cli-identity.mjs +17 -0
- package/x/bin/helpers/create-target.mjs +35 -0
- package/{bin → x/bin}/helpers/index.mjs +44 -1
- package/x/bin/helpers/project-artifacts.mjs +140 -0
- package/x/bin/helpers/project-root.mjs +70 -0
- package/x/bin/helpers/runtime-info.mjs +172 -0
- package/x/bin/helpers/tmp-config.mjs +67 -0
- package/x/bin/helpers/tmp-layout.mjs +281 -0
- package/x/bin/helpers/tmp-schema.mjs +9 -0
- package/x/bin/helpers/toolchain-config.mjs +233 -0
- package/x/bin/main-cli.js +80 -0
- package/x/bin/paths.mjs +14 -0
- package/x/bin/scripts/clean-source-types.mjs +19 -0
- package/x/bin/scripts/fix-dist-imports.mjs +80 -0
- package/x/bin/scripts/install-git-hooks.mjs +86 -0
- package/x/bin/scripts/minify-dist.mjs +50 -0
- package/x/bin/scripts/prepare-npm-publish.mjs +49 -0
- package/x/bin/scripts/release-prepare.mjs +56 -0
- package/x/bin/scripts/tag.mjs +17 -0
- package/x/bin/scripts/unpublish-leaked-versions.mjs +62 -0
- package/x/bin/scripts/verify-npm-pack.mjs +45 -0
- package/x/bin/scripts/verify-version-bump.mjs +27 -0
- package/x/bin/scripts/version-check.mjs +370 -0
- package/x/dist/index.d.ts +3 -0
- package/x/dist/index.js +1 -0
- package/{source → x/dist}/loader/clients/index.d.ts +2 -1
- package/x/dist/loader/clients/index.js +1 -0
- package/{source → x/dist}/loader/configs/index.d.ts +3 -2
- package/x/dist/loader/configs/index.js +1 -0
- package/x/dist/loader/controller/index.d.ts +69 -0
- package/x/dist/loader/controller/index.js +1 -0
- package/x/dist/loader/dto/index.d.ts +39 -0
- package/x/dist/loader/dto/index.js +1 -0
- package/{source → x/dist}/loader/events/index.d.ts +1 -1
- package/x/dist/loader/events/index.js +1 -0
- package/{source → x/dist}/loader/index.d.ts +2 -1
- package/x/dist/loader/index.js +1 -0
- package/{source → x/dist}/loader/kafka/index.d.ts +6 -3
- package/x/dist/loader/kafka/index.js +1 -0
- package/{source → x/dist}/loader/localizations/index.d.ts +4 -3
- package/x/dist/loader/localizations/index.js +1 -0
- package/{source → x/dist}/loader/logger/index.d.ts +10 -7
- package/x/dist/loader/logger/index.js +2 -0
- package/x/dist/loader/service/index.js +1 -0
- package/{source → x/dist}/loader/system/index.d.ts +4 -3
- package/x/dist/loader/system/index.js +1 -0
- package/{source → x/dist}/project/index.d.ts +2 -2
- package/x/dist/project/index.js +1 -0
- package/x/dist/utils/constants/defaults.json +44 -0
- package/x/dist/utils/constants/index.d.ts +27 -0
- package/x/dist/utils/constants/index.js +1 -0
- package/x/dist/utils/helpers/configs/index.js +1 -0
- package/x/dist/utils/helpers/context/controller-store.d.ts +51 -0
- package/x/dist/utils/helpers/context/controller-store.js +1 -0
- package/x/dist/utils/helpers/context/index.d.ts +18 -0
- package/x/dist/utils/helpers/context/index.js +1 -0
- package/{source → x/dist}/utils/helpers/core/index.d.ts +8 -6
- package/x/dist/utils/helpers/core/index.js +1 -0
- package/x/dist/utils/helpers/core/paths.d.ts +2 -0
- package/x/dist/utils/helpers/core/paths.js +1 -0
- package/x/dist/utils/helpers/core/tmp-layout.d.ts +45 -0
- package/x/dist/utils/helpers/core/tmp-layout.js +1 -0
- package/{source → x/dist}/utils/helpers/date/index.d.ts +1 -1
- package/x/dist/utils/helpers/date/index.js +1 -0
- package/x/dist/utils/helpers/dispatch/index.d.ts +9 -0
- package/x/dist/utils/helpers/dispatch/index.js +1 -0
- package/x/dist/utils/helpers/dto/index.d.ts +10 -0
- package/x/dist/utils/helpers/dto/index.js +1 -0
- package/x/dist/utils/helpers/filters/index.js +1 -0
- package/x/dist/utils/helpers/framework/index.d.ts +3 -0
- package/x/dist/utils/helpers/framework/index.js +1 -0
- package/x/dist/utils/helpers/handlers/adapters.d.ts +10 -0
- package/x/dist/utils/helpers/handlers/adapters.js +1 -0
- package/x/dist/utils/helpers/handlers/execute.d.ts +5 -0
- package/x/dist/utils/helpers/handlers/execute.js +1 -0
- package/x/dist/utils/helpers/handlers/index.d.ts +18 -0
- package/x/dist/utils/helpers/handlers/index.js +1 -0
- package/x/dist/utils/helpers/hash/crypto.js +1 -0
- package/x/dist/utils/helpers/id/index.js +1 -0
- package/x/dist/utils/helpers/index.d.ts +26 -0
- package/x/dist/utils/helpers/index.js +1 -0
- package/x/dist/utils/helpers/ip/index.js +1 -0
- package/x/dist/utils/helpers/is/index.js +1 -0
- package/{source → x/dist}/utils/helpers/locales/index.d.ts +1 -0
- package/x/dist/utils/helpers/locales/index.js +1 -0
- package/x/dist/utils/helpers/math/index.js +1 -0
- package/x/dist/utils/helpers/middleware/index.d.ts +19 -0
- package/x/dist/utils/helpers/middleware/index.js +1 -0
- package/x/dist/utils/helpers/objects/index.js +1 -0
- package/x/dist/utils/helpers/path/index.js +1 -0
- package/x/dist/utils/helpers/protocol/index.d.ts +20 -0
- package/x/dist/utils/helpers/protocol/index.js +1 -0
- package/x/dist/utils/helpers/protocol/options.d.ts +6 -0
- package/x/dist/utils/helpers/protocol/options.js +1 -0
- package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-access.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/dto-access.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-types.d.ts +19 -0
- package/x/dist/utils/helpers/runtime/dto-types.js +1 -0
- package/x/dist/utils/helpers/runtime/index.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/index.js +1 -0
- package/x/dist/utils/helpers/runtime/shutdown.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/shutdown.js +1 -0
- package/x/dist/utils/helpers/state/index.d.ts +59 -0
- package/x/dist/utils/helpers/state/index.js +1 -0
- package/x/dist/utils/helpers/state/props-from-tmp.d.ts +9 -0
- package/x/dist/utils/helpers/state/props-from-tmp.js +1 -0
- package/x/dist/utils/helpers/state/request-key-guard.d.ts +3 -0
- package/x/dist/utils/helpers/state/request-key-guard.js +1 -0
- package/x/dist/utils/helpers/state/scopes.d.ts +21 -0
- package/x/dist/utils/helpers/state/scopes.js +1 -0
- package/x/dist/utils/helpers/string/index.js +1 -0
- package/x/dist/utils/helpers/tests/tmp-schema.test.js +1 -0
- package/{source/utils/models/types/index.js → x/dist/utils/helpers/tests/tmp-watch.test.d.ts} +0 -1
- package/x/dist/utils/helpers/tests/tmp-watch.test.js +1 -0
- package/x/dist/utils/helpers/timer/index.js +1 -0
- package/x/dist/utils/helpers/tmp/index.d.ts +5 -0
- package/x/dist/utils/helpers/tmp/index.js +1 -0
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.d.ts +4 -0
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +1 -0
- package/x/dist/utils/helpers/tmp/runtime-tmp.d.ts +9 -0
- package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-loader.d.ts +7 -0
- package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +47 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-watch.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -0
- package/x/dist/utils/helpers/validates/index.js +1 -0
- package/x/dist/utils/index.d.ts +3 -0
- package/x/dist/utils/index.js +1 -0
- package/x/dist/utils/models/classes/class.clients.js +1 -0
- package/x/dist/utils/models/classes/class.interfaces.js +1 -0
- package/x/dist/utils/models/classes/class.service-locator.js +1 -0
- package/{source → x/dist}/utils/models/classes/class.tmp-file-loader.d.ts +3 -2
- package/x/dist/utils/models/classes/class.tmp-file-loader.js +1 -0
- package/x/dist/utils/models/classes/class.x.js +1 -0
- package/{source → x/dist}/utils/models/enums/index.d.ts +14 -1
- package/x/dist/utils/models/enums/index.js +1 -0
- package/x/dist/utils/models/index.d.ts +9 -0
- package/x/dist/utils/models/index.js +1 -0
- package/x/dist/utils/models/types/index.d.ts +5 -0
- package/x/dist/utils/models/types/index.js +1 -0
- package/x/dist/utils/package-root.d.ts +2 -0
- package/x/dist/utils/package-root.js +1 -0
- package/x/tmp.yml +48 -17
- package/bin/constants/index.mjs +0 -17
- package/bin/main-cli.js +0 -131
- package/source/index.js +0 -6
- package/source/loader/clients/index.js +0 -18
- package/source/loader/configs/index.js +0 -81
- package/source/loader/controller/index.d.ts +0 -129
- package/source/loader/controller/index.js +0 -327
- package/source/loader/events/index.js +0 -44
- package/source/loader/index.js +0 -10
- package/source/loader/kafka/index.js +0 -122
- package/source/loader/localizations/index.js +0 -40
- package/source/loader/logger/index.js +0 -183
- package/source/loader/service/index.js +0 -7
- package/source/loader/system/index.js +0 -19
- package/source/project/index.js +0 -66
- package/source/utils/constants/index.d.ts +0 -10
- package/source/utils/constants/index.js +0 -11
- package/source/utils/helpers/configs/index.js +0 -1
- package/source/utils/helpers/core/index.js +0 -105
- package/source/utils/helpers/date/index.js +0 -48
- package/source/utils/helpers/filters/index.js +0 -44
- package/source/utils/helpers/hash/crypto.js +0 -22
- package/source/utils/helpers/id/index.js +0 -24
- package/source/utils/helpers/index.d.ts +0 -17
- package/source/utils/helpers/index.js +0 -17
- package/source/utils/helpers/ip/index.js +0 -21
- package/source/utils/helpers/is/index.js +0 -35
- package/source/utils/helpers/locales/index.js +0 -63
- package/source/utils/helpers/math/index.js +0 -14
- package/source/utils/helpers/middlewares/index.d.ts +0 -1
- package/source/utils/helpers/middlewares/index.js +0 -26
- package/source/utils/helpers/objects/index.js +0 -55
- package/source/utils/helpers/path/index.js +0 -4
- package/source/utils/helpers/regex/checkSpecialRegexControl.js +0 -3
- package/source/utils/helpers/string/index.js +0 -9
- package/source/utils/helpers/timer/index.js +0 -5
- package/source/utils/helpers/validates/index.js +0 -20
- package/source/utils/index.d.ts +0 -3
- package/source/utils/index.js +0 -3
- package/source/utils/models/classes/class.clients.js +0 -142
- package/source/utils/models/classes/class.dtos.d.ts +0 -47
- package/source/utils/models/classes/class.dtos.js +0 -36
- package/source/utils/models/classes/class.interfaces.js +0 -10
- package/source/utils/models/classes/class.response.d.ts +0 -17
- package/source/utils/models/classes/class.response.js +0 -35
- package/source/utils/models/classes/class.service-locator.js +0 -16
- package/source/utils/models/classes/class.tmp-file-loader.js +0 -38
- package/source/utils/models/classes/class.x.js +0 -179
- package/source/utils/models/enums/index.js +0 -133
- package/source/utils/models/index.d.ts +0 -11
- package/source/utils/models/index.js +0 -11
- package/source/utils/models/types/index.d.ts +0 -3
- /package/{source → x/dist}/loader/service/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/configs/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/filters/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/hash/crypto.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/id/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/ip/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/is/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/math/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/objects/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/path/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/regex/checkSpecialRegexControl.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/string/index.d.ts +0 -0
- /package/{source/index.d.ts → x/dist/utils/helpers/tests/tmp-schema.test.d.ts} +0 -0
- /package/{source → x/dist}/utils/helpers/timer/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/validates/index.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.clients.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.interfaces.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.service-locator.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.x.d.ts +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
|
|
6
|
+
import { isCorePackageName } from './build-config.mjs'
|
|
7
|
+
import { syncProjectToolchain } from './toolchain-config.mjs'
|
|
8
|
+
import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
|
|
9
|
+
|
|
10
|
+
const CLI_BIN_DIR = path.dirname(fileURLToPath(import.meta.url))
|
|
11
|
+
const CLI_GENERATED_SCHEMA = path.join(CLI_BIN_DIR, '.generated/tmp-schema.mjs')
|
|
12
|
+
const CLI_SCHEMA_SOURCE = 'source/utils/helpers/tmp/tmp-schema.ts'
|
|
13
|
+
|
|
14
|
+
const CORE_EXPORT_SUBPATHS = [
|
|
15
|
+
'',
|
|
16
|
+
'utils',
|
|
17
|
+
'loader',
|
|
18
|
+
'loader/controller',
|
|
19
|
+
'loader/dto',
|
|
20
|
+
'project',
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
export function resolveDistLayout(root = process.cwd()) {
|
|
24
|
+
const { layout } = ensureTmpFile(root)
|
|
25
|
+
const distRel = relativeFromRoot(root, layout.pathsAbs.dist).replace(/\\/g, '/')
|
|
26
|
+
const distPrefix = distRel.startsWith('./') ? distRel : `./${distRel}`
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
layout,
|
|
30
|
+
distRel,
|
|
31
|
+
distPrefix,
|
|
32
|
+
distAbs: layout.pathsAbs.dist,
|
|
33
|
+
rootFolderPath: layout.rootFolderPath,
|
|
34
|
+
distSegment: layout.paths.dist,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function buildCorePackageExports(distPrefix) {
|
|
39
|
+
const base = distPrefix.replace(/\/$/, '')
|
|
40
|
+
const exports = {
|
|
41
|
+
'./tsconfig.base.json': './tsconfig.base.json',
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (const sub of CORE_EXPORT_SUBPATHS) {
|
|
45
|
+
const suffix = sub ? `/${sub}` : ''
|
|
46
|
+
const key = sub ? `./${sub}` : '.'
|
|
47
|
+
exports[key] = {
|
|
48
|
+
types: `${base}${suffix}/index.d.ts`,
|
|
49
|
+
default: `${base}${suffix}/index.js`,
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return exports
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const CORE_PUBLISH_FILES_STATIC = ['x/bin', 'x/tmp.yml', 'x/assets', 'tsconfig.base.json', 'README.md']
|
|
57
|
+
|
|
58
|
+
function normalizeFilesList(files, distRel) {
|
|
59
|
+
const distEntry = distRel.replace(/^\.\//, '')
|
|
60
|
+
const base = [...CORE_PUBLISH_FILES_STATIC]
|
|
61
|
+
if (!base.includes(distEntry)) base.unshift(distEntry)
|
|
62
|
+
return base
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function stablePackageShape(pkg) {
|
|
66
|
+
return {
|
|
67
|
+
main: pkg.main,
|
|
68
|
+
types: pkg.types,
|
|
69
|
+
exports: pkg.exports,
|
|
70
|
+
files: pkg.files,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function syncCliTmpSchema(root = process.cwd(), { force = false } = {}) {
|
|
75
|
+
const srcAbs = path.join(root, CLI_SCHEMA_SOURCE)
|
|
76
|
+
if (!fs.existsSync(srcAbs)) {
|
|
77
|
+
return { synced: false, reason: 'missing source' }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const outDir = path.dirname(CLI_GENERATED_SCHEMA)
|
|
81
|
+
const needsSync = force
|
|
82
|
+
|| !fs.existsSync(CLI_GENERATED_SCHEMA)
|
|
83
|
+
|| fs.statSync(srcAbs).mtimeMs > fs.statSync(CLI_GENERATED_SCHEMA).mtimeMs
|
|
84
|
+
|
|
85
|
+
if (!needsSync) return { synced: false, reason: 'up-to-date', out: CLI_GENERATED_SCHEMA }
|
|
86
|
+
|
|
87
|
+
fs.mkdirSync(outDir, { recursive: true })
|
|
88
|
+
execSync(
|
|
89
|
+
`bun build "${srcAbs}" --outfile "${CLI_GENERATED_SCHEMA}" --target node --format esm`,
|
|
90
|
+
{ cwd: root, stdio: 'pipe' },
|
|
91
|
+
)
|
|
92
|
+
fs.writeFileSync(path.join(outDir, '.generated-from'), `${CLI_SCHEMA_SOURCE}\n`)
|
|
93
|
+
|
|
94
|
+
return { synced: true, out: CLI_GENERATED_SCHEMA }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function syncPackageManifest(root = process.cwd(), { write = true } = {}) {
|
|
98
|
+
const pkgPath = path.join(root, 'package.json')
|
|
99
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
100
|
+
|
|
101
|
+
if (!isCorePackageName(pkg.name)) {
|
|
102
|
+
return { synced: false, reason: 'not @xrystal/core' }
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const { distPrefix, distRel } = resolveDistLayout(root)
|
|
106
|
+
const next = {
|
|
107
|
+
...pkg,
|
|
108
|
+
main: `${distPrefix}/index.js`,
|
|
109
|
+
types: `${distPrefix}/index.d.ts`,
|
|
110
|
+
exports: buildCorePackageExports(distPrefix),
|
|
111
|
+
files: normalizeFilesList(pkg.files, distRel),
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const changed = JSON.stringify(stablePackageShape(pkg)) !== JSON.stringify(stablePackageShape(next))
|
|
115
|
+
if (write && changed) {
|
|
116
|
+
fs.writeFileSync(pkgPath, `${JSON.stringify(next, null, 2)}\n`)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return { synced: true, wrote: write && changed, distPrefix, distRel, changed }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** tmp.yml → toolchain + CLI schema (+ core package exports on build/release). */
|
|
123
|
+
export function ensureProjectArtifacts(root = process.cwd(), options = {}) {
|
|
124
|
+
const {
|
|
125
|
+
writeToolchain = false,
|
|
126
|
+
writeManifest = false,
|
|
127
|
+
forceSchema = false,
|
|
128
|
+
} = options
|
|
129
|
+
|
|
130
|
+
const schema = syncCliTmpSchema(root, { force: forceSchema })
|
|
131
|
+
const toolchain = syncProjectToolchain(root, { write: writeToolchain })
|
|
132
|
+
let manifest = { synced: false, reason: 'skipped' }
|
|
133
|
+
|
|
134
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
|
|
135
|
+
if (isCorePackageName(pkg.name) && writeManifest) {
|
|
136
|
+
manifest = syncPackageManifest(root, { write: true })
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return { schema, toolchain, manifest }
|
|
140
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { packageDefaults, packageRoot } from '../paths.mjs'
|
|
5
|
+
|
|
6
|
+
export function getProjectRoot(startDir = process.cwd()) {
|
|
7
|
+
return resolveProjectRoot(startDir)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function resolveProjectRoot(startDir = process.cwd()) {
|
|
11
|
+
let dir = path.resolve(startDir)
|
|
12
|
+
|
|
13
|
+
while (dir !== path.dirname(dir)) {
|
|
14
|
+
const pkgPath = path.join(dir, 'package.json')
|
|
15
|
+
if (fs.existsSync(pkgPath)) {
|
|
16
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
17
|
+
if (pkg.name === '@xrystal/core') return dir
|
|
18
|
+
|
|
19
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies }
|
|
20
|
+
if (deps['@xrystal/core']) return dir
|
|
21
|
+
}
|
|
22
|
+
dir = path.dirname(dir)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return path.resolve(startDir)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getCliPackageRoot() {
|
|
29
|
+
return packageRoot
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getBundledCoreTmpPath() {
|
|
33
|
+
return path.join(
|
|
34
|
+
packageRoot,
|
|
35
|
+
packageDefaults.packageRootFolder,
|
|
36
|
+
`${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`,
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function readCliPackageJson() {
|
|
41
|
+
return JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function readProjectPackageJson(root = resolveProjectRoot()) {
|
|
45
|
+
return JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function getInstalledCoreVersion(root = resolveProjectRoot()) {
|
|
49
|
+
const project = readProjectPackageJson(root)
|
|
50
|
+
const declared =
|
|
51
|
+
project.dependencies?.['@xrystal/core']
|
|
52
|
+
?? project.devDependencies?.['@xrystal/core']
|
|
53
|
+
?? null
|
|
54
|
+
|
|
55
|
+
const installedPath = path.join(root, 'node_modules', '@xrystal', 'core', 'package.json')
|
|
56
|
+
if (!fs.existsSync(installedPath)) {
|
|
57
|
+
if (root === packageRoot) {
|
|
58
|
+
const cli = readCliPackageJson()
|
|
59
|
+
return { declared, installed: cli.version, path: path.join(packageRoot, 'package.json'), isWorkspace: true }
|
|
60
|
+
}
|
|
61
|
+
return { declared, installed: null, path: null, isWorkspace: false }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const installed = JSON.parse(fs.readFileSync(installedPath, 'utf8'))
|
|
65
|
+
return { declared, installed: installed.version, path: installedPath, isWorkspace: false }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function projectHasPath(root, relativePath) {
|
|
69
|
+
return fs.existsSync(path.join(root, relativePath))
|
|
70
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
|
+
import os from 'node:os'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
|
|
6
|
+
const EXECUTABLES = [
|
|
7
|
+
{ key: 'node', label: 'Node.js', cmd: 'node' },
|
|
8
|
+
{ key: 'bun', label: 'Bun', cmd: 'bun' },
|
|
9
|
+
{ key: 'npm', label: 'npm', cmd: 'npm' },
|
|
10
|
+
{ key: 'pnpm', label: 'pnpm', cmd: 'pnpm' },
|
|
11
|
+
{ key: 'yarn', label: 'Yarn', cmd: 'yarn' },
|
|
12
|
+
{ key: 'deno', label: 'Deno', cmd: 'deno' },
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
const NODE_MANAGERS = [
|
|
16
|
+
{ key: 'fnm', label: 'fnm', cmd: 'fnm', env: 'FNM_DIR' },
|
|
17
|
+
{ key: 'nvm', label: 'nvm', cmd: 'nvm', env: 'NVM_DIR', shellProbe: true },
|
|
18
|
+
{ key: 'volta', label: 'Volta', cmd: 'volta', env: 'VOLTA_HOME' },
|
|
19
|
+
{ key: 'asdf', label: 'asdf', cmd: 'asdf', env: 'ASDF_DATA_DIR' },
|
|
20
|
+
{ key: 'mise', label: 'mise', cmd: 'mise', env: 'MISE_DATA_DIR' },
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
function tryExec(cmd, cwd = process.cwd()) {
|
|
24
|
+
try {
|
|
25
|
+
return execSync(cmd, {
|
|
26
|
+
cwd,
|
|
27
|
+
encoding: 'utf8',
|
|
28
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
29
|
+
env: process.env,
|
|
30
|
+
}).trim()
|
|
31
|
+
} catch {
|
|
32
|
+
return null
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function tryShellExec(script, cwd = process.cwd()) {
|
|
37
|
+
const shell = process.env.SHELL || '/bin/bash'
|
|
38
|
+
try {
|
|
39
|
+
return execSync(script, {
|
|
40
|
+
cwd,
|
|
41
|
+
encoding: 'utf8',
|
|
42
|
+
shell,
|
|
43
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
44
|
+
env: process.env,
|
|
45
|
+
}).trim()
|
|
46
|
+
} catch {
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function normalizeSemver(value) {
|
|
52
|
+
if (!value) return null
|
|
53
|
+
const trimmed = String(value).trim()
|
|
54
|
+
return trimmed.startsWith('v') ? trimmed : `v${trimmed}`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function parseVersionOutput(raw, cmd) {
|
|
58
|
+
if (!raw) return null
|
|
59
|
+
const firstLine = raw.split('\n').map((line) => line.trim()).find(Boolean) ?? raw
|
|
60
|
+
if (cmd === 'node') return normalizeSemver(firstLine.replace(/^v/i, ''))
|
|
61
|
+
if (cmd === 'deno') {
|
|
62
|
+
const match = firstLine.match(/deno\s+(v[\d.]+)/i) ?? firstLine.match(/(v?\d+\.\d+[\d.-]*)/)
|
|
63
|
+
return match ? normalizeSemver(match[1] ?? match[0]) : firstLine
|
|
64
|
+
}
|
|
65
|
+
const match = firstLine.match(/(v?\d+\.\d+[\w.-]*)/)
|
|
66
|
+
return match ? normalizeSemver(match[1]) : firstLine.slice(0, 48)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function resolveExecutablePath(cmd) {
|
|
70
|
+
if (process.platform === 'win32') {
|
|
71
|
+
return tryExec(`where ${cmd}`)?.split('\n')[0]?.trim() ?? null
|
|
72
|
+
}
|
|
73
|
+
return tryExec(`command -v ${cmd}`) ?? null
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function probeExecutable({ key, label, cmd }, root, { activeKey, execPath }) {
|
|
77
|
+
let version = null
|
|
78
|
+
let location = null
|
|
79
|
+
|
|
80
|
+
if (key === 'node' && !process.versions.bun) {
|
|
81
|
+
version = normalizeSemver(process.version.replace(/^v/, ''))
|
|
82
|
+
location = process.execPath
|
|
83
|
+
} else if (key === 'bun' && process.versions.bun) {
|
|
84
|
+
version = normalizeSemver(process.versions.bun)
|
|
85
|
+
location = process.execPath
|
|
86
|
+
} else {
|
|
87
|
+
version = parseVersionOutput(tryExec(`${cmd} --version`, root), cmd)
|
|
88
|
+
location = resolveExecutablePath(cmd)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!version && !location) return null
|
|
92
|
+
|
|
93
|
+
const active = key === activeKey
|
|
94
|
+
|| (key === 'node' && execPath && location && path.resolve(location) === path.resolve(execPath))
|
|
95
|
+
|
|
96
|
+
return { key, label, version, path: location, active: Boolean(active) }
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function probeManager({ key, label, cmd, env, shellProbe }, root) {
|
|
100
|
+
const envPath = env ? process.env[env] : null
|
|
101
|
+
let version = null
|
|
102
|
+
|
|
103
|
+
if (shellProbe && key === 'nvm') {
|
|
104
|
+
version = tryShellExec('export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"; [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"; command -v nvm >/dev/null 2>&1 && nvm --version', root)
|
|
105
|
+
} else if (cmd) {
|
|
106
|
+
version = parseVersionOutput(tryExec(`${cmd} --version`, root), cmd)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const pathHint = envPath || (key === 'nvm' && fs.existsSync(path.join(os.homedir(), '.nvm')) ? path.join(os.homedir(), '.nvm') : null)
|
|
110
|
+
|
|
111
|
+
if (!version && !pathHint) return null
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
key,
|
|
115
|
+
label,
|
|
116
|
+
version: version ? normalizeSemver(version.replace(/^v/i, '')) : null,
|
|
117
|
+
path: pathHint,
|
|
118
|
+
active: Boolean(envPath && process.env[env]),
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function detectPackageManager(root = process.cwd()) {
|
|
123
|
+
if (fs.existsSync(path.join(root, 'bun.lock')) || fs.existsSync(path.join(root, 'bun.lockb'))) return 'bun'
|
|
124
|
+
if (fs.existsSync(path.join(root, 'pnpm-lock.yaml'))) return 'pnpm'
|
|
125
|
+
if (fs.existsSync(path.join(root, 'yarn.lock'))) return 'yarn'
|
|
126
|
+
if (fs.existsSync(path.join(root, 'package-lock.json'))) return 'npm'
|
|
127
|
+
return process.versions.bun ? 'bun' : 'npm'
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function resolveRuntimeInfo(root = process.cwd()) {
|
|
131
|
+
const bunEmbedded = process.versions.bun
|
|
132
|
+
const cliHost = bunEmbedded ? 'bun' : 'node'
|
|
133
|
+
const cliHostLabel = bunEmbedded ? 'Bun' : 'Node.js'
|
|
134
|
+
const cliHostVersion = bunEmbedded
|
|
135
|
+
? normalizeSemver(bunEmbedded)
|
|
136
|
+
: normalizeSemver(process.version.replace(/^v/, ''))
|
|
137
|
+
|
|
138
|
+
const executables = EXECUTABLES
|
|
139
|
+
.map((item) => probeExecutable(item, root, { activeKey: cliHost, execPath: process.execPath }))
|
|
140
|
+
.filter(Boolean)
|
|
141
|
+
|
|
142
|
+
const managers = NODE_MANAGERS
|
|
143
|
+
.map((item) => probeManager(item, root))
|
|
144
|
+
.filter(Boolean)
|
|
145
|
+
|
|
146
|
+
const git = tryExec('git --version', root)
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
platform: `${os.platform()} ${os.arch()}`,
|
|
150
|
+
osRelease: os.release(),
|
|
151
|
+
cliHost,
|
|
152
|
+
cliHostLabel,
|
|
153
|
+
cliHostVersion,
|
|
154
|
+
executables,
|
|
155
|
+
managers,
|
|
156
|
+
git,
|
|
157
|
+
packageManager: detectPackageManager(root),
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function listRuntimeInventory(info) {
|
|
162
|
+
return {
|
|
163
|
+
executables: EXECUTABLES.map(({ key, label }) => {
|
|
164
|
+
const found = info.executables.find((item) => item.key === key)
|
|
165
|
+
return found ?? { key, label, version: null, path: null, active: false }
|
|
166
|
+
}),
|
|
167
|
+
managers: NODE_MANAGERS.map(({ key, label }) => {
|
|
168
|
+
const found = info.managers.find((item) => item.key === key)
|
|
169
|
+
return found ?? { key, label, version: null, path: null, active: false }
|
|
170
|
+
}),
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { readTmpServiceBlock } from './tmp-schema.mjs'
|
|
2
|
+
const PROTOCOL_ALIASES = {
|
|
3
|
+
http: 'http',
|
|
4
|
+
https: 'https',
|
|
5
|
+
ws: 'ws',
|
|
6
|
+
websocket: 'ws',
|
|
7
|
+
socketio: 'socketio',
|
|
8
|
+
socket: 'socketio',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function parseProtocolValue(value) {
|
|
12
|
+
if (!value) return 'http'
|
|
13
|
+
const key = String(value).toLowerCase().replace(/[-_\s.]/g, '')
|
|
14
|
+
return PROTOCOL_ALIASES[key] ?? String(value)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** configs.protocols from tmp.yml */
|
|
18
|
+
export function resolveProtocolsFromConfig(configs = {}) {
|
|
19
|
+
const raw = configs.protocols
|
|
20
|
+
if (!raw) return ['http']
|
|
21
|
+
return (Array.isArray(raw) ? raw : [raw]).map(parseProtocolValue)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function summarizeLoaders(tmp = {}) {
|
|
25
|
+
const configs = tmp.configs ?? {}
|
|
26
|
+
const service = configs.service ?? readTmpServiceBlock(configs)
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
framework: service.framework ?? 'elysia',
|
|
30
|
+
protocols: resolveProtocolsFromConfig(service),
|
|
31
|
+
service: service.name,
|
|
32
|
+
items: [
|
|
33
|
+
service.loaders?.dto && { key: 'dto', detail: formatLoaderDetail(service.loaders?.dto) },
|
|
34
|
+
service.loaders?.loggers && { key: 'loggers', detail: formatLoaderDetail(service.loaders?.loggers) },
|
|
35
|
+
service.loaders?.localization && { key: 'localization', detail: formatLoaderDetail(service.loaders?.localization) },
|
|
36
|
+
service.loaders?.configs && { key: 'configs', detail: formatLoaderDetail(service.loaders?.configs) },
|
|
37
|
+
service.loaders?.controller && Object.keys(service.loaders?.controller).length > 0 && {
|
|
38
|
+
key: 'controller',
|
|
39
|
+
detail: formatLoaderDetail(service.loaders?.controller),
|
|
40
|
+
},
|
|
41
|
+
].filter(Boolean),
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function formatLoaderDetail(obj) {
|
|
46
|
+
if (!obj || typeof obj !== 'object') return String(obj)
|
|
47
|
+
const parts = []
|
|
48
|
+
if (obj.loadPath) parts.push(`path: ${obj.loadPath}`)
|
|
49
|
+
if (obj.logLevel) parts.push(`level: ${obj.logLevel}`)
|
|
50
|
+
if (obj.fallbackLang) parts.push(`fallback: ${obj.fallbackLang}`)
|
|
51
|
+
if (obj.preloadLangs) parts.push(`langs: ${obj.preloadLangs.join(', ')}`)
|
|
52
|
+
if (obj.withDefaultHeaders !== undefined) parts.push(`headers: ${obj.withDefaultHeaders}`)
|
|
53
|
+
if (!parts.length) return Object.keys(obj).join(', ') || 'ok'
|
|
54
|
+
return parts.join(' · ')
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function formatLoaderSummary(summary) {
|
|
58
|
+
const lines = [
|
|
59
|
+
`framework: ${summary.framework}`,
|
|
60
|
+
`protocols: ${summary.protocols.join(', ')}`,
|
|
61
|
+
]
|
|
62
|
+
if (summary.service) lines.push(`service: ${summary.service}`)
|
|
63
|
+
for (const item of summary.items) {
|
|
64
|
+
lines.push(`${item.key}: ${item.detail}`)
|
|
65
|
+
}
|
|
66
|
+
return lines
|
|
67
|
+
}
|