@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.
Files changed (233) hide show
  1. package/README.md +2331 -21
  2. package/package.json +66 -24
  3. package/tsconfig.base.json +15 -0
  4. package/x/bin/commands/create.mjs +136 -0
  5. package/x/bin/commands/doctor.mjs +149 -0
  6. package/x/bin/commands/hooks.mjs +55 -0
  7. package/x/bin/commands/project.mjs +126 -0
  8. package/x/bin/commands/release.mjs +66 -0
  9. package/x/bin/commands/sync-toolchain.mjs +43 -0
  10. package/x/bin/commands/tmp.mjs +57 -0
  11. package/x/bin/constants/index.mjs +6 -0
  12. package/x/bin/helpers/.generated/.generated-from +1 -0
  13. package/x/bin/helpers/.generated/tmp-schema.mjs +192 -0
  14. package/x/bin/helpers/banner.mjs +80 -0
  15. package/x/bin/helpers/build-config.mjs +342 -0
  16. package/x/bin/helpers/cli-help.mjs +164 -0
  17. package/x/bin/helpers/cli-identity.mjs +17 -0
  18. package/x/bin/helpers/create-target.mjs +35 -0
  19. package/{bin → x/bin}/helpers/index.mjs +44 -1
  20. package/x/bin/helpers/project-artifacts.mjs +140 -0
  21. package/x/bin/helpers/project-root.mjs +70 -0
  22. package/x/bin/helpers/runtime-info.mjs +172 -0
  23. package/x/bin/helpers/tmp-config.mjs +67 -0
  24. package/x/bin/helpers/tmp-layout.mjs +281 -0
  25. package/x/bin/helpers/tmp-schema.mjs +9 -0
  26. package/x/bin/helpers/toolchain-config.mjs +233 -0
  27. package/x/bin/main-cli.js +80 -0
  28. package/x/bin/paths.mjs +14 -0
  29. package/x/bin/scripts/clean-source-types.mjs +19 -0
  30. package/x/bin/scripts/fix-dist-imports.mjs +80 -0
  31. package/x/bin/scripts/install-git-hooks.mjs +86 -0
  32. package/x/bin/scripts/minify-dist.mjs +50 -0
  33. package/x/bin/scripts/prepare-npm-publish.mjs +49 -0
  34. package/x/bin/scripts/release-prepare.mjs +56 -0
  35. package/x/bin/scripts/tag.mjs +17 -0
  36. package/x/bin/scripts/unpublish-leaked-versions.mjs +62 -0
  37. package/x/bin/scripts/verify-npm-pack.mjs +45 -0
  38. package/x/bin/scripts/verify-version-bump.mjs +27 -0
  39. package/x/bin/scripts/version-check.mjs +370 -0
  40. package/x/dist/index.d.ts +3 -0
  41. package/x/dist/index.js +1 -0
  42. package/{source → x/dist}/loader/clients/index.d.ts +2 -1
  43. package/x/dist/loader/clients/index.js +1 -0
  44. package/{source → x/dist}/loader/configs/index.d.ts +3 -2
  45. package/x/dist/loader/configs/index.js +1 -0
  46. package/x/dist/loader/controller/index.d.ts +69 -0
  47. package/x/dist/loader/controller/index.js +1 -0
  48. package/x/dist/loader/dto/index.d.ts +39 -0
  49. package/x/dist/loader/dto/index.js +1 -0
  50. package/{source → x/dist}/loader/events/index.d.ts +1 -1
  51. package/x/dist/loader/events/index.js +1 -0
  52. package/{source → x/dist}/loader/index.d.ts +2 -1
  53. package/x/dist/loader/index.js +1 -0
  54. package/{source → x/dist}/loader/kafka/index.d.ts +6 -3
  55. package/x/dist/loader/kafka/index.js +1 -0
  56. package/{source → x/dist}/loader/localizations/index.d.ts +4 -3
  57. package/x/dist/loader/localizations/index.js +1 -0
  58. package/{source → x/dist}/loader/logger/index.d.ts +10 -7
  59. package/x/dist/loader/logger/index.js +2 -0
  60. package/x/dist/loader/service/index.js +1 -0
  61. package/{source → x/dist}/loader/system/index.d.ts +4 -3
  62. package/x/dist/loader/system/index.js +1 -0
  63. package/{source → x/dist}/project/index.d.ts +2 -2
  64. package/x/dist/project/index.js +1 -0
  65. package/x/dist/utils/constants/defaults.json +44 -0
  66. package/x/dist/utils/constants/index.d.ts +27 -0
  67. package/x/dist/utils/constants/index.js +1 -0
  68. package/x/dist/utils/helpers/configs/index.js +1 -0
  69. package/x/dist/utils/helpers/context/controller-store.d.ts +51 -0
  70. package/x/dist/utils/helpers/context/controller-store.js +1 -0
  71. package/x/dist/utils/helpers/context/index.d.ts +18 -0
  72. package/x/dist/utils/helpers/context/index.js +1 -0
  73. package/{source → x/dist}/utils/helpers/core/index.d.ts +8 -6
  74. package/x/dist/utils/helpers/core/index.js +1 -0
  75. package/x/dist/utils/helpers/core/paths.d.ts +2 -0
  76. package/x/dist/utils/helpers/core/paths.js +1 -0
  77. package/x/dist/utils/helpers/core/tmp-layout.d.ts +45 -0
  78. package/x/dist/utils/helpers/core/tmp-layout.js +1 -0
  79. package/{source → x/dist}/utils/helpers/date/index.d.ts +1 -1
  80. package/x/dist/utils/helpers/date/index.js +1 -0
  81. package/x/dist/utils/helpers/dispatch/index.d.ts +9 -0
  82. package/x/dist/utils/helpers/dispatch/index.js +1 -0
  83. package/x/dist/utils/helpers/dto/index.d.ts +10 -0
  84. package/x/dist/utils/helpers/dto/index.js +1 -0
  85. package/x/dist/utils/helpers/filters/index.js +1 -0
  86. package/x/dist/utils/helpers/framework/index.d.ts +3 -0
  87. package/x/dist/utils/helpers/framework/index.js +1 -0
  88. package/x/dist/utils/helpers/handlers/adapters.d.ts +10 -0
  89. package/x/dist/utils/helpers/handlers/adapters.js +1 -0
  90. package/x/dist/utils/helpers/handlers/execute.d.ts +5 -0
  91. package/x/dist/utils/helpers/handlers/execute.js +1 -0
  92. package/x/dist/utils/helpers/handlers/index.d.ts +18 -0
  93. package/x/dist/utils/helpers/handlers/index.js +1 -0
  94. package/x/dist/utils/helpers/hash/crypto.js +1 -0
  95. package/x/dist/utils/helpers/id/index.js +1 -0
  96. package/x/dist/utils/helpers/index.d.ts +26 -0
  97. package/x/dist/utils/helpers/index.js +1 -0
  98. package/x/dist/utils/helpers/ip/index.js +1 -0
  99. package/x/dist/utils/helpers/is/index.js +1 -0
  100. package/{source → x/dist}/utils/helpers/locales/index.d.ts +1 -0
  101. package/x/dist/utils/helpers/locales/index.js +1 -0
  102. package/x/dist/utils/helpers/math/index.js +1 -0
  103. package/x/dist/utils/helpers/middleware/index.d.ts +19 -0
  104. package/x/dist/utils/helpers/middleware/index.js +1 -0
  105. package/x/dist/utils/helpers/objects/index.js +1 -0
  106. package/x/dist/utils/helpers/path/index.js +1 -0
  107. package/x/dist/utils/helpers/protocol/index.d.ts +20 -0
  108. package/x/dist/utils/helpers/protocol/index.js +1 -0
  109. package/x/dist/utils/helpers/protocol/options.d.ts +6 -0
  110. package/x/dist/utils/helpers/protocol/options.js +1 -0
  111. package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +1 -0
  112. package/x/dist/utils/helpers/runtime/dto-access.d.ts +3 -0
  113. package/x/dist/utils/helpers/runtime/dto-access.js +1 -0
  114. package/x/dist/utils/helpers/runtime/dto-types.d.ts +19 -0
  115. package/x/dist/utils/helpers/runtime/dto-types.js +1 -0
  116. package/x/dist/utils/helpers/runtime/index.d.ts +3 -0
  117. package/x/dist/utils/helpers/runtime/index.js +1 -0
  118. package/x/dist/utils/helpers/runtime/shutdown.d.ts +3 -0
  119. package/x/dist/utils/helpers/runtime/shutdown.js +1 -0
  120. package/x/dist/utils/helpers/state/index.d.ts +59 -0
  121. package/x/dist/utils/helpers/state/index.js +1 -0
  122. package/x/dist/utils/helpers/state/props-from-tmp.d.ts +9 -0
  123. package/x/dist/utils/helpers/state/props-from-tmp.js +1 -0
  124. package/x/dist/utils/helpers/state/request-key-guard.d.ts +3 -0
  125. package/x/dist/utils/helpers/state/request-key-guard.js +1 -0
  126. package/x/dist/utils/helpers/state/scopes.d.ts +21 -0
  127. package/x/dist/utils/helpers/state/scopes.js +1 -0
  128. package/x/dist/utils/helpers/string/index.js +1 -0
  129. package/x/dist/utils/helpers/tests/tmp-schema.test.js +1 -0
  130. package/{source/utils/models/types/index.js → x/dist/utils/helpers/tests/tmp-watch.test.d.ts} +0 -1
  131. package/x/dist/utils/helpers/tests/tmp-watch.test.js +1 -0
  132. package/x/dist/utils/helpers/timer/index.js +1 -0
  133. package/x/dist/utils/helpers/tmp/index.d.ts +5 -0
  134. package/x/dist/utils/helpers/tmp/index.js +1 -0
  135. package/x/dist/utils/helpers/tmp/loader-tmp-sync.d.ts +4 -0
  136. package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +1 -0
  137. package/x/dist/utils/helpers/tmp/runtime-tmp.d.ts +9 -0
  138. package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -0
  139. package/x/dist/utils/helpers/tmp/tmp-loader.d.ts +7 -0
  140. package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -0
  141. package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +47 -0
  142. package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -0
  143. package/x/dist/utils/helpers/tmp/tmp-watch.d.ts +1 -0
  144. package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -0
  145. package/x/dist/utils/helpers/validates/index.js +1 -0
  146. package/x/dist/utils/index.d.ts +3 -0
  147. package/x/dist/utils/index.js +1 -0
  148. package/x/dist/utils/models/classes/class.clients.js +1 -0
  149. package/x/dist/utils/models/classes/class.interfaces.js +1 -0
  150. package/x/dist/utils/models/classes/class.service-locator.js +1 -0
  151. package/{source → x/dist}/utils/models/classes/class.tmp-file-loader.d.ts +3 -2
  152. package/x/dist/utils/models/classes/class.tmp-file-loader.js +1 -0
  153. package/x/dist/utils/models/classes/class.x.js +1 -0
  154. package/{source → x/dist}/utils/models/enums/index.d.ts +14 -1
  155. package/x/dist/utils/models/enums/index.js +1 -0
  156. package/x/dist/utils/models/index.d.ts +9 -0
  157. package/x/dist/utils/models/index.js +1 -0
  158. package/x/dist/utils/models/types/index.d.ts +5 -0
  159. package/x/dist/utils/models/types/index.js +1 -0
  160. package/x/dist/utils/package-root.d.ts +2 -0
  161. package/x/dist/utils/package-root.js +1 -0
  162. package/x/tmp.yml +48 -17
  163. package/bin/constants/index.mjs +0 -17
  164. package/bin/main-cli.js +0 -131
  165. package/source/index.js +0 -6
  166. package/source/loader/clients/index.js +0 -18
  167. package/source/loader/configs/index.js +0 -81
  168. package/source/loader/controller/index.d.ts +0 -129
  169. package/source/loader/controller/index.js +0 -327
  170. package/source/loader/events/index.js +0 -44
  171. package/source/loader/index.js +0 -10
  172. package/source/loader/kafka/index.js +0 -122
  173. package/source/loader/localizations/index.js +0 -40
  174. package/source/loader/logger/index.js +0 -183
  175. package/source/loader/service/index.js +0 -7
  176. package/source/loader/system/index.js +0 -19
  177. package/source/project/index.js +0 -66
  178. package/source/utils/constants/index.d.ts +0 -10
  179. package/source/utils/constants/index.js +0 -11
  180. package/source/utils/helpers/configs/index.js +0 -1
  181. package/source/utils/helpers/core/index.js +0 -105
  182. package/source/utils/helpers/date/index.js +0 -48
  183. package/source/utils/helpers/filters/index.js +0 -44
  184. package/source/utils/helpers/hash/crypto.js +0 -22
  185. package/source/utils/helpers/id/index.js +0 -24
  186. package/source/utils/helpers/index.d.ts +0 -17
  187. package/source/utils/helpers/index.js +0 -17
  188. package/source/utils/helpers/ip/index.js +0 -21
  189. package/source/utils/helpers/is/index.js +0 -35
  190. package/source/utils/helpers/locales/index.js +0 -63
  191. package/source/utils/helpers/math/index.js +0 -14
  192. package/source/utils/helpers/middlewares/index.d.ts +0 -1
  193. package/source/utils/helpers/middlewares/index.js +0 -26
  194. package/source/utils/helpers/objects/index.js +0 -55
  195. package/source/utils/helpers/path/index.js +0 -4
  196. package/source/utils/helpers/regex/checkSpecialRegexControl.js +0 -3
  197. package/source/utils/helpers/string/index.js +0 -9
  198. package/source/utils/helpers/timer/index.js +0 -5
  199. package/source/utils/helpers/validates/index.js +0 -20
  200. package/source/utils/index.d.ts +0 -3
  201. package/source/utils/index.js +0 -3
  202. package/source/utils/models/classes/class.clients.js +0 -142
  203. package/source/utils/models/classes/class.dtos.d.ts +0 -47
  204. package/source/utils/models/classes/class.dtos.js +0 -36
  205. package/source/utils/models/classes/class.interfaces.js +0 -10
  206. package/source/utils/models/classes/class.response.d.ts +0 -17
  207. package/source/utils/models/classes/class.response.js +0 -35
  208. package/source/utils/models/classes/class.service-locator.js +0 -16
  209. package/source/utils/models/classes/class.tmp-file-loader.js +0 -38
  210. package/source/utils/models/classes/class.x.js +0 -179
  211. package/source/utils/models/enums/index.js +0 -133
  212. package/source/utils/models/index.d.ts +0 -11
  213. package/source/utils/models/index.js +0 -11
  214. package/source/utils/models/types/index.d.ts +0 -3
  215. /package/{source → x/dist}/loader/service/index.d.ts +0 -0
  216. /package/{source → x/dist}/utils/helpers/configs/index.d.ts +0 -0
  217. /package/{source → x/dist}/utils/helpers/filters/index.d.ts +0 -0
  218. /package/{source → x/dist}/utils/helpers/hash/crypto.d.ts +0 -0
  219. /package/{source → x/dist}/utils/helpers/id/index.d.ts +0 -0
  220. /package/{source → x/dist}/utils/helpers/ip/index.d.ts +0 -0
  221. /package/{source → x/dist}/utils/helpers/is/index.d.ts +0 -0
  222. /package/{source → x/dist}/utils/helpers/math/index.d.ts +0 -0
  223. /package/{source → x/dist}/utils/helpers/objects/index.d.ts +0 -0
  224. /package/{source → x/dist}/utils/helpers/path/index.d.ts +0 -0
  225. /package/{source → x/dist}/utils/helpers/regex/checkSpecialRegexControl.d.ts +0 -0
  226. /package/{source → x/dist}/utils/helpers/string/index.d.ts +0 -0
  227. /package/{source/index.d.ts → x/dist/utils/helpers/tests/tmp-schema.test.d.ts} +0 -0
  228. /package/{source → x/dist}/utils/helpers/timer/index.d.ts +0 -0
  229. /package/{source → x/dist}/utils/helpers/validates/index.d.ts +0 -0
  230. /package/{source → x/dist}/utils/models/classes/class.clients.d.ts +0 -0
  231. /package/{source → x/dist}/utils/models/classes/class.interfaces.d.ts +0 -0
  232. /package/{source → x/dist}/utils/models/classes/class.service-locator.d.ts +0 -0
  233. /package/{source → x/dist}/utils/models/classes/class.x.d.ts +0 -0
