@xrystal/core 3.32.1 → 3.37.4
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 +676 -136
- package/package.json +27 -24
- package/tsconfig.base.json +15 -0
- package/x/bin/commands/create.mjs +34 -5
- package/x/bin/commands/doctor.mjs +115 -25
- package/x/bin/commands/hooks.mjs +55 -0
- package/x/bin/commands/project.mjs +75 -42
- package/x/bin/commands/release.mjs +8 -3
- package/x/bin/commands/sync-toolchain.mjs +43 -0
- package/x/bin/commands/tmp.mjs +13 -4
- 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 +66 -12
- package/x/bin/helpers/build-config.mjs +342 -0
- package/x/bin/helpers/cli-help.mjs +164 -0
- package/x/bin/helpers/create-target.mjs +18 -2
- package/x/bin/helpers/project-artifacts.mjs +142 -0
- package/x/bin/helpers/runtime-info.mjs +172 -0
- package/x/bin/helpers/tmp-config.mjs +11 -10
- package/x/bin/helpers/tmp-layout.mjs +10 -16
- package/x/bin/helpers/tmp-schema.mjs +9 -0
- package/x/bin/helpers/toolchain-config.mjs +233 -0
- package/x/bin/main-cli.js +31 -3
- 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 +39 -0
- package/x/bin/scripts/publish-guard.mjs +113 -0
- package/x/bin/scripts/verify-npm-pack.mjs +12 -0
- package/x/bin/scripts/verify-publish-config.mjs +10 -0
- package/x/bin/scripts/verify-version-bump.mjs +27 -0
- package/x/bin/scripts/version-check.mjs +173 -0
- package/x/dist/index.js +1 -0
- package/x/dist/loader/clients/index.js +1 -0
- package/x/dist/loader/configs/index.js +1 -0
- package/{source → x/dist}/loader/controller/index.d.ts +20 -17
- package/x/dist/loader/controller/index.js +1 -0
- package/x/dist/loader/dto/index.js +1 -0
- package/x/dist/loader/events/index.js +1 -0
- package/x/dist/loader/index.d.ts +11 -0
- package/x/dist/loader/index.js +1 -0
- package/{source → x/dist}/loader/kafka/index.d.ts +1 -0
- package/x/dist/loader/kafka/index.js +1 -0
- package/x/dist/loader/localizations/index.js +1 -0
- package/{source → x/dist}/loader/logger/index.d.ts +1 -0
- package/x/dist/loader/logger/index.js +2 -0
- package/x/dist/loader/service/index.js +1 -0
- package/x/dist/loader/system/index.js +1 -0
- package/x/dist/project/index.d.ts +12 -0
- package/x/dist/project/index.js +1 -0
- package/x/dist/utils/constants/defaults.json +44 -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.js +1 -0
- package/x/dist/utils/helpers/context/index.js +1 -0
- package/{source → x/dist}/utils/helpers/core/index.d.ts +1 -1
- package/x/dist/utils/helpers/core/index.js +1 -0
- package/x/dist/utils/helpers/core/paths.js +1 -0
- package/x/dist/utils/helpers/core/tmp-layout.js +1 -0
- package/x/dist/utils/helpers/date/index.js +1 -0
- package/x/dist/utils/helpers/dispatch/index.js +1 -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.js +1 -0
- package/x/dist/utils/helpers/handlers/adapters.js +1 -0
- package/x/dist/utils/helpers/handlers/execute.js +1 -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.js +1 -0
- package/x/dist/utils/helpers/ip/index.js +1 -0
- package/x/dist/utils/helpers/is/index.js +1 -0
- package/x/dist/utils/helpers/locales/index.js +1 -0
- package/x/dist/utils/helpers/math/index.js +1 -0
- package/{source → x/dist}/utils/helpers/middleware/index.d.ts +2 -2
- 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/{source → x/dist}/utils/helpers/protocol/index.d.ts +2 -10
- package/x/dist/utils/helpers/protocol/index.js +1 -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.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-types.js +1 -0
- package/{source → x/dist}/utils/helpers/runtime/index.d.ts +1 -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.js +1 -0
- package/x/dist/utils/helpers/state/props-from-tmp.js +1 -0
- package/x/dist/utils/helpers/state/request-key-guard.js +1 -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/x/dist/utils/helpers/tests/tmp-watch.test.d.ts +1 -0
- 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.js +1 -0
- package/{source → x/dist}/utils/helpers/tmp/runtime-tmp.d.ts +2 -6
- package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -0
- package/{source → x/dist}/utils/helpers/tmp/tmp-loader.d.ts +1 -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.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/x/dist/utils/models/enums/index.js +1 -0
- package/x/dist/utils/models/index.js +1 -0
- package/x/dist/utils/models/types/index.js +1 -0
- package/x/dist/utils/package-root.js +1 -0
- package/x/tmp.yml +51 -42
- package/source/index.js +0 -11
- package/source/loader/clients/index.js +0 -22
- package/source/loader/configs/index.js +0 -88
- package/source/loader/controller/index.js +0 -236
- package/source/loader/dto/index.js +0 -92
- package/source/loader/events/index.js +0 -44
- package/source/loader/index.d.ts +0 -11
- package/source/loader/index.js +0 -11
- package/source/loader/kafka/index.js +0 -137
- package/source/loader/localizations/index.js +0 -46
- package/source/loader/logger/index.js +0 -217
- package/source/loader/service/index.js +0 -7
- package/source/loader/system/index.js +0 -25
- package/source/project/index.d.ts +0 -8
- package/source/project/index.js +0 -70
- package/source/utils/constants/defaults.json +0 -15
- package/source/utils/constants/defaults.mjs +0 -10
- package/source/utils/constants/index.js +0 -22
- package/source/utils/helpers/configs/index.js +0 -1
- package/source/utils/helpers/context/controller-store.js +0 -12
- package/source/utils/helpers/context/index.js +0 -24
- package/source/utils/helpers/core/index.js +0 -58
- package/source/utils/helpers/core/paths.js +0 -78
- package/source/utils/helpers/core/tmp-layout.js +0 -241
- package/source/utils/helpers/date/index.js +0 -48
- package/source/utils/helpers/dispatch/index.js +0 -53
- package/source/utils/helpers/dto/index.js +0 -10
- package/source/utils/helpers/filters/index.js +0 -44
- package/source/utils/helpers/framework/index.js +0 -17
- package/source/utils/helpers/handlers/adapters.js +0 -40
- package/source/utils/helpers/handlers/execute.js +0 -82
- package/source/utils/helpers/handlers/index.js +0 -31
- package/source/utils/helpers/hash/crypto.js +0 -22
- package/source/utils/helpers/id/index.js +0 -24
- package/source/utils/helpers/index.js +0 -26
- 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 -82
- package/source/utils/helpers/math/index.js +0 -14
- package/source/utils/helpers/middleware/index.js +0 -36
- package/source/utils/helpers/objects/index.js +0 -55
- package/source/utils/helpers/path/index.js +0 -4
- package/source/utils/helpers/protocol/index.js +0 -99
- package/source/utils/helpers/protocol/options.js +0 -13
- package/source/utils/helpers/regex/checkSpecialRegexControl.js +0 -3
- package/source/utils/helpers/runtime/dto-access.js +0 -5
- package/source/utils/helpers/runtime/index.js +0 -1
- package/source/utils/helpers/state/index.js +0 -185
- package/source/utils/helpers/state/props-from-tmp.js +0 -44
- package/source/utils/helpers/state/request-key-guard.js +0 -42
- package/source/utils/helpers/state/scopes.js +0 -69
- package/source/utils/helpers/string/index.js +0 -9
- package/source/utils/helpers/timer/index.js +0 -5
- package/source/utils/helpers/tmp/index.d.ts +0 -3
- package/source/utils/helpers/tmp/index.js +0 -3
- package/source/utils/helpers/tmp/loader-tmp-sync.js +0 -13
- package/source/utils/helpers/tmp/runtime-tmp.js +0 -30
- package/source/utils/helpers/tmp/tmp-loader.js +0 -48
- package/source/utils/helpers/validates/index.js +0 -20
- package/source/utils/index.js +0 -3
- package/source/utils/models/classes/class.clients.js +0 -142
- package/source/utils/models/classes/class.interfaces.js +0 -10
- 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 -180
- package/source/utils/models/enums/index.js +0 -148
- package/source/utils/models/index.js +0 -9
- package/source/utils/models/types/index.js +0 -2
- package/source/utils/models/types/shims.d.ts +0 -123
- package/source/utils/package-root.js +0 -5
- package/x/tests/cli.test.ts +0 -85
- package/x/tests/context.test.ts +0 -25
- package/x/tests/dispatch.test.ts +0 -84
- package/x/tests/fixtures/locales/en/translation.json +0 -8
- package/x/tests/fixtures/locales/tr/translation.json +0 -8
- package/x/tests/frameworks.integration.test.ts +0 -185
- package/x/tests/helpers/i18n-setup.ts +0 -52
- package/x/tests/helpers/middleware.ts +0 -23
- package/x/tests/helpers/register-test-dto.ts +0 -52
- package/x/tests/i18n.integration.test.ts +0 -77
- package/x/tests/i18n.test.ts +0 -96
- package/x/tests/middleware.test.ts +0 -83
- package/x/tests/project-layout.test.ts +0 -65
- package/x/tests/protocol.test.ts +0 -75
- package/x/tests/realtime.examples.test.ts +0 -198
- package/x/tests/runtime-tmp.test.ts +0 -49
- package/x/tests/socket.integration.test.ts +0 -174
- package/x/tests/state.test.ts +0 -183
- package/x/tests/tmp-layout-guard.test.ts +0 -40
- /package/{source → x/dist}/index.d.ts +0 -0
- /package/{source → x/dist}/loader/clients/index.d.ts +0 -0
- /package/{source → x/dist}/loader/configs/index.d.ts +0 -0
- /package/{source → x/dist}/loader/dto/index.d.ts +0 -0
- /package/{source → x/dist}/loader/events/index.d.ts +0 -0
- /package/{source → x/dist}/loader/localizations/index.d.ts +0 -0
- /package/{source → x/dist}/loader/service/index.d.ts +0 -0
- /package/{source → x/dist}/loader/system/index.d.ts +0 -0
- /package/{source → x/dist}/utils/constants/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/configs/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/context/controller-store.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/context/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/core/paths.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/core/tmp-layout.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/date/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/dispatch/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/dto/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/filters/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/framework/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/handlers/adapters.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/handlers/execute.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/handlers/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/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/locales/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/protocol/options.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/regex/checkSpecialRegexControl.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/runtime/dto-access.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/runtime/dto-types.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/state/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/state/props-from-tmp.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/state/request-key-guard.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/state/scopes.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/string/index.d.ts +0 -0
- /package/{source/utils/helpers/runtime/dto-types.js → 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/tmp/loader-tmp-sync.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/validates/index.d.ts +0 -0
- /package/{source → x/dist}/utils/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
- /package/{source → x/dist}/utils/models/enums/index.d.ts +0 -0
- /package/{source → x/dist}/utils/models/index.d.ts +0 -0
- /package/{source → x/dist}/utils/models/types/index.d.ts +0 -0
- /package/{source → x/dist}/utils/package-root.d.ts +0 -0
|
@@ -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
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readTmpServiceBlock } from './tmp-schema.mjs'
|
|
1
2
|
const PROTOCOL_ALIASES = {
|
|
2
3
|
http: 'http',
|
|
3
4
|
https: 'https',
|
|
@@ -22,20 +23,20 @@ export function resolveProtocolsFromConfig(configs = {}) {
|
|
|
22
23
|
|
|
23
24
|
export function summarizeLoaders(tmp = {}) {
|
|
24
25
|
const configs = tmp.configs ?? {}
|
|
25
|
-
const
|
|
26
|
+
const service = configs.service ?? readTmpServiceBlock(configs)
|
|
26
27
|
|
|
27
28
|
return {
|
|
28
|
-
framework:
|
|
29
|
-
protocols: resolveProtocolsFromConfig(
|
|
30
|
-
service:
|
|
29
|
+
framework: service.framework ?? 'elysia',
|
|
30
|
+
protocols: resolveProtocolsFromConfig(service),
|
|
31
|
+
service: service.name,
|
|
31
32
|
items: [
|
|
32
|
-
loaders
|
|
33
|
-
loaders
|
|
34
|
-
loaders
|
|
35
|
-
loaders
|
|
36
|
-
loaders
|
|
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 && {
|
|
37
38
|
key: 'controller',
|
|
38
|
-
detail: formatLoaderDetail(loaders
|
|
39
|
+
detail: formatLoaderDetail(service.loaders?.controller),
|
|
39
40
|
},
|
|
40
41
|
].filter(Boolean),
|
|
41
42
|
}
|
|
@@ -5,6 +5,7 @@ import yaml from 'yaml'
|
|
|
5
5
|
import { packageDefaults } from '../paths.mjs'
|
|
6
6
|
import { findAllFilesRecursively, findFileRecursively } from './index.mjs'
|
|
7
7
|
import { getBundledCoreTmpPath } from './project-root.mjs'
|
|
8
|
+
import { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, readTmpServiceBlock, resolveServiceLayoutPaths } from './tmp-schema.mjs'
|
|
8
9
|
|
|
9
10
|
const DEFAULT_PATHS = packageDefaults.layoutPaths
|
|
10
11
|
|
|
@@ -93,10 +94,11 @@ function resolveTmpFilePath(projectRoot, tmpFileName, ext) {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
export function resolveRootFolderPath(tmp, tmpFilePath, projectRoot) {
|
|
96
|
-
const configs = tmp
|
|
97
|
+
const configs = normalizeTmpDocument(tmp ?? {}).configs ?? {}
|
|
98
|
+
const service = readTmpServiceBlock(configs)
|
|
97
99
|
|
|
98
|
-
if (
|
|
99
|
-
return
|
|
100
|
+
if (service.paths?.root?.trim()) {
|
|
101
|
+
return normalizeRootFolder(service.paths.root)
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
if (typeof tmp?.project?.name === 'string' && tmp.project.name.trim()) {
|
|
@@ -115,28 +117,20 @@ export function resolveRootFolderPath(tmp, tmpFilePath, projectRoot) {
|
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
export function resolveLayoutPaths(configs) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return {
|
|
121
|
-
tests: typeof paths.tests === 'string' && paths.tests.trim() ? paths.tests.trim() : DEFAULT_PATHS.tests,
|
|
122
|
-
environments:
|
|
123
|
-
typeof paths.environments === 'string' && paths.environments.trim()
|
|
124
|
-
? paths.environments.trim()
|
|
125
|
-
: DEFAULT_PATHS.environments,
|
|
126
|
-
dist: typeof paths.dist === 'string' && paths.dist.trim() ? paths.dist.trim() : DEFAULT_PATHS.dist,
|
|
127
|
-
}
|
|
120
|
+
return resolveServiceLayoutPaths(readTmpServiceBlock(configs))
|
|
128
121
|
}
|
|
129
122
|
|
|
130
123
|
export function resolveMainFolderPath(configs) {
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
const source = readTmpServiceBlock(configs).paths?.source
|
|
125
|
+
if (typeof source === 'string' && source.trim()) {
|
|
126
|
+
return normalizeSourceFolder(source)
|
|
133
127
|
}
|
|
134
128
|
return packageDefaults.mainSourceFolder
|
|
135
129
|
}
|
|
136
130
|
|
|
137
131
|
export function buildTmpLayout(projectRoot, tmp, tmpFilePath) {
|
|
138
132
|
const resolvedRoot = path.resolve(projectRoot)
|
|
139
|
-
const configs = tmp
|
|
133
|
+
const configs = tmp ? normalizeTmpDocument(tmp).configs : undefined
|
|
140
134
|
const rootFolderPath = tmp && tmpFilePath && !isCorePackageRoot(resolvedRoot)
|
|
141
135
|
? resolveRootFolderPath(tmp, tmpFilePath, resolvedRoot)
|
|
142
136
|
: packageDefaults.packageRootFolder
|
|
@@ -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
|
+
}
|
package/x/bin/main-cli.js
CHANGED
|
@@ -3,17 +3,26 @@
|
|
|
3
3
|
import { Command } from 'commander'
|
|
4
4
|
import chalk from 'chalk'
|
|
5
5
|
|
|
6
|
-
import { Constants } from './constants/index.mjs'
|
|
7
6
|
import { registerCreateCommand } from './commands/create.mjs'
|
|
8
7
|
import { registerDoctorCommand } from './commands/doctor.mjs'
|
|
9
8
|
import { registerProjectCommands } from './commands/project.mjs'
|
|
10
9
|
import { registerTmpCommand } from './commands/tmp.mjs'
|
|
10
|
+
import { registerSyncToolchainCommand } from './commands/sync-toolchain.mjs'
|
|
11
11
|
import { registerTagCommand, registerVersionCommand } from './commands/release.mjs'
|
|
12
|
+
import { registerHooksCommand } from './commands/hooks.mjs'
|
|
12
13
|
import { printBanner, shouldShowBanner } from './helpers/banner.mjs'
|
|
14
|
+
import { formatRootHelp, formatCreateCommandHelp, isCreateHelpRequest, isRootHelpRequest, printQuickStartGuide } from './helpers/cli-help.mjs'
|
|
13
15
|
import { resolveInvokedAs } from './helpers/cli-identity.mjs'
|
|
14
|
-
import { readCliPackageJson } from './helpers/project-root.mjs'
|
|
16
|
+
import { readCliPackageJson, getProjectRoot } from './helpers/project-root.mjs'
|
|
17
|
+
import { ensureProjectArtifacts } from './helpers/project-artifacts.mjs'
|
|
15
18
|
|
|
16
19
|
const pkg = readCliPackageJson()
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
ensureProjectArtifacts(getProjectRoot(), { writeToolchain: false, writeManifest: false })
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
|
|
17
26
|
const cliName = resolveInvokedAs()
|
|
18
27
|
|
|
19
28
|
const isBun = !!process.versions.bun
|
|
@@ -27,18 +36,37 @@ if (shouldShowBanner()) {
|
|
|
27
36
|
printBanner({ version: pkg.version, runtimeName, invokedAs: cliName })
|
|
28
37
|
}
|
|
29
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
|
+
|
|
30
49
|
const cli = new Command()
|
|
31
50
|
|
|
32
51
|
cli
|
|
33
52
|
.name(cliName)
|
|
34
|
-
.description(
|
|
53
|
+
.description('xrystal core — microservice runtime library')
|
|
35
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
|
+
})
|
|
36
62
|
|
|
37
63
|
registerCreateCommand(cli, cliContext)
|
|
38
64
|
registerVersionCommand(cli, cliContext)
|
|
39
65
|
registerTagCommand(cli, cliContext)
|
|
40
66
|
registerDoctorCommand(cli, cliContext)
|
|
41
67
|
registerTmpCommand(cli, cliContext)
|
|
68
|
+
registerSyncToolchainCommand(cli, cliContext)
|
|
69
|
+
registerHooksCommand(cli, cliContext)
|
|
42
70
|
registerProjectCommands(cli, cliContext)
|
|
43
71
|
|
|
44
72
|
cli.parseAsync(process.argv).catch((error) => {
|
|
@@ -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)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
const distRoot = path.join(process.cwd(), 'x', 'dist')
|
|
5
|
+
|
|
6
|
+
const HAS_EXT = /\.(js|mjs|cjs|json|node|wasm)(\?.*)?$/i
|
|
7
|
+
|
|
8
|
+
function walkJsFiles(dir, out = []) {
|
|
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()) {
|
|
13
|
+
walkJsFiles(abs, out)
|
|
14
|
+
continue
|
|
15
|
+
}
|
|
16
|
+
if (name.endsWith('.js')) out.push(abs)
|
|
17
|
+
}
|
|
18
|
+
return out
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function fixRelativeSpecifier(fileDir, specifier) {
|
|
22
|
+
if (!specifier.startsWith('.')) return specifier
|
|
23
|
+
if (HAS_EXT.test(specifier)) return specifier
|
|
24
|
+
|
|
25
|
+
const resolved = path.resolve(fileDir, specifier)
|
|
26
|
+
const asFile = `${resolved}.js`
|
|
27
|
+
if (fs.existsSync(asFile)) {
|
|
28
|
+
return HAS_EXT.test(specifier) ? specifier : `${specifier}.js`
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const indexFile = path.join(resolved, 'index.js')
|
|
32
|
+
if (fs.existsSync(indexFile)) {
|
|
33
|
+
const normalized = specifier.replace(/\/+$/, '')
|
|
34
|
+
return `${normalized}/index.js`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return `${specifier}.js`
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
function fixJsonImportAttributes(source) {
|
|
42
|
+
return source.replace(
|
|
43
|
+
/(from\s*)(['"])([^'"]+\.json)\2(?!\s+with\b)/g,
|
|
44
|
+
(match, fromKw, quote, spec) => `${fromKw}${quote}${spec}${quote} with { type: 'json' }`,
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function fixImportSpecifiersInSource(source, fileDir) {
|
|
49
|
+
return source.replace(/(['"])(\.\.?\/[^'"]+?)\1/g, (match, quote, spec) => {
|
|
50
|
+
const fixed = fixRelativeSpecifier(fileDir, spec)
|
|
51
|
+
return fixed === spec ? match : `${quote}${fixed}${quote}`
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function fixDistImports(distDir = distRoot) {
|
|
56
|
+
if (!fs.existsSync(distDir)) {
|
|
57
|
+
throw new Error(`dist directory not found: ${distDir}`)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let filesChanged = 0
|
|
61
|
+
const jsFiles = walkJsFiles(distDir)
|
|
62
|
+
for (const file of jsFiles) {
|
|
63
|
+
const before = fs.readFileSync(file, 'utf8')
|
|
64
|
+
const after = fixJsonImportAttributes(fixImportSpecifiersInSource(before, path.dirname(file)))
|
|
65
|
+
if (after !== before) {
|
|
66
|
+
fs.writeFileSync(file, after)
|
|
67
|
+
filesChanged++
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { filesChanged, jsFileCount: jsFiles.length }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const invoked = process.argv[1] ? path.resolve(process.argv[1]) : ''
|
|
74
|
+
const isMain = invoked === path.resolve('x/bin/scripts/fix-dist-imports.mjs')
|
|
75
|
+
|| invoked.endsWith(`${path.sep}fix-dist-imports.mjs`)
|
|
76
|
+
|
|
77
|
+
if (isMain) {
|
|
78
|
+
const result = fixDistImports()
|
|
79
|
+
console.log(`fix-dist-imports: updated ${result.filesChanged} file(s), ${result.jsFileCount} .js total`)
|
|
80
|
+
}
|