@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,281 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import yaml from 'yaml'
|
|
4
|
+
|
|
5
|
+
import { packageDefaults } from '../paths.mjs'
|
|
6
|
+
import { findAllFilesRecursively, findFileRecursively } from './index.mjs'
|
|
7
|
+
import { getBundledCoreTmpPath } from './project-root.mjs'
|
|
8
|
+
import { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, readTmpServiceBlock, resolveServiceLayoutPaths } from './tmp-schema.mjs'
|
|
9
|
+
|
|
10
|
+
const DEFAULT_PATHS = packageDefaults.layoutPaths
|
|
11
|
+
|
|
12
|
+
function formatTmpTarget(name, ext) {
|
|
13
|
+
return `${name}${ext.startsWith('.') ? ext : `.${ext}`}`
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function readTmpFile(filePath) {
|
|
17
|
+
return yaml.parse(fs.readFileSync(filePath, 'utf8'))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function isCorePackageRoot(projectRoot) {
|
|
21
|
+
const pkgPath = path.join(path.resolve(projectRoot), 'package.json')
|
|
22
|
+
if (!fs.existsSync(pkgPath)) return false
|
|
23
|
+
try {
|
|
24
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
25
|
+
return pkg.name === packageDefaults.packageName
|
|
26
|
+
} catch {
|
|
27
|
+
return false
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export function coreCanonicalTmpPath(projectRoot = process.cwd()) {
|
|
33
|
+
return path.join(
|
|
34
|
+
path.resolve(projectRoot),
|
|
35
|
+
packageDefaults.packageRootFolder,
|
|
36
|
+
formatTmpTarget(packageDefaults.tmpBaseName, packageDefaults.tmpExtension),
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function assertCoreTmpGuard(projectRoot, tmpFilePath) {
|
|
41
|
+
if (!isCorePackageRoot(projectRoot)) return
|
|
42
|
+
|
|
43
|
+
const canonical = coreCanonicalTmpPath(projectRoot)
|
|
44
|
+
if (path.resolve(tmpFilePath) !== path.resolve(canonical)) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`@xrystal/core: tmp.yml must stay at ${packageDefaults.packageRootFolder}/tmp.yml (expected ${canonical}, got ${tmpFilePath})`,
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function findStrayCoreTmpFiles(projectRoot, canonicalPath) {
|
|
52
|
+
const resolvedRoot = path.resolve(projectRoot)
|
|
53
|
+
const canonical = path.resolve(canonicalPath)
|
|
54
|
+
return findAllFilesRecursively(resolvedRoot, packageDefaults.tmpBaseName, packageDefaults.tmpExtension)
|
|
55
|
+
.filter((filePath) => path.resolve(filePath) !== canonical)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function ensureCoreTmpEntry(projectRoot = process.cwd(), options = {}) {
|
|
59
|
+
const resolvedRoot = path.resolve(projectRoot)
|
|
60
|
+
if (!isCorePackageRoot(resolvedRoot)) {
|
|
61
|
+
throw new Error('ensureCoreTmpEntry is only for @xrystal/core package root')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const canonical = coreCanonicalTmpPath(resolvedRoot)
|
|
65
|
+
const strays = findStrayCoreTmpFiles(resolvedRoot, canonical)
|
|
66
|
+
if (strays.length > 0) {
|
|
67
|
+
const rel = strays.map((p) => path.relative(resolvedRoot, p)).join(', ')
|
|
68
|
+
throw new Error(
|
|
69
|
+
`@xrystal/core: tmp.yml must only exist under ${packageDefaults.packageRootFolder}/. Remove extra copies: ${rel}`,
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (fs.existsSync(canonical)) {
|
|
74
|
+
assertCoreTmpGuard(resolvedRoot, canonical)
|
|
75
|
+
return {
|
|
76
|
+
tmpFilePath: canonical,
|
|
77
|
+
created: false,
|
|
78
|
+
layout: buildTmpLayout(resolvedRoot, readTmpFile(canonical), canonical),
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return ensureTmpFile(resolvedRoot, { ...options, patchServiceName: false })
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function resolveTmpFilePath(projectRoot, tmpFileName, ext) {
|
|
86
|
+
const resolvedRoot = path.resolve(projectRoot)
|
|
87
|
+
|
|
88
|
+
if (isCorePackageRoot(resolvedRoot)) {
|
|
89
|
+
const canonical = coreCanonicalTmpPath(resolvedRoot)
|
|
90
|
+
return fs.existsSync(canonical) ? canonical : null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return findFileRecursively(resolvedRoot, tmpFileName, ext)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function resolveRootFolderPath(tmp, tmpFilePath, projectRoot) {
|
|
97
|
+
const configs = normalizeTmpDocument(tmp ?? {}).configs ?? {}
|
|
98
|
+
const service = readTmpServiceBlock(configs)
|
|
99
|
+
|
|
100
|
+
if (service.paths?.root?.trim()) {
|
|
101
|
+
return normalizeRootFolder(service.paths.root)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (typeof tmp?.project?.name === 'string' && tmp.project.name.trim()) {
|
|
105
|
+
return tmp.project.name.trim()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const relativeDir = path.relative(
|
|
109
|
+
path.resolve(projectRoot),
|
|
110
|
+
path.dirname(path.resolve(tmpFilePath)),
|
|
111
|
+
)
|
|
112
|
+
if (relativeDir && relativeDir !== '.') {
|
|
113
|
+
return relativeDir
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return packageDefaults.packageRootFolder
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function resolveLayoutPaths(configs) {
|
|
120
|
+
return resolveServiceLayoutPaths(readTmpServiceBlock(configs))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function resolveMainFolderPath(configs) {
|
|
124
|
+
const source = readTmpServiceBlock(configs).paths?.source
|
|
125
|
+
if (typeof source === 'string' && source.trim()) {
|
|
126
|
+
return normalizeSourceFolder(source)
|
|
127
|
+
}
|
|
128
|
+
return packageDefaults.mainSourceFolder
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function buildTmpLayout(projectRoot, tmp, tmpFilePath) {
|
|
132
|
+
const resolvedRoot = path.resolve(projectRoot)
|
|
133
|
+
const configs = tmp ? normalizeTmpDocument(tmp).configs : undefined
|
|
134
|
+
const rootFolderPath = tmp && tmpFilePath && !isCorePackageRoot(resolvedRoot)
|
|
135
|
+
? resolveRootFolderPath(tmp, tmpFilePath, resolvedRoot)
|
|
136
|
+
: packageDefaults.packageRootFolder
|
|
137
|
+
const rootFolderAbs = path.join(resolvedRoot, rootFolderPath)
|
|
138
|
+
const paths = resolveLayoutPaths(configs)
|
|
139
|
+
const mainFolderPath = resolveMainFolderPath(configs)
|
|
140
|
+
|
|
141
|
+
const pathsAbs = {
|
|
142
|
+
tests: path.join(rootFolderAbs, paths.tests),
|
|
143
|
+
environments: path.join(rootFolderAbs, paths.environments),
|
|
144
|
+
dist: path.join(rootFolderAbs, paths.dist),
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
projectRoot: resolvedRoot,
|
|
149
|
+
rootFolderPath,
|
|
150
|
+
rootFolderAbs,
|
|
151
|
+
tmpFilePath,
|
|
152
|
+
mainFolderPath,
|
|
153
|
+
paths,
|
|
154
|
+
pathsAbs,
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function resolveTmpLayout(projectRoot = process.cwd(), options = {}) {
|
|
159
|
+
const tmpFileName = options.tmpFileName ?? packageDefaults.tmpBaseName
|
|
160
|
+
const ext = options.ext ?? packageDefaults.tmpExtension
|
|
161
|
+
const tmpFilePath = resolveTmpFilePath(projectRoot, tmpFileName, ext)
|
|
162
|
+
|
|
163
|
+
if (!tmpFilePath) {
|
|
164
|
+
throw new Error(`${formatTmpTarget(tmpFileName, ext)} not found under ${path.resolve(projectRoot)}`)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (isCorePackageRoot(path.resolve(projectRoot))) {
|
|
168
|
+
assertCoreTmpGuard(projectRoot, tmpFilePath)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return buildTmpLayout(projectRoot, readTmpFile(tmpFilePath), tmpFilePath)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function resolveTmpLayoutOrDefaults(projectRoot = process.cwd()) {
|
|
175
|
+
const tmpFilePath = resolveTmpFilePath(
|
|
176
|
+
projectRoot,
|
|
177
|
+
packageDefaults.tmpBaseName,
|
|
178
|
+
packageDefaults.tmpExtension,
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
if (!tmpFilePath) {
|
|
182
|
+
return buildTmpLayout(projectRoot, null, null)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return buildTmpLayout(projectRoot, readTmpFile(tmpFilePath), tmpFilePath)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function ownerTmpFilePath(projectRoot = process.cwd(), layout) {
|
|
189
|
+
const resolved = layout ?? resolveTmpLayoutOrDefaults(projectRoot)
|
|
190
|
+
return path.join(
|
|
191
|
+
resolved.rootFolderAbs,
|
|
192
|
+
formatTmpTarget(packageDefaults.tmpBaseName, packageDefaults.tmpExtension),
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function relativeFromRoot(projectRoot, absolutePath) {
|
|
197
|
+
const rel = path.relative(path.resolve(projectRoot), absolutePath)
|
|
198
|
+
return rel.startsWith('.') ? rel : `./${rel}`
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function ensureTmpFile(projectRoot = process.cwd(), { patchServiceName = true } = {}) {
|
|
202
|
+
const resolvedRoot = path.resolve(projectRoot)
|
|
203
|
+
|
|
204
|
+
if (isCorePackageRoot(resolvedRoot)) {
|
|
205
|
+
const canonical = coreCanonicalTmpPath(resolvedRoot)
|
|
206
|
+
const strays = findStrayCoreTmpFiles(resolvedRoot, canonical)
|
|
207
|
+
if (strays.length > 0) {
|
|
208
|
+
const rel = strays.map((p) => path.relative(resolvedRoot, p)).join(', ')
|
|
209
|
+
throw new Error(
|
|
210
|
+
`@xrystal/core: tmp.yml must only exist under ${packageDefaults.packageRootFolder}/. Remove extra copies: ${rel}`,
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (fs.existsSync(canonical)) {
|
|
215
|
+
assertCoreTmpGuard(resolvedRoot, canonical)
|
|
216
|
+
return {
|
|
217
|
+
tmpFilePath: canonical,
|
|
218
|
+
created: false,
|
|
219
|
+
layout: buildTmpLayout(resolvedRoot, readTmpFile(canonical), canonical),
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
} else {
|
|
223
|
+
const existing = findFileRecursively(
|
|
224
|
+
resolvedRoot,
|
|
225
|
+
packageDefaults.tmpBaseName,
|
|
226
|
+
packageDefaults.tmpExtension,
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
if (existing) {
|
|
230
|
+
return {
|
|
231
|
+
tmpFilePath: existing,
|
|
232
|
+
created: false,
|
|
233
|
+
layout: buildTmpLayout(resolvedRoot, readTmpFile(existing), existing),
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const templatePath = getBundledCoreTmpPath()
|
|
239
|
+
if (!fs.existsSync(templatePath)) {
|
|
240
|
+
throw new Error('@xrystal/core bundled x/tmp.yml not found in package')
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const layout = buildTmpLayout(resolvedRoot, null, null)
|
|
244
|
+
fs.mkdirSync(layout.rootFolderAbs, { recursive: true })
|
|
245
|
+
|
|
246
|
+
const targetPath = path.join(
|
|
247
|
+
layout.rootFolderAbs,
|
|
248
|
+
formatTmpTarget(packageDefaults.tmpBaseName, packageDefaults.tmpExtension),
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
let content = fs.readFileSync(templatePath, 'utf8')
|
|
252
|
+
if (patchServiceName) {
|
|
253
|
+
try {
|
|
254
|
+
const pkgPath = path.join(resolvedRoot, 'package.json')
|
|
255
|
+
if (fs.existsSync(pkgPath)) {
|
|
256
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
257
|
+
const serviceName = typeof pkg.name === 'string'
|
|
258
|
+
? pkg.name.replace(/^@/, '').replace(/\//g, '-')
|
|
259
|
+
: null
|
|
260
|
+
if (serviceName) {
|
|
261
|
+
const tmp = yaml.parse(content)
|
|
262
|
+
tmp.configs = tmp.configs ?? {}
|
|
263
|
+
tmp.configs.service = serviceName
|
|
264
|
+
content = yaml.stringify(tmp)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
} catch {
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
fs.writeFileSync(targetPath, content)
|
|
272
|
+
return {
|
|
273
|
+
tmpFilePath: targetPath,
|
|
274
|
+
created: true,
|
|
275
|
+
layout: buildTmpLayout(resolvedRoot, readTmpFile(targetPath), targetPath),
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function resolveTmpLayoutEnsured(projectRoot = process.cwd()) {
|
|
280
|
+
return ensureTmpFile(projectRoot).layout
|
|
281
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { packageDefaults } from '../paths.mjs'
|
|
5
|
+
import { relativeFromRoot, resolveTmpLayoutOrDefaults } from './tmp-layout.mjs'
|
|
6
|
+
|
|
7
|
+
function stripLeadingDotSlash(value) {
|
|
8
|
+
return String(value).replace(/^\.\//, '')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function layoutToToolchainOptions(layout) {
|
|
12
|
+
if (!layout) return {}
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
rootFolderPath: layout.rootFolderPath,
|
|
16
|
+
mainFolderPath: layout.mainFolderPath,
|
|
17
|
+
pathsDist: layout.paths?.dist,
|
|
18
|
+
pathsTests: layout.paths?.tests,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function resolveToolchainPaths(options = {}) {
|
|
23
|
+
const rootFolder = options.rootFolderPath ?? packageDefaults.packageRootFolder
|
|
24
|
+
const mainFolder = stripLeadingDotSlash(options.mainFolderPath ?? packageDefaults.mainSourceFolder)
|
|
25
|
+
const distSegment = options.pathsDist ?? packageDefaults.layoutPaths.dist
|
|
26
|
+
const testsSegment = options.pathsTests ?? packageDefaults.layoutPaths.tests
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
mainSourceFolder: `./${mainFolder}`,
|
|
30
|
+
mainSourceRel: mainFolder,
|
|
31
|
+
packageRootFolder: rootFolder,
|
|
32
|
+
outDir: `./${rootFolder}/${distSegment}`,
|
|
33
|
+
include: [mainFolder],
|
|
34
|
+
exclude: [`${rootFolder}/${testsSegment}`],
|
|
35
|
+
pathAliasKey: packageDefaults.tsconfigDefaults?.pathAliasKey ?? '@/*',
|
|
36
|
+
pathAliasTarget: [`${mainFolder}/*`],
|
|
37
|
+
eslintFiles: [`${mainFolder}/**/*.ts`, `${mainFolder}/**/*.tsx`],
|
|
38
|
+
eslintIgnores: [
|
|
39
|
+
`${rootFolder}/${distSegment}/**`,
|
|
40
|
+
'**/node_modules/**',
|
|
41
|
+
`${mainFolder}/**/*.d.ts`,
|
|
42
|
+
],
|
|
43
|
+
bunfigAliasLine: `@/* = "./${mainFolder}/*"`,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function resolveToolchainPathsFromProject(root = process.cwd()) {
|
|
48
|
+
const layout = resolveTmpLayoutOrDefaults(root)
|
|
49
|
+
return resolveToolchainPaths(layoutToToolchainOptions(layout))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function resolveRecommendedTsconfig(options = {}) {
|
|
53
|
+
const paths = resolveToolchainPaths(options)
|
|
54
|
+
const baseOptions = packageDefaults.tsconfigDefaults?.compilerOptions ?? {}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
include: [...paths.include],
|
|
58
|
+
exclude: [...paths.exclude],
|
|
59
|
+
compilerOptions: {
|
|
60
|
+
target: 'ESNext',
|
|
61
|
+
module: 'ESNext',
|
|
62
|
+
moduleResolution: 'Bundler',
|
|
63
|
+
baseUrl: '.',
|
|
64
|
+
paths: { [paths.pathAliasKey]: paths.pathAliasTarget },
|
|
65
|
+
rootDir: paths.mainSourceFolder,
|
|
66
|
+
outDir: paths.outDir,
|
|
67
|
+
esModuleInterop: true,
|
|
68
|
+
forceConsistentCasingInFileNames: true,
|
|
69
|
+
skipLibCheck: true,
|
|
70
|
+
...baseOptions,
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function resolveRecommendedTsconfigFromProject(root = process.cwd()) {
|
|
76
|
+
const layout = resolveTmpLayoutOrDefaults(root)
|
|
77
|
+
return resolveRecommendedTsconfig(layoutToToolchainOptions(layout))
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function resolveTsconfigExtends(root) {
|
|
81
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
|
|
82
|
+
if (pkg.name === packageDefaults.packageName) return './tsconfig.base.json'
|
|
83
|
+
return '@xrystal/core/tsconfig.base.json'
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function mergeTsconfigWithLayout(recommended, existing = {}, extendsPath) {
|
|
87
|
+
const merged = {
|
|
88
|
+
...existing,
|
|
89
|
+
extends: existing.extends ?? extendsPath,
|
|
90
|
+
include: recommended.include,
|
|
91
|
+
exclude: recommended.exclude,
|
|
92
|
+
compilerOptions: {
|
|
93
|
+
...(existing.compilerOptions ?? {}),
|
|
94
|
+
baseUrl: recommended.compilerOptions.baseUrl,
|
|
95
|
+
paths: recommended.compilerOptions.paths,
|
|
96
|
+
rootDir: recommended.compilerOptions.rootDir,
|
|
97
|
+
outDir: recommended.compilerOptions.outDir,
|
|
98
|
+
},
|
|
99
|
+
}
|
|
100
|
+
return merged
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function readProjectTsconfig(root, tsconfigRel = packageDefaults.buildDefaults?.tsconfig ?? 'tsconfig.json') {
|
|
104
|
+
const abs = path.isAbsolute(tsconfigRel) ? tsconfigRel : path.join(root, tsconfigRel)
|
|
105
|
+
if (!fs.existsSync(abs)) return null
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
return { rel: tsconfigRel, abs, raw: JSON.parse(fs.readFileSync(abs, 'utf8')) }
|
|
109
|
+
} catch {
|
|
110
|
+
return null
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function syncProjectToolchain(root = process.cwd(), { write = true, tsconfigRel = 'tsconfig.json' } = {}) {
|
|
115
|
+
const layout = resolveTmpLayoutOrDefaults(root)
|
|
116
|
+
const options = layoutToToolchainOptions(layout)
|
|
117
|
+
const recommended = resolveRecommendedTsconfig(options)
|
|
118
|
+
const extendsPath = resolveTsconfigExtends(root)
|
|
119
|
+
const existing = readProjectTsconfig(root, tsconfigRel)
|
|
120
|
+
const merged = mergeTsconfigWithLayout(recommended, existing?.raw ?? {}, extendsPath)
|
|
121
|
+
const paths = resolveToolchainPaths(options)
|
|
122
|
+
|
|
123
|
+
const result = {
|
|
124
|
+
layout: {
|
|
125
|
+
rootFolderPath: layout.rootFolderPath,
|
|
126
|
+
mainFolderPath: layout.mainFolderPath,
|
|
127
|
+
paths: layout.paths,
|
|
128
|
+
},
|
|
129
|
+
tsconfigRel,
|
|
130
|
+
merged,
|
|
131
|
+
paths,
|
|
132
|
+
wrote: false,
|
|
133
|
+
created: false,
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (write) {
|
|
137
|
+
const abs = path.join(root, tsconfigRel)
|
|
138
|
+
result.created = !fs.existsSync(abs)
|
|
139
|
+
fs.writeFileSync(abs, `${JSON.stringify(merged, null, 2)}\n`, 'utf8')
|
|
140
|
+
result.wrote = true
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return result
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function auditTsconfigAlignment(root, options = null) {
|
|
147
|
+
const resolvedOptions = options ?? layoutToToolchainOptions(resolveTmpLayoutOrDefaults(root))
|
|
148
|
+
const recommended = resolveRecommendedTsconfig(resolvedOptions)
|
|
149
|
+
const onDisk = readProjectTsconfig(root)
|
|
150
|
+
if (!onDisk) {
|
|
151
|
+
return { ok: false, missing: true, notes: ['tsconfig.json not found — run xcore sync-toolchain'] }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const notes = []
|
|
155
|
+
const opts = onDisk.raw.compilerOptions ?? {}
|
|
156
|
+
const aliasKey = resolveToolchainPaths(resolvedOptions).pathAliasKey
|
|
157
|
+
|
|
158
|
+
if (opts.outDir !== recommended.compilerOptions.outDir) {
|
|
159
|
+
notes.push(`outDir: tsconfig="${opts.outDir ?? '(missing)'}" tmp→"${recommended.compilerOptions.outDir}"`)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const include = onDisk.raw.include ?? []
|
|
163
|
+
if (!include.some((item) => String(item).replace(/^\.\//, '') === recommended.include[0])) {
|
|
164
|
+
notes.push(`include: tsconfig=${JSON.stringify(include)} tmp→${JSON.stringify(recommended.include)}`)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const alias = opts.paths?.[aliasKey]
|
|
168
|
+
const expectedAlias = recommended.compilerOptions.paths[aliasKey]
|
|
169
|
+
if (JSON.stringify(alias) !== JSON.stringify(expectedAlias)) {
|
|
170
|
+
notes.push(`paths ${aliasKey}: tsconfig=${JSON.stringify(alias)} tmp→${JSON.stringify(expectedAlias)}`)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return { ok: notes.length === 0, missing: false, notes, recommended, onDisk: onDisk.raw, layoutOptions: resolvedOptions }
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function createEslintConfigFromProject(root = process.cwd(), tseslint) {
|
|
177
|
+
const paths = resolveToolchainPathsFromProject(root)
|
|
178
|
+
const depth = packageDefaults.eslintDefaults?.restrictedImportDepth ?? 2
|
|
179
|
+
const deepRelative = '../'.repeat(depth + 1)
|
|
180
|
+
|
|
181
|
+
return tseslint.config(
|
|
182
|
+
{ ignores: paths.eslintIgnores },
|
|
183
|
+
{
|
|
184
|
+
files: paths.eslintFiles,
|
|
185
|
+
languageOptions: { parser: tseslint.parser },
|
|
186
|
+
rules: {
|
|
187
|
+
'no-restricted-imports': [
|
|
188
|
+
'error',
|
|
189
|
+
{
|
|
190
|
+
patterns: [
|
|
191
|
+
{
|
|
192
|
+
group: [`${deepRelative}*`, `${deepRelative}**`],
|
|
193
|
+
message: 'Use @/ alias instead of relative imports deeper than ../..',
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function resolveCoreBuildEntries(root) {
|
|
204
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
|
|
205
|
+
const entries = new Set()
|
|
206
|
+
|
|
207
|
+
const addEntry = (spec) => {
|
|
208
|
+
if (typeof spec !== 'string' || !spec) return
|
|
209
|
+
const normalized = spec.startsWith('./') ? spec : `./${spec}`
|
|
210
|
+
const tsPath = normalized
|
|
211
|
+
.replace(/^\.\/[^/]+\/dist\//, './source/')
|
|
212
|
+
.replace(/\.js$/, '.ts')
|
|
213
|
+
if (tsPath.endsWith('.ts') && fs.existsSync(path.join(root, tsPath))) {
|
|
214
|
+
entries.add(tsPath)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
addEntry(pkg.main)
|
|
219
|
+
for (const value of Object.values(pkg.exports ?? {})) {
|
|
220
|
+
if (typeof value === 'string') addEntry(value)
|
|
221
|
+
else if (value && typeof value === 'object') {
|
|
222
|
+
addEntry(value.default)
|
|
223
|
+
addEntry(value.import)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (entries.size === 0) {
|
|
228
|
+
const paths = resolveToolchainPathsFromProject(root)
|
|
229
|
+
addEntry(`${paths.mainSourceFolder}/index.ts`)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return [...entries].sort()
|
|
233
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Command } from 'commander'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
|
|
6
|
+
import { registerCreateCommand } from './commands/create.mjs'
|
|
7
|
+
import { registerDoctorCommand } from './commands/doctor.mjs'
|
|
8
|
+
import { registerProjectCommands } from './commands/project.mjs'
|
|
9
|
+
import { registerTmpCommand } from './commands/tmp.mjs'
|
|
10
|
+
import { registerSyncToolchainCommand } from './commands/sync-toolchain.mjs'
|
|
11
|
+
import { registerTagCommand, registerVersionCommand } from './commands/release.mjs'
|
|
12
|
+
import { registerHooksCommand } from './commands/hooks.mjs'
|
|
13
|
+
import { printBanner, shouldShowBanner } from './helpers/banner.mjs'
|
|
14
|
+
import { formatRootHelp, formatCreateCommandHelp, isCreateHelpRequest, isRootHelpRequest, printQuickStartGuide } from './helpers/cli-help.mjs'
|
|
15
|
+
import { resolveInvokedAs } from './helpers/cli-identity.mjs'
|
|
16
|
+
import { readCliPackageJson, getProjectRoot } from './helpers/project-root.mjs'
|
|
17
|
+
import { ensureProjectArtifacts } from './helpers/project-artifacts.mjs'
|
|
18
|
+
|
|
19
|
+
const pkg = readCliPackageJson()
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
ensureProjectArtifacts(getProjectRoot(), { writeToolchain: false, writeManifest: false })
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const cliName = resolveInvokedAs()
|
|
27
|
+
|
|
28
|
+
const isBun = !!process.versions.bun
|
|
29
|
+
const runtimeName = isBun ? 'Bun' : 'Node.js'
|
|
30
|
+
const packageManager = isBun ? 'bun' : 'npm'
|
|
31
|
+
const installCommand = isBun ? 'bun install' : 'npm install'
|
|
32
|
+
const devCommand = isBun ? `${cliName} dev` : `npx ${cliName} dev`
|
|
33
|
+
const cliContext = { cliName, runtimeName, packageManager, installCommand, devCommand }
|
|
34
|
+
|
|
35
|
+
if (shouldShowBanner()) {
|
|
36
|
+
printBanner({ version: pkg.version, runtimeName, invokedAs: cliName })
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (isRootHelpRequest()) {
|
|
40
|
+
console.log(formatRootHelp({ cliName }))
|
|
41
|
+
process.exit(0)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (isCreateHelpRequest()) {
|
|
45
|
+
console.log(formatCreateCommandHelp({ cliName }))
|
|
46
|
+
process.exit(0)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const cli = new Command()
|
|
50
|
+
|
|
51
|
+
cli
|
|
52
|
+
.name(cliName)
|
|
53
|
+
.description('xrystal core — microservice runtime library')
|
|
54
|
+
.version(pkg.version, '-V, --version', 'Show @xrystal/core CLI version')
|
|
55
|
+
.configureHelp({
|
|
56
|
+
helpWidth: () => Math.min(100, Math.max(56, process.stdout.columns || 80)),
|
|
57
|
+
sortSubcommands: true,
|
|
58
|
+
})
|
|
59
|
+
.action(() => {
|
|
60
|
+
printQuickStartGuide({ cliName })
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
registerCreateCommand(cli, cliContext)
|
|
64
|
+
registerVersionCommand(cli, cliContext)
|
|
65
|
+
registerTagCommand(cli, cliContext)
|
|
66
|
+
registerDoctorCommand(cli, cliContext)
|
|
67
|
+
registerTmpCommand(cli, cliContext)
|
|
68
|
+
registerSyncToolchainCommand(cli, cliContext)
|
|
69
|
+
registerHooksCommand(cli, cliContext)
|
|
70
|
+
registerProjectCommands(cli, cliContext)
|
|
71
|
+
|
|
72
|
+
cli.parseAsync(process.argv).catch((error) => {
|
|
73
|
+
console.error(chalk.red(`\n✗ ${error.message}\n`))
|
|
74
|
+
process.exit(1)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
process.on('uncaughtException', (error) => {
|
|
78
|
+
console.error(chalk.red(`Critical error: ${error.message}`))
|
|
79
|
+
process.exit(1)
|
|
80
|
+
})
|
package/x/bin/paths.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
|
|
4
|
+
const binDir = path.dirname(fileURLToPath(import.meta.url))
|
|
5
|
+
|
|
6
|
+
export const packageRoot = path.resolve(binDir, '..', '..')
|
|
7
|
+
export const sourceDir = path.join(packageRoot, 'source')
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
packageDefaults,
|
|
11
|
+
packageDefaults as Constants,
|
|
12
|
+
coreVersionPattern,
|
|
13
|
+
semverVersionPattern,
|
|
14
|
+
} from '../../source/utils/constants/defaults.mjs'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
const root = process.cwd()
|
|
5
|
+
const sourceRoot = path.join(root, 'source')
|
|
6
|
+
const keepRel = path.join('source', 'utils', 'models', 'types', 'shims.d.ts')
|
|
7
|
+
|
|
8
|
+
function walk(dir) {
|
|
9
|
+
for (const name of fs.readdirSync(dir)) {
|
|
10
|
+
const abs = path.join(dir, name)
|
|
11
|
+
const stat = fs.statSync(abs)
|
|
12
|
+
if (stat.isDirectory()) { walk(abs); continue }
|
|
13
|
+
if (!name.endsWith('.d.ts') && !name.endsWith('.js')) continue
|
|
14
|
+
if (name.endsWith('.d.ts') && path.relative(root, abs) === keepRel) continue
|
|
15
|
+
fs.unlinkSync(abs)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (fs.existsSync(sourceRoot)) walk(sourceRoot)
|