@@ -0,0 +1,66 @@
1
+ import chalk from 'chalk'
2
+ import { readCliPackageJson, readProjectPackageJson, getProjectRoot } from '../helpers/project-root.mjs'
3
+ import { compareSemver, getVersionState, resolveVersionBaseline, runTagRelease } from '../scripts/version-check.mjs'
4
+
5
+ export function registerTagCommand(cli, { cliName = 'xcore' } = {}) {
6
+ cli
7
+ .command('tag')
8
+ .description('Git tag from package.json (+ npm publish for core)')
9
+ .option('--dry-run', 'Print commands without executing')
10
+ .option('--strict-clean', 'Require fully clean working tree (default: only package.json must be committed)')
11
+ .option('--skip-prepare', 'Skip lint, test, and build:prod (core only)')
12
+ .action(async (options) => {
13
+ try {
14
+ await runTagRelease({
15
+ dryRun: options.dryRun,
16
+ requireClean: options.strictClean,
17
+ skipPrepare: options.skipPrepare,
18
+ root: getProjectRoot(),
19
+ })
20
+ if (!options.dryRun) {
21
+ console.log(chalk.green('\n✓ Tag pushed.\n'))
22
+ }
23
+ } catch (error) {
24
+ console.error(chalk.red(`\n✗ ${error.message}\n`))
25
+ process.exit(1)
26
+ }
27
+ })
28
+ }
29
+
30
+ export function registerVersionCommand(cli, { cliName = 'xcore' } = {}) {
31
+ cli
32
+ .command('version')
33
+ .description('Show CLI and project package versions')
34
+ .action(() => {
35
+ try {
36
+ const root = getProjectRoot()
37
+ const cliPkg = readCliPackageJson()
38
+ const projectPkg = readProjectPackageJson(root)
39
+ const state = getVersionState('HEAD', root)
40
+
41
+ console.log(chalk.cyan(`\n${cliName} version\n`))
42
+ console.log(chalk.gray(' CLI (tool)'))
43
+ console.log(` @xrystal/core: ${chalk.bold(`${cliPkg.name}@${cliPkg.version}`)}`)
44
+ console.log('')
45
+ console.log(chalk.gray(' Project'))
46
+ console.log(` root: ${root}`)
47
+ console.log(` name: ${chalk.bold(projectPkg.name)}`)
48
+ console.log(` package.json (disk): ${chalk.bold(state.disk.version)}`)
49
+ console.log(` package.json (HEAD): ${chalk.bold(state.committed.version)}`)
50
+ console.log(` git tag name: ${chalk.bold(`v${state.committed.version}`)}`)
51
+ console.log(` branch: ${state.branch}`)
52
+ console.log(` version match: ${state.versionMatch ? chalk.green('yes') : chalk.red('no')}`)
53
+ console.log(` package.json committed: ${state.isPackageJsonClean ? chalk.green('yes') : chalk.red('no')}`)
54
+ const { baselineVersion, baselineLabel } = resolveVersionBaseline(root)
55
+ if (baselineVersion) {
56
+ const bumpOk = compareSemver(state.committed.version, baselineVersion) > 0
57
+ console.log(` bump vs ${baselineLabel}: ${bumpOk ? chalk.green('ok') : chalk.red('must be > ' + baselineVersion)}`)
58
+ }
59
+ console.log(` working tree: ${state.isClean ? chalk.green('clean') : chalk.yellow('dirty')}`)
60
+ console.log('')
61
+ } catch (error) {
62
+ console.error(chalk.red(`\n✗ ${error.message}\n`))
63
+ process.exit(1)
64
+ }
65
+ })
66
+ }
@@ -0,0 +1,43 @@
1
+ import chalk from 'chalk'
2
+ import { printCommandHeader } from '../helpers/banner.mjs'
3
+ import { readCliPackageJson } from '../helpers/project-root.mjs'
4
+
5
+ import { syncProjectToolchain, auditTsconfigAlignment } from '../helpers/toolchain-config.mjs'
6
+ import { getProjectRoot } from '../helpers/project-root.mjs'
7
+
8
+ export function registerSyncToolchainCommand(cli, { cliName = 'xcore' } = {}) {
9
+ cli
10
+ .command('sync-toolchain')
11
+ .description('Sync tsconfig paths from tmp.yml layout')
12
+ .option('--dry-run', 'Show changes without writing tsconfig.json')
13
+ .action((options) => {
14
+ const root = getProjectRoot()
15
+ const auditBefore = auditTsconfigAlignment(root)
16
+
17
+ printCommandHeader({ cliName, command: 'sync-toolchain', version: readCliPackageJson().version })
18
+ console.log(chalk.gray(` root: ${root}`))
19
+
20
+ const lo = auditBefore.layoutOptions ?? {}
21
+ console.log(chalk.gray(' tmp.yml layout:'))
22
+ console.log(chalk.gray(` paths.root: ${lo.rootFolderPath ?? 'x'}`))
23
+ console.log(chalk.gray(` paths.source: ${lo.mainFolderPath ?? './source'}`))
24
+ console.log(chalk.gray(` paths.dist: ${lo.pathsDist ?? 'dist'}`))
25
+
26
+ if (options.dryRun) {
27
+ const preview = syncProjectToolchain(root, { write: false })
28
+ console.log(chalk.gray('\n would write tsconfig.json:'))
29
+ console.log(chalk.gray(` include: ${JSON.stringify(preview.merged.include)}`))
30
+ console.log(chalk.gray(` outDir: ${preview.merged.compilerOptions.outDir}`))
31
+ console.log(chalk.gray(` paths: ${JSON.stringify(preview.merged.compilerOptions.paths)}`))
32
+ console.log(chalk.gray(`\n bunfig.toml → ${preview.paths.bunfigAliasLine}\n`))
33
+ return
34
+ }
35
+
36
+ const result = syncProjectToolchain(root, { write: true })
37
+ console.log(result.created ? chalk.green(` created ${result.tsconfigRel}`) : chalk.green(` updated ${result.tsconfigRel}`))
38
+ console.log(chalk.gray(` include → ${JSON.stringify(result.merged.include)}`))
39
+ console.log(chalk.gray(` outDir → ${result.merged.compilerOptions.outDir}`))
40
+ console.log(chalk.gray(` eslint → ${result.paths.eslintFiles.join(', ')}`))
41
+ console.log(chalk.yellow(`\n bunfig.toml [resolve.alias]: ${result.paths.bunfigAliasLine}\n`))
42
+ })
43
+ }
@@ -0,0 +1,57 @@
1
+ import fs from 'node:fs'
2
+ import chalk from 'chalk'
3
+ import yaml from 'yaml'
4
+
5
+ import { printCommandHeader } from '../helpers/banner.mjs'
6
+ import { resolveObjWithHandlebars } from '../helpers/index.mjs'
7
+ import { getProjectRoot, readCliPackageJson } from '../helpers/project-root.mjs'
8
+ import {
9
+ ensureTmpFile,
10
+ ownerTmpFilePath,
11
+ relativeFromRoot,
12
+ resolveTmpLayoutOrDefaults,
13
+ } from '../helpers/tmp-layout.mjs'
14
+ import { formatLoaderSummary, summarizeLoaders } from '../helpers/tmp-config.mjs'
15
+
16
+ export function registerTmpCommand(cli, { cliName = 'xcore' } = {}) {
17
+ cli
18
+ .command('tmp')
19
+ .description('Ensure tmp.yml exists (seed from @xrystal/core)')
20
+ .option('--dry-run', 'Show target path without writing')
21
+ .action((options) => {
22
+ const root = getProjectRoot()
23
+ const version = readCliPackageJson().version
24
+
25
+ if (options.dryRun) {
26
+ const layout = resolveTmpLayoutOrDefaults(root)
27
+ const target = layout.tmpFilePath ?? ownerTmpFilePath(root, layout)
28
+ const exists = fs.existsSync(target)
29
+
30
+ printCommandHeader({ cliName, command: 'tmp (dry-run)', version })
31
+ console.log(chalk.gray(` root: ${root}`))
32
+ console.log(` ${exists ? 'exists' : 'would create'}: ${target}`)
33
+ console.log('')
34
+ return
35
+ }
36
+
37
+ const result = ensureTmpFile(root)
38
+ const rel = relativeFromRoot(root, result.tmpFilePath)
39
+
40
+ printCommandHeader({ cliName, command: 'tmp', version })
41
+ console.log(chalk.gray(` root: ${root}`))
42
+ console.log(result.created ? chalk.green(` created ${rel}`) : chalk.gray(` ok ${rel}`))
43
+
44
+ try {
45
+ const tmp = yaml.parse(fs.readFileSync(result.tmpFilePath, 'utf8'))
46
+ const summary = summarizeLoaders(resolveObjWithHandlebars(tmp, tmp))
47
+ console.log(chalk.gray(` root: ${result.layout.rootFolderPath} · service: ${summary.service ?? '-'}`))
48
+ if (summary.items?.length) {
49
+ console.log(chalk.gray(` loaders: ${formatLoaderSummary(summary)}`))
50
+ }
51
+ } catch {
52
+ // summary optional
53
+ }
54
+
55
+ console.log('')
56
+ })
57
+ }
@@ -0,0 +1,6 @@
1
+ export {
2
+ packageDefaults,
3
+ packageDefaults as Constants,
4
+ coreVersionPattern,
5
+ semverVersionPattern,
6
+ } from '../paths.mjs'
@@ -0,0 +1 @@
1
+ source/utils/helpers/tmp/tmp-schema.ts
@@ -0,0 +1,192 @@
1
+ // source/utils/constants/index.ts
2
+ import path2 from "node:path";
3
+
4
+ // source/utils/package-root.ts
5
+ import path from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ var utilsDir = path.dirname(fileURLToPath(import.meta.url));
8
+ var sourceDir = path.resolve(utilsDir, "..");
9
+ var packageRootDir = path.resolve(utilsDir, "..", "..");
10
+ // source/utils/constants/defaults.json
11
+ var defaults_default = {
12
+ packageName: "@xrystal/core",
13
+ packageRootFolder: "x",
14
+ tmpBaseName: "tmp",
15
+ tmpExtension: ".yml",
16
+ mainSourceFolder: "./source",
17
+ layoutPaths: {
18
+ tests: "tests",
19
+ environments: "environments",
20
+ dist: "dist"
21
+ },
22
+ buildDefaults: {
23
+ tsconfig: "tsconfig.json",
24
+ typecheck: false,
25
+ tscLenient: false,
26
+ declarations: false,
27
+ sourcemap: false,
28
+ minify: false
29
+ },
30
+ tsconfigDefaults: {
31
+ pathAliasKey: "@/*",
32
+ compilerOptions: {
33
+ noEmit: false,
34
+ noEmitOnError: false,
35
+ declaration: true,
36
+ emitDeclarationOnly: false,
37
+ sourceMap: false,
38
+ declarationMap: false,
39
+ strict: true,
40
+ noImplicitAny: true
41
+ }
42
+ },
43
+ eslintDefaults: {
44
+ restrictedImportDepth: 2
45
+ },
46
+ tmpWatchDefaults: {
47
+ intervalMs: 500,
48
+ minIntervalMs: 100,
49
+ maxIntervalMs: 1e4
50
+ },
51
+ publicFolderName: "public",
52
+ kafkaLogsTopic: "log",
53
+ templateRepoUri: "https://github.com/xdloper/api-gpt-svc"
54
+ };
55
+
56
+ // source/utils/constants/index.ts
57
+ var packageDefaults = Object.freeze({
58
+ ...defaults_default,
59
+ layoutPaths: Object.freeze({ ...defaults_default.layoutPaths })
60
+ });
61
+ var tmpFileName = `${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;
62
+
63
+ class Constants {
64
+ static packageName = packageDefaults.packageName;
65
+ static packageRootFolder = packageDefaults.packageRootFolder;
66
+ static tmpBaseName = packageDefaults.tmpBaseName;
67
+ static tmpExtension = packageDefaults.tmpExtension;
68
+ static mainSourceFolder = packageDefaults.mainSourceFolder;
69
+ static layoutPaths = packageDefaults.layoutPaths;
70
+ static publicFolderName = packageDefaults.publicFolderName;
71
+ static kafkaLogsTopic = packageDefaults.kafkaLogsTopic;
72
+ static templateRepoUri = packageDefaults.templateRepoUri;
73
+ static bundledCoreTmpPath = path2.join(packageRootDir, packageDefaults.packageRootFolder, tmpFileName);
74
+ }
75
+
76
+ // source/utils/helpers/tmp/tmp-schema.ts
77
+ function isRecord(value) {
78
+ return typeof value === "object" && value !== null && !Array.isArray(value);
79
+ }
80
+ function readWatchIntervalValue(raw) {
81
+ if (typeof raw === "number" || typeof raw === "string")
82
+ return raw;
83
+ return;
84
+ }
85
+ function normalizeRootFolder(value) {
86
+ if (!value?.trim())
87
+ return Constants.packageRootFolder;
88
+ return value.trim().replace(/^\.\/+/, "");
89
+ }
90
+ function normalizeSourceFolder(value) {
91
+ if (!value?.trim())
92
+ return Constants.mainSourceFolder;
93
+ const trimmed = value.trim();
94
+ if (trimmed.startsWith("./") || trimmed.startsWith("../"))
95
+ return trimmed;
96
+ return `./${trimmed}`;
97
+ }
98
+ function readTmpCoreBlock(configs) {
99
+ const core = isRecord(configs?.core) ? configs.core : {};
100
+ const tmp = isRecord(core.tmp) ? core.tmp : {};
101
+ return {
102
+ tmp: {
103
+ fileWatchIntervalMs: readWatchIntervalValue(tmp.fileWatchIntervalMs)
104
+ }
105
+ };
106
+ }
107
+ function readTmpServiceBlock(configs) {
108
+ const service = isRecord(configs?.service) ? configs.service : {};
109
+ const pathsRaw = isRecord(service.paths) ? service.paths : {};
110
+ const special = isRecord(pathsRaw.special) ? pathsRaw.special : {};
111
+ let loaders = isRecord(service.loaders) ? { ...service.loaders } : undefined;
112
+ let build = isRecord(service.build) ? service.build : undefined;
113
+ if (loaders && isRecord(loaders.build)) {
114
+ const { build: nestedBuild, ...rest } = loaders;
115
+ loaders = rest;
116
+ if (!build && isRecord(nestedBuild)) {
117
+ build = nestedBuild;
118
+ }
119
+ }
120
+ return {
121
+ name: typeof service.name === "string" ? service.name : undefined,
122
+ framework: typeof service.framework === "string" ? service.framework : undefined,
123
+ paths: {
124
+ root: typeof pathsRaw.root === "string" ? pathsRaw.root : undefined,
125
+ source: typeof pathsRaw.source === "string" ? pathsRaw.source : undefined,
126
+ special: {
127
+ tests: typeof special.tests === "string" ? special.tests : undefined,
128
+ environments: typeof special.environments === "string" ? special.environments : undefined,
129
+ dist: typeof special.dist === "string" ? special.dist : undefined
130
+ }
131
+ },
132
+ protocols: service.protocols,
133
+ loaders,
134
+ build
135
+ };
136
+ }
137
+ function resolveServiceLayoutPaths(service) {
138
+ const special = service.paths?.special ?? {};
139
+ return {
140
+ tests: special.tests?.trim() || Constants.layoutPaths.tests,
141
+ environments: special.environments?.trim() || Constants.layoutPaths.environments,
142
+ dist: special.dist?.trim() || Constants.layoutPaths.dist
143
+ };
144
+ }
145
+ function buildNormalizedService(service) {
146
+ const layoutPaths = resolveServiceLayoutPaths(service);
147
+ return {
148
+ name: service.name,
149
+ framework: service.framework ?? "elysia",
150
+ paths: {
151
+ root: service.paths?.root ?? Constants.packageRootFolder,
152
+ source: service.paths?.source ?? Constants.mainSourceFolder,
153
+ special: layoutPaths
154
+ },
155
+ protocols: service.protocols,
156
+ loaders: service.loaders,
157
+ build: service.build
158
+ };
159
+ }
160
+ function buildNormalizedCore(core) {
161
+ return {
162
+ tmp: {
163
+ fileWatchIntervalMs: core.tmp?.fileWatchIntervalMs
164
+ }
165
+ };
166
+ }
167
+ function resolveTmpRuntimeConfigs(tmp) {
168
+ const configs = isRecord(tmp?.configs) ? tmp.configs : {};
169
+ const service = readTmpServiceBlock(configs);
170
+ const core = readTmpCoreBlock(configs);
171
+ const normalizedService = buildNormalizedService(service);
172
+ return {
173
+ service: normalizedService,
174
+ core: buildNormalizedCore(core),
175
+ rootFolderPath: normalizeRootFolder(normalizedService.paths.root)
176
+ };
177
+ }
178
+ function normalizeTmpDocument(tmp) {
179
+ return {
180
+ ...tmp,
181
+ configs: resolveTmpRuntimeConfigs(tmp)
182
+ };
183
+ }
184
+ export {
185
+ resolveTmpRuntimeConfigs,
186
+ resolveServiceLayoutPaths,
187
+ readTmpServiceBlock,
188
+ readTmpCoreBlock,
189
+ normalizeTmpDocument,
190
+ normalizeSourceFolder,
191
+ normalizeRootFolder
192
+ };
@@ -0,0 +1,80 @@
1
+ import chalk from 'chalk'
2
+
3
+ import { CLI_BIN_NAMES, CLI_PRIMARY_NAME } from './cli-identity.mjs'
4
+
5
+ /** figlet standard — lowercase wordmark, split for two-tone print */
6
+ const XRYSTAL_LINES = [
7
+ ' _ _ ',
8
+ ' __ ___ __ _ _ ___| |_ __ _| |',
9
+ " \\ \\/ / '__| | | / __| __/ _` | |",
10
+ ' > <| | | |_| \\__ \\ || (_| | |',
11
+ ' /_/\\_\\_| \\__, |___/\\__\\__,_|_|',
12
+ ' |___/ ',
13
+ ]
14
+
15
+ const CORE_LINES = [
16
+ '',
17
+ ' ___ ___ _ __ ___ ',
18
+ " / __/ _ \\| '__/ _ \\",
19
+ ' | (_| (_) | | | __/',
20
+ ' \\___\\___/|_| \\___/',
21
+ '',
22
+ ]
23
+
24
+ const WORDMARK_WIDTH = Math.max(...XRYSTAL_LINES.map((line) => line.length))
25
+ const BIN_ALIASES_LABEL = CLI_BIN_NAMES.join(' · ')
26
+ export function printWordmark() {
27
+ const rows = Math.max(XRYSTAL_LINES.length, CORE_LINES.length)
28
+ for (let i = 0; i < rows; i += 1) {
29
+ const left = (XRYSTAL_LINES[i] ?? '').padEnd(WORDMARK_WIDTH)
30
+ const right = CORE_LINES[i] ?? ''
31
+ console.log(` ${chalk.bold.white(left)}${chalk.bold.magenta(right)}`)
32
+ }
33
+ }
34
+
35
+ export function brandTitle() {
36
+ return `${chalk.bold.white('xrystal ')}${chalk.bold.magenta('core')}`
37
+ }
38
+
39
+ /** Full banner — bare `xcore` / `xcore -h` (root help). */
40
+ export function printBanner({ version, runtimeName, invokedAs } = {}) {
41
+ const bin = invokedAs && invokedAs !== 'main-cli.js' ? invokedAs : CLI_PRIMARY_NAME
42
+ const versionLabel = version ? chalk.bold.green(`v${version}`) : chalk.gray('v?')
43
+ const runtimeLabel = runtimeName ? chalk.bold.white(runtimeName) : ''
44
+
45
+ console.log('')
46
+
47
+ printWordmark()
48
+ console.log('')
49
+ console.log(chalk.bold.gray(' microservice runtime library'))
50
+
51
+ console.log('')
52
+ console.log(
53
+ ` ${chalk.bold.cyan(bin)} ${chalk.gray('·')} ${chalk.bold('@xrystal/core')} ${versionLabel}${runtimeLabel ? ` ${chalk.gray('·')} ${runtimeLabel}` : ''}`,
54
+ )
55
+ console.log(chalk.bold.gray(' loaders · tmp.yml · dto · i18n · multi-protocol · scaffold'))
56
+ console.log(chalk.dim(` bin aliases: ${BIN_ALIASES_LABEL}`))
57
+ console.log('')
58
+ }
59
+
60
+ /** One-line header for subcommands (build, dev, doctor, …). */
61
+ export function printCommandHeader({ cliName, command, version } = {}) {
62
+ const label = cliName || CLI_PRIMARY_NAME
63
+ const versionLabel = version ? chalk.green(`v${version}`) : ''
64
+ console.log('')
65
+ console.log(
66
+ `${chalk.bold.cyan(`${label} ${command}`)} ${chalk.gray('·')} ${brandTitle()} ${versionLabel}`.trim(),
67
+ )
68
+ }
69
+
70
+ /**
71
+ * Root banner: bare CLI, or root-level -h / --help / help.
72
+ * Subcommands keep compact headers only.
73
+ */
74
+ export function shouldShowBanner(argv = process.argv) {
75
+ const args = argv.slice(2)
76
+ if (!args.length) return true
77
+ if (args.length === 1 && ['-h', '--help', 'help'].includes(args[0])) return true
78
+ if (args.some((a) => ['-V', '--version'].includes(a))) return false
79
+ return false
80
+ }