@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.
Files changed (264) hide show
  1. package/README.md +676 -136
  2. package/package.json +27 -24
  3. package/tsconfig.base.json +15 -0
  4. package/x/bin/commands/create.mjs +34 -5
  5. package/x/bin/commands/doctor.mjs +115 -25
  6. package/x/bin/commands/hooks.mjs +55 -0
  7. package/x/bin/commands/project.mjs +75 -42
  8. package/x/bin/commands/release.mjs +8 -3
  9. package/x/bin/commands/sync-toolchain.mjs +43 -0
  10. package/x/bin/commands/tmp.mjs +13 -4
  11. package/x/bin/helpers/.generated/.generated-from +1 -0
  12. package/x/bin/helpers/.generated/tmp-schema.mjs +192 -0
  13. package/x/bin/helpers/banner.mjs +66 -12
  14. package/x/bin/helpers/build-config.mjs +342 -0
  15. package/x/bin/helpers/cli-help.mjs +164 -0
  16. package/x/bin/helpers/create-target.mjs +18 -2
  17. package/x/bin/helpers/project-artifacts.mjs +142 -0
  18. package/x/bin/helpers/runtime-info.mjs +172 -0
  19. package/x/bin/helpers/tmp-config.mjs +11 -10
  20. package/x/bin/helpers/tmp-layout.mjs +10 -16
  21. package/x/bin/helpers/tmp-schema.mjs +9 -0
  22. package/x/bin/helpers/toolchain-config.mjs +233 -0
  23. package/x/bin/main-cli.js +31 -3
  24. package/x/bin/scripts/clean-source-types.mjs +19 -0
  25. package/x/bin/scripts/fix-dist-imports.mjs +80 -0
  26. package/x/bin/scripts/install-git-hooks.mjs +86 -0
  27. package/x/bin/scripts/minify-dist.mjs +50 -0
  28. package/x/bin/scripts/prepare-npm-publish.mjs +39 -0
  29. package/x/bin/scripts/publish-guard.mjs +113 -0
  30. package/x/bin/scripts/verify-npm-pack.mjs +12 -0
  31. package/x/bin/scripts/verify-publish-config.mjs +10 -0
  32. package/x/bin/scripts/verify-version-bump.mjs +27 -0
  33. package/x/bin/scripts/version-check.mjs +173 -0
  34. package/x/dist/index.js +1 -0
  35. package/x/dist/loader/clients/index.js +1 -0
  36. package/x/dist/loader/configs/index.js +1 -0
  37. package/{source → x/dist}/loader/controller/index.d.ts +20 -17
  38. package/x/dist/loader/controller/index.js +1 -0
  39. package/x/dist/loader/dto/index.js +1 -0
  40. package/x/dist/loader/events/index.js +1 -0
  41. package/x/dist/loader/index.d.ts +11 -0
  42. package/x/dist/loader/index.js +1 -0
  43. package/{source → x/dist}/loader/kafka/index.d.ts +1 -0
  44. package/x/dist/loader/kafka/index.js +1 -0
  45. package/x/dist/loader/localizations/index.js +1 -0
  46. package/{source → x/dist}/loader/logger/index.d.ts +1 -0
  47. package/x/dist/loader/logger/index.js +2 -0
  48. package/x/dist/loader/service/index.js +1 -0
  49. package/x/dist/loader/system/index.js +1 -0
  50. package/x/dist/project/index.d.ts +12 -0
  51. package/x/dist/project/index.js +1 -0
  52. package/x/dist/utils/constants/defaults.json +44 -0
  53. package/x/dist/utils/constants/index.js +1 -0
  54. package/x/dist/utils/helpers/configs/index.js +1 -0
  55. package/x/dist/utils/helpers/context/controller-store.js +1 -0
  56. package/x/dist/utils/helpers/context/index.js +1 -0
  57. package/{source → x/dist}/utils/helpers/core/index.d.ts +1 -1
  58. package/x/dist/utils/helpers/core/index.js +1 -0
  59. package/x/dist/utils/helpers/core/paths.js +1 -0
  60. package/x/dist/utils/helpers/core/tmp-layout.js +1 -0
  61. package/x/dist/utils/helpers/date/index.js +1 -0
  62. package/x/dist/utils/helpers/dispatch/index.js +1 -0
  63. package/x/dist/utils/helpers/dto/index.js +1 -0
  64. package/x/dist/utils/helpers/filters/index.js +1 -0
  65. package/x/dist/utils/helpers/framework/index.js +1 -0
  66. package/x/dist/utils/helpers/handlers/adapters.js +1 -0
  67. package/x/dist/utils/helpers/handlers/execute.js +1 -0
  68. package/x/dist/utils/helpers/handlers/index.js +1 -0
  69. package/x/dist/utils/helpers/hash/crypto.js +1 -0
  70. package/x/dist/utils/helpers/id/index.js +1 -0
  71. package/x/dist/utils/helpers/index.js +1 -0
  72. package/x/dist/utils/helpers/ip/index.js +1 -0
  73. package/x/dist/utils/helpers/is/index.js +1 -0
  74. package/x/dist/utils/helpers/locales/index.js +1 -0
  75. package/x/dist/utils/helpers/math/index.js +1 -0
  76. package/{source → x/dist}/utils/helpers/middleware/index.d.ts +2 -2
  77. package/x/dist/utils/helpers/middleware/index.js +1 -0
  78. package/x/dist/utils/helpers/objects/index.js +1 -0
  79. package/x/dist/utils/helpers/path/index.js +1 -0
  80. package/{source → x/dist}/utils/helpers/protocol/index.d.ts +2 -10
  81. package/x/dist/utils/helpers/protocol/index.js +1 -0
  82. package/x/dist/utils/helpers/protocol/options.js +1 -0
  83. package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +1 -0
  84. package/x/dist/utils/helpers/runtime/dto-access.js +1 -0
  85. package/x/dist/utils/helpers/runtime/dto-types.js +1 -0
  86. package/{source → x/dist}/utils/helpers/runtime/index.d.ts +1 -0
  87. package/x/dist/utils/helpers/runtime/index.js +1 -0
  88. package/x/dist/utils/helpers/runtime/shutdown.d.ts +3 -0
  89. package/x/dist/utils/helpers/runtime/shutdown.js +1 -0
  90. package/x/dist/utils/helpers/state/index.js +1 -0
  91. package/x/dist/utils/helpers/state/props-from-tmp.js +1 -0
  92. package/x/dist/utils/helpers/state/request-key-guard.js +1 -0
  93. package/x/dist/utils/helpers/state/scopes.js +1 -0
  94. package/x/dist/utils/helpers/string/index.js +1 -0
  95. package/x/dist/utils/helpers/tests/tmp-schema.test.js +1 -0
  96. package/x/dist/utils/helpers/tests/tmp-watch.test.d.ts +1 -0
  97. package/x/dist/utils/helpers/tests/tmp-watch.test.js +1 -0
  98. package/x/dist/utils/helpers/timer/index.js +1 -0
  99. package/x/dist/utils/helpers/tmp/index.d.ts +5 -0
  100. package/x/dist/utils/helpers/tmp/index.js +1 -0
  101. package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +1 -0
  102. package/{source → x/dist}/utils/helpers/tmp/runtime-tmp.d.ts +2 -6
  103. package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -0
  104. package/{source → x/dist}/utils/helpers/tmp/tmp-loader.d.ts +1 -0
  105. package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -0
  106. package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +47 -0
  107. package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -0
  108. package/x/dist/utils/helpers/tmp/tmp-watch.d.ts +1 -0
  109. package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -0
  110. package/x/dist/utils/helpers/validates/index.js +1 -0
  111. package/x/dist/utils/index.js +1 -0
  112. package/x/dist/utils/models/classes/class.clients.js +1 -0
  113. package/x/dist/utils/models/classes/class.interfaces.js +1 -0
  114. package/x/dist/utils/models/classes/class.service-locator.js +1 -0
  115. package/{source → x/dist}/utils/models/classes/class.tmp-file-loader.d.ts +3 -2
  116. package/x/dist/utils/models/classes/class.tmp-file-loader.js +1 -0
  117. package/x/dist/utils/models/classes/class.x.js +1 -0
  118. package/x/dist/utils/models/enums/index.js +1 -0
  119. package/x/dist/utils/models/index.js +1 -0
  120. package/x/dist/utils/models/types/index.js +1 -0
  121. package/x/dist/utils/package-root.js +1 -0
  122. package/x/tmp.yml +51 -42
  123. package/source/index.js +0 -11
  124. package/source/loader/clients/index.js +0 -22
  125. package/source/loader/configs/index.js +0 -88
  126. package/source/loader/controller/index.js +0 -236
  127. package/source/loader/dto/index.js +0 -92
  128. package/source/loader/events/index.js +0 -44
  129. package/source/loader/index.d.ts +0 -11
  130. package/source/loader/index.js +0 -11
  131. package/source/loader/kafka/index.js +0 -137
  132. package/source/loader/localizations/index.js +0 -46
  133. package/source/loader/logger/index.js +0 -217
  134. package/source/loader/service/index.js +0 -7
  135. package/source/loader/system/index.js +0 -25
  136. package/source/project/index.d.ts +0 -8
  137. package/source/project/index.js +0 -70
  138. package/source/utils/constants/defaults.json +0 -15
  139. package/source/utils/constants/defaults.mjs +0 -10
  140. package/source/utils/constants/index.js +0 -22
  141. package/source/utils/helpers/configs/index.js +0 -1
  142. package/source/utils/helpers/context/controller-store.js +0 -12
  143. package/source/utils/helpers/context/index.js +0 -24
  144. package/source/utils/helpers/core/index.js +0 -58
  145. package/source/utils/helpers/core/paths.js +0 -78
  146. package/source/utils/helpers/core/tmp-layout.js +0 -241
  147. package/source/utils/helpers/date/index.js +0 -48
  148. package/source/utils/helpers/dispatch/index.js +0 -53
  149. package/source/utils/helpers/dto/index.js +0 -10
  150. package/source/utils/helpers/filters/index.js +0 -44
  151. package/source/utils/helpers/framework/index.js +0 -17
  152. package/source/utils/helpers/handlers/adapters.js +0 -40
  153. package/source/utils/helpers/handlers/execute.js +0 -82
  154. package/source/utils/helpers/handlers/index.js +0 -31
  155. package/source/utils/helpers/hash/crypto.js +0 -22
  156. package/source/utils/helpers/id/index.js +0 -24
  157. package/source/utils/helpers/index.js +0 -26
  158. package/source/utils/helpers/ip/index.js +0 -21
  159. package/source/utils/helpers/is/index.js +0 -35
  160. package/source/utils/helpers/locales/index.js +0 -82
  161. package/source/utils/helpers/math/index.js +0 -14
  162. package/source/utils/helpers/middleware/index.js +0 -36
  163. package/source/utils/helpers/objects/index.js +0 -55
  164. package/source/utils/helpers/path/index.js +0 -4
  165. package/source/utils/helpers/protocol/index.js +0 -99
  166. package/source/utils/helpers/protocol/options.js +0 -13
  167. package/source/utils/helpers/regex/checkSpecialRegexControl.js +0 -3
  168. package/source/utils/helpers/runtime/dto-access.js +0 -5
  169. package/source/utils/helpers/runtime/index.js +0 -1
  170. package/source/utils/helpers/state/index.js +0 -185
  171. package/source/utils/helpers/state/props-from-tmp.js +0 -44
  172. package/source/utils/helpers/state/request-key-guard.js +0 -42
  173. package/source/utils/helpers/state/scopes.js +0 -69
  174. package/source/utils/helpers/string/index.js +0 -9
  175. package/source/utils/helpers/timer/index.js +0 -5
  176. package/source/utils/helpers/tmp/index.d.ts +0 -3
  177. package/source/utils/helpers/tmp/index.js +0 -3
  178. package/source/utils/helpers/tmp/loader-tmp-sync.js +0 -13
  179. package/source/utils/helpers/tmp/runtime-tmp.js +0 -30
  180. package/source/utils/helpers/tmp/tmp-loader.js +0 -48
  181. package/source/utils/helpers/validates/index.js +0 -20
  182. package/source/utils/index.js +0 -3
  183. package/source/utils/models/classes/class.clients.js +0 -142
  184. package/source/utils/models/classes/class.interfaces.js +0 -10
  185. package/source/utils/models/classes/class.service-locator.js +0 -16
  186. package/source/utils/models/classes/class.tmp-file-loader.js +0 -38
  187. package/source/utils/models/classes/class.x.js +0 -180
  188. package/source/utils/models/enums/index.js +0 -148
  189. package/source/utils/models/index.js +0 -9
  190. package/source/utils/models/types/index.js +0 -2
  191. package/source/utils/models/types/shims.d.ts +0 -123
  192. package/source/utils/package-root.js +0 -5
  193. package/x/tests/cli.test.ts +0 -85
  194. package/x/tests/context.test.ts +0 -25
  195. package/x/tests/dispatch.test.ts +0 -84
  196. package/x/tests/fixtures/locales/en/translation.json +0 -8
  197. package/x/tests/fixtures/locales/tr/translation.json +0 -8
  198. package/x/tests/frameworks.integration.test.ts +0 -185
  199. package/x/tests/helpers/i18n-setup.ts +0 -52
  200. package/x/tests/helpers/middleware.ts +0 -23
  201. package/x/tests/helpers/register-test-dto.ts +0 -52
  202. package/x/tests/i18n.integration.test.ts +0 -77
  203. package/x/tests/i18n.test.ts +0 -96
  204. package/x/tests/middleware.test.ts +0 -83
  205. package/x/tests/project-layout.test.ts +0 -65
  206. package/x/tests/protocol.test.ts +0 -75
  207. package/x/tests/realtime.examples.test.ts +0 -198
  208. package/x/tests/runtime-tmp.test.ts +0 -49
  209. package/x/tests/socket.integration.test.ts +0 -174
  210. package/x/tests/state.test.ts +0 -183
  211. package/x/tests/tmp-layout-guard.test.ts +0 -40
  212. /package/{source → x/dist}/index.d.ts +0 -0
  213. /package/{source → x/dist}/loader/clients/index.d.ts +0 -0
  214. /package/{source → x/dist}/loader/configs/index.d.ts +0 -0
  215. /package/{source → x/dist}/loader/dto/index.d.ts +0 -0
  216. /package/{source → x/dist}/loader/events/index.d.ts +0 -0
  217. /package/{source → x/dist}/loader/localizations/index.d.ts +0 -0
  218. /package/{source → x/dist}/loader/service/index.d.ts +0 -0
  219. /package/{source → x/dist}/loader/system/index.d.ts +0 -0
  220. /package/{source → x/dist}/utils/constants/index.d.ts +0 -0
  221. /package/{source → x/dist}/utils/helpers/configs/index.d.ts +0 -0
  222. /package/{source → x/dist}/utils/helpers/context/controller-store.d.ts +0 -0
  223. /package/{source → x/dist}/utils/helpers/context/index.d.ts +0 -0
  224. /package/{source → x/dist}/utils/helpers/core/paths.d.ts +0 -0
  225. /package/{source → x/dist}/utils/helpers/core/tmp-layout.d.ts +0 -0
  226. /package/{source → x/dist}/utils/helpers/date/index.d.ts +0 -0
  227. /package/{source → x/dist}/utils/helpers/dispatch/index.d.ts +0 -0
  228. /package/{source → x/dist}/utils/helpers/dto/index.d.ts +0 -0
  229. /package/{source → x/dist}/utils/helpers/filters/index.d.ts +0 -0
  230. /package/{source → x/dist}/utils/helpers/framework/index.d.ts +0 -0
  231. /package/{source → x/dist}/utils/helpers/handlers/adapters.d.ts +0 -0
  232. /package/{source → x/dist}/utils/helpers/handlers/execute.d.ts +0 -0
  233. /package/{source → x/dist}/utils/helpers/handlers/index.d.ts +0 -0
  234. /package/{source → x/dist}/utils/helpers/hash/crypto.d.ts +0 -0
  235. /package/{source → x/dist}/utils/helpers/id/index.d.ts +0 -0
  236. /package/{source → x/dist}/utils/helpers/index.d.ts +0 -0
  237. /package/{source → x/dist}/utils/helpers/ip/index.d.ts +0 -0
  238. /package/{source → x/dist}/utils/helpers/is/index.d.ts +0 -0
  239. /package/{source → x/dist}/utils/helpers/locales/index.d.ts +0 -0
  240. /package/{source → x/dist}/utils/helpers/math/index.d.ts +0 -0
  241. /package/{source → x/dist}/utils/helpers/objects/index.d.ts +0 -0
  242. /package/{source → x/dist}/utils/helpers/path/index.d.ts +0 -0
  243. /package/{source → x/dist}/utils/helpers/protocol/options.d.ts +0 -0
  244. /package/{source → x/dist}/utils/helpers/regex/checkSpecialRegexControl.d.ts +0 -0
  245. /package/{source → x/dist}/utils/helpers/runtime/dto-access.d.ts +0 -0
  246. /package/{source → x/dist}/utils/helpers/runtime/dto-types.d.ts +0 -0
  247. /package/{source → x/dist}/utils/helpers/state/index.d.ts +0 -0
  248. /package/{source → x/dist}/utils/helpers/state/props-from-tmp.d.ts +0 -0
  249. /package/{source → x/dist}/utils/helpers/state/request-key-guard.d.ts +0 -0
  250. /package/{source → x/dist}/utils/helpers/state/scopes.d.ts +0 -0
  251. /package/{source → x/dist}/utils/helpers/string/index.d.ts +0 -0
  252. /package/{source/utils/helpers/runtime/dto-types.js → x/dist/utils/helpers/tests/tmp-schema.test.d.ts} +0 -0
  253. /package/{source → x/dist}/utils/helpers/timer/index.d.ts +0 -0
  254. /package/{source → x/dist}/utils/helpers/tmp/loader-tmp-sync.d.ts +0 -0
  255. /package/{source → x/dist}/utils/helpers/validates/index.d.ts +0 -0
  256. /package/{source → x/dist}/utils/index.d.ts +0 -0
  257. /package/{source → x/dist}/utils/models/classes/class.clients.d.ts +0 -0
  258. /package/{source → x/dist}/utils/models/classes/class.interfaces.d.ts +0 -0
  259. /package/{source → x/dist}/utils/models/classes/class.service-locator.d.ts +0 -0
  260. /package/{source → x/dist}/utils/models/classes/class.x.d.ts +0 -0
  261. /package/{source → x/dist}/utils/models/enums/index.d.ts +0 -0
  262. /package/{source → x/dist}/utils/models/index.d.ts +0 -0
  263. /package/{source → x/dist}/utils/models/types/index.d.ts +0 -0
  264. /package/{source → x/dist}/utils/package-root.d.ts +0 -0
@@ -0,0 +1,342 @@
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 { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
7
+ import { normalizeTmpDocument, readTmpServiceBlock } from './tmp-schema.mjs'
8
+
9
+ export const CLI_BUILD_SCRIPT_RE = /^(xcore|xrystal|tmp)\s+build\b/
10
+
11
+ const BUILD_DEFAULTS = packageDefaults.buildDefaults ?? {}
12
+
13
+ export function isCorePackageName(name) {
14
+ return name === packageDefaults.packageName
15
+ }
16
+
17
+ export function shouldDelegatePackageBuild(pkg) {
18
+ const buildScript = pkg.scripts?.build?.trim() ?? ''
19
+ if (!buildScript) return false
20
+ if (isCorePackageName(pkg.name)) return false
21
+ if (CLI_BUILD_SCRIPT_RE.test(buildScript)) return false
22
+ return true
23
+ }
24
+
25
+ export function readTmpBuildContext(root) {
26
+ const ensured = ensureTmpFile(root)
27
+ const tmp = normalizeTmpDocument(yaml.parse(fs.readFileSync(ensured.tmpFilePath, 'utf8')))
28
+ const configs = tmp.configs ?? {}
29
+ const build = readTmpServiceBlock(configs).build ?? {}
30
+ return { layout: ensured.layout, configs, build }
31
+ }
32
+
33
+ export function normalizeMainFolder(mainFolderPath = packageDefaults.mainSourceFolder) {
34
+ const trimmed = String(mainFolderPath).trim() || packageDefaults.mainSourceFolder
35
+ if (trimmed.startsWith('./') || trimmed.startsWith('../')) return trimmed
36
+ return `./${trimmed}`
37
+ }
38
+
39
+ export function resolveTsconfigRel(root, buildConfig = {}) {
40
+ const configured =
41
+ typeof buildConfig.tsconfig === 'string' && buildConfig.tsconfig.trim()
42
+ ? buildConfig.tsconfig.trim()
43
+ : BUILD_DEFAULTS.tsconfig ?? 'tsconfig.json'
44
+
45
+ const abs = path.isAbsolute(configured) ? configured : path.join(root, configured)
46
+ if (!fs.existsSync(abs)) return null
47
+ return relativeFromRoot(root, abs)
48
+ }
49
+
50
+ export function readTsconfigJson(root, buildConfig = {}) {
51
+ const rel = resolveTsconfigRel(root, buildConfig)
52
+ if (!rel) return null
53
+
54
+ const abs = path.join(root, rel)
55
+ let raw
56
+ try {
57
+ raw = JSON.parse(fs.readFileSync(abs, 'utf8'))
58
+ } catch (error) {
59
+ throw new Error(`Failed to parse ${rel}: ${error instanceof Error ? error.message : error}`)
60
+ }
61
+
62
+ return {
63
+ rel,
64
+ raw,
65
+ compilerOptions: raw.compilerOptions ?? {},
66
+ include: Array.isArray(raw.include) ? raw.include : null,
67
+ exclude: Array.isArray(raw.exclude) ? raw.exclude : null,
68
+ }
69
+ }
70
+
71
+ export function includeToEntryGlobs(include) {
72
+ const items = Array.isArray(include) && include.length > 0 ? include : null
73
+ if (!items) return null
74
+
75
+ const globs = []
76
+ for (const item of items.map(String)) {
77
+ const trimmed = item.trim()
78
+ if (!trimmed) continue
79
+
80
+ const normalized = trimmed.startsWith('./') || trimmed.startsWith('../') ? trimmed : `./${trimmed}`
81
+
82
+ if (normalized.includes('*')) {
83
+ if (normalized.endsWith('.ts')) {
84
+ globs.push(normalized)
85
+ continue
86
+ }
87
+ const base = normalized.replace(/\/+$/, '')
88
+ globs.push(`${base}/*.ts`, `${base}/**/*.ts`)
89
+ continue
90
+ }
91
+
92
+ globs.push(`${normalized}/*.ts`, `${normalized}/**/*.ts`)
93
+ }
94
+
95
+ return globs.length > 0 ? [...new Set(globs)] : null
96
+ }
97
+
98
+ export function sourcemapFromTsconfig(compilerOptions = {}) {
99
+ if (compilerOptions.inlineSourceMap === true) return 'inline'
100
+ if (compilerOptions.sourceMap === true) return 'linked'
101
+ if (compilerOptions.sourceMap === false) return false
102
+ return undefined
103
+ }
104
+
105
+ export function declarationsFromTsconfig(compilerOptions = {}) {
106
+ if (compilerOptions.emitDeclarationOnly === true) return true
107
+ if (compilerOptions.declaration === false) return false
108
+ return undefined
109
+ }
110
+
111
+ export function resolveBuildEntryGlobs(mainFolderPath, buildConfig = {}, tsconfig = null) {
112
+ if (Array.isArray(buildConfig.entries) && buildConfig.entries.length > 0) {
113
+ return buildConfig.entries.map(String)
114
+ }
115
+
116
+ if (typeof buildConfig.glob === 'string' && buildConfig.glob.trim()) {
117
+ const glob = buildConfig.glob.trim()
118
+ if (glob.includes('*')) {
119
+ const flat = glob.replace(/\/\*\*\/\*\.ts$/, '/*.ts')
120
+ return flat === glob ? [glob] : [flat, glob]
121
+ }
122
+ }
123
+
124
+ const fromInclude = includeToEntryGlobs(tsconfig?.include)
125
+ if (fromInclude) return fromInclude
126
+
127
+ const rootDir = tsconfig?.compilerOptions?.rootDir
128
+ if (typeof rootDir === 'string' && rootDir.trim()) {
129
+ const fromRootDir = includeToEntryGlobs([rootDir])
130
+ if (fromRootDir) return fromRootDir
131
+ }
132
+
133
+ const main = normalizeMainFolder(mainFolderPath)
134
+ return [`${main}/*.ts`, `${main}/**/*.ts`]
135
+ }
136
+
137
+ export function resolveDistRel(root, layout) {
138
+ return relativeFromRoot(root, layout.pathsAbs.dist)
139
+ }
140
+
141
+ export function resolveDistRelWithTsconfig(root, layout, buildConfig = {}, tsconfig = null) {
142
+ if (typeof buildConfig.outDir === 'string' && buildConfig.outDir.trim()) {
143
+ const abs = path.isAbsolute(buildConfig.outDir)
144
+ ? buildConfig.outDir
145
+ : path.join(root, buildConfig.outDir.trim())
146
+ return relativeFromRoot(root, abs)
147
+ }
148
+
149
+ const outDir = tsconfig?.compilerOptions?.outDir
150
+ if (typeof outDir === 'string' && outDir.trim()) {
151
+ const abs = path.isAbsolute(outDir) ? outDir : path.join(root, outDir.trim())
152
+ return relativeFromRoot(root, abs)
153
+ }
154
+
155
+ return resolveDistRel(root, layout)
156
+ }
157
+
158
+ export function resolveDistEntryAbs(root, layout, buildConfig = {}) {
159
+ const tsconfig = readTsconfigJson(root, buildConfig)
160
+ const distRel = resolveDistRelWithTsconfig(root, layout, buildConfig, tsconfig)
161
+ const distAbs = path.join(root, distRel)
162
+ return path.join(distAbs, 'index.js')
163
+ }
164
+
165
+ export function resolveTypecheckEnabled(buildConfig = {}) {
166
+ if (typeof buildConfig.typecheck === 'boolean') return buildConfig.typecheck
167
+ return BUILD_DEFAULTS.typecheck ?? false
168
+ }
169
+
170
+ export function resolveDeclarationsEnabled(buildConfig = {}, tsconfig = null) {
171
+ if (typeof buildConfig.declarations === 'boolean') return buildConfig.declarations
172
+ const fromTsconfig = declarationsFromTsconfig(tsconfig?.compilerOptions ?? {})
173
+ if (typeof fromTsconfig === 'boolean') return fromTsconfig
174
+ return BUILD_DEFAULTS.declarations ?? false
175
+ }
176
+
177
+ export function resolveMinifyEnabled(buildConfig = {}) {
178
+ const raw = buildConfig.minify ?? buildConfig.protect ?? buildConfig.compress ?? BUILD_DEFAULTS.minify ?? false
179
+ if (raw === false || raw === 'off' || raw === 'none' || raw === 0 || raw === null) return false
180
+ return true
181
+ }
182
+
183
+ /** tmp.yml build.minify / build.protect — strip comments/whitespace, mangle identifiers. */
184
+ export function resolveMinifyFlags(buildConfig = {}) {
185
+ const raw = buildConfig.minify ?? buildConfig.protect ?? buildConfig.compress ?? BUILD_DEFAULTS.minify ?? false
186
+
187
+ if (raw === false || raw === 'off' || raw === 'none' || raw === 0 || raw === null) return []
188
+
189
+ if (raw === true || raw === 'on' || raw === 'all') return ['--minify']
190
+ if (raw === 'production' || raw === 'prod') return ['--production']
191
+
192
+ if (typeof raw === 'object') {
193
+ if (raw.minify === true || raw.protect === true || raw.all === true) return ['--minify']
194
+ const flags = []
195
+ if (raw.syntax) flags.push('--minify-syntax')
196
+ if (raw.whitespace) flags.push('--minify-whitespace')
197
+ if (raw.identifiers) flags.push('--minify-identifiers')
198
+ return flags.length ? flags : ['--minify']
199
+ }
200
+
201
+ if (typeof raw === 'string' && raw.trim()) return ['--minify']
202
+ return ['--minify']
203
+ }
204
+
205
+ export function resolveSourcemapFlag(buildConfig = {}, tsconfig = null) {
206
+ if (resolveMinifyEnabled(buildConfig) && buildConfig.sourcemap === undefined) {
207
+ return ''
208
+ }
209
+ const fromTsconfig = sourcemapFromTsconfig(tsconfig?.compilerOptions ?? {})
210
+ const raw = buildConfig.sourcemap ?? fromTsconfig ?? BUILD_DEFAULTS.sourcemap ?? false
211
+
212
+ if (raw === false || raw === 'none' || raw === 'off' || raw === 0) return ''
213
+ if (raw === true || raw === 'linked' || raw === 'external') return '--sourcemap=linked'
214
+ if (raw === 'inline') return '--sourcemap=inline'
215
+ if (typeof raw === 'string' && raw.trim()) return `--sourcemap=${raw.trim()}`
216
+ return ''
217
+ }
218
+
219
+ function withTscProject(root, buildConfig, extraArgs) {
220
+ const tsconfigRel = resolveTsconfigRel(root, buildConfig)
221
+ const projectFlag = tsconfigRel ? `--project ${tsconfigRel} ` : ''
222
+ return `bunx tsc ${projectFlag}${extraArgs}`.replace(/\s+/g, ' ').trim()
223
+ }
224
+
225
+ export function resolveTypecheckCommand(root, buildConfig = {}) {
226
+ const tsconfigRel = resolveTsconfigRel(root, buildConfig)
227
+ if (!tsconfigRel) {
228
+ throw new Error(
229
+ 'build.typecheck is enabled but tsconfig was not found. Set build.tsconfig or add tsconfig.json.',
230
+ )
231
+ }
232
+ return withTscProject(root, buildConfig, '--noEmit')
233
+ }
234
+
235
+ export function resolveTscCommand(root, distRel, buildConfig = {}) {
236
+ const cmd = withTscProject(root, buildConfig, `--emitDeclarationOnly --declaration --outDir ${distRel}`)
237
+ return buildConfig.tscLenient ? `${cmd} || true` : cmd
238
+ }
239
+
240
+ export function resolveBunBuildCommand(entryGlobs, distRel, buildConfig = {}, tsconfig = null) {
241
+ const sourcemapFlag = resolveSourcemapFlag(buildConfig, tsconfig)
242
+ const minifyFlags = resolveMinifyFlags(buildConfig)
243
+ const flags = [...minifyFlags, ...(sourcemapFlag ? [sourcemapFlag] : []), '--outdir', distRel, '--target', 'node', "--external", "'*'"]
244
+ return `bun build ${entryGlobs.join(' ')} ${flags.join(' ')}`.replace(/\s+/g, ' ').trim()
245
+ }
246
+
247
+ export function resolveEffectiveBuildOptions(root, layout, buildConfig = {}) {
248
+ const tsconfig = readTsconfigJson(root, buildConfig)
249
+ const distRel = resolveDistRelWithTsconfig(root, layout, buildConfig, tsconfig)
250
+ const entryGlobs = resolveBuildEntryGlobs(layout.mainFolderPath, buildConfig, tsconfig)
251
+
252
+ return {
253
+ tsconfig,
254
+ tsconfigRel: tsconfig?.rel ?? null,
255
+ distRel,
256
+ entryGlobs,
257
+ typecheck: resolveTypecheckEnabled(buildConfig),
258
+ declarations: resolveDeclarationsEnabled(buildConfig, tsconfig),
259
+ sourcemap: resolveSourcemapFlag(buildConfig, tsconfig) || 'false',
260
+ minify: resolveMinifyFlags(buildConfig).join(' ') || 'off',
261
+ distSource: typeof buildConfig.outDir === 'string'
262
+ ? 'tmp.build.outDir'
263
+ : tsconfig?.compilerOptions?.outDir
264
+ ? 'tsconfig.outDir'
265
+ : 'tmp.paths.dist',
266
+ globSource: Array.isArray(buildConfig.entries) && buildConfig.entries.length > 0
267
+ ? 'tmp.build.entries'
268
+ : typeof buildConfig.glob === 'string' && buildConfig.glob.trim()
269
+ ? 'tmp.build.glob'
270
+ : tsconfig?.include?.length
271
+ ? 'tsconfig.include'
272
+ : tsconfig?.compilerOptions?.rootDir
273
+ ? 'tsconfig.rootDir'
274
+ : 'tmp.mainFolderPath',
275
+ }
276
+ }
277
+
278
+ export function resolveCoreBuildSteps(root, distRel, buildConfig = {}) {
279
+ const tsconfigRel = resolveTsconfigRel(root, buildConfig) ?? 'tsconfig.json'
280
+ const steps = [
281
+ `rm -rf ${distRel}`,
282
+ `bun run tsc --project ${tsconfigRel}`,
283
+ `bunx tsc-alias -p ${tsconfigRel}`,
284
+ ]
285
+ if (resolveMinifyEnabled(buildConfig)) {
286
+ steps.push('node x/bin/scripts/minify-dist.mjs')
287
+ }
288
+ steps.push('node x/bin/scripts/fix-dist-imports.mjs')
289
+ steps.push('node x/bin/scripts/clean-source-types.mjs')
290
+ return steps
291
+ }
292
+
293
+ export function resolveServiceBuildSteps(root, layout, buildConfig = {}) {
294
+ const plan = resolveEffectiveBuildOptions(root, layout, buildConfig)
295
+ const steps = []
296
+
297
+ if (plan.typecheck) {
298
+ steps.push(resolveTypecheckCommand(root, buildConfig))
299
+ }
300
+
301
+ steps.push(
302
+ `rm -rf ${plan.distRel}`,
303
+ resolveBunBuildCommand(plan.entryGlobs, plan.distRel, buildConfig, plan.tsconfig),
304
+ )
305
+
306
+ if (plan.declarations) {
307
+ steps.push(resolveTscCommand(root, plan.distRel, buildConfig))
308
+ }
309
+
310
+ return steps
311
+ }
312
+
313
+ export function summarizeBuildPlan(root, layout, buildConfig = {}) {
314
+ const plan = resolveEffectiveBuildOptions(root, layout, buildConfig)
315
+ return {
316
+ distRel: plan.distRel,
317
+ entryGlobs: plan.entryGlobs,
318
+ tsconfigRel: plan.tsconfigRel,
319
+ typecheck: plan.typecheck,
320
+ declarations: plan.declarations,
321
+ sourcemap: plan.sourcemap,
322
+ minify: plan.minify,
323
+ distSource: plan.distSource,
324
+ globSource: plan.globSource,
325
+ }
326
+ }
327
+
328
+ export function resolveDevEntry(root, layout) {
329
+ const tsEntry = path.join(path.resolve(root, layout.mainFolderPath), 'index.ts')
330
+ if (!fs.existsSync(tsEntry)) {
331
+ throw new Error(
332
+ `No index.ts for dev (expected ${path.relative(root, tsEntry)}). Prod: ${layout.rootFolderPath}/${layout.paths.dist}/index.js via xcore start.`,
333
+ )
334
+ }
335
+ return relativeFromRoot(root, tsEntry)
336
+ }
337
+
338
+ export function resolveEnvFiles(envDir, names) {
339
+ return names
340
+ .map((name) => path.join(envDir, name))
341
+ .filter((file) => fs.existsSync(file))
342
+ }
@@ -0,0 +1,164 @@
1
+ import chalk from 'chalk'
2
+
3
+ import { CLI_BIN_NAMES } from './cli-identity.mjs'
4
+
5
+ export const LIST_BULLET = chalk.cyan('◆')
6
+ import { brandTitle } from './banner.mjs'
7
+
8
+ const QUICK_COMMANDS = [
9
+ { cmd: 'create', hint: '<name> [path]', desc: 'Scaffold service · path defaults to cwd' },
10
+ { cmd: 'dev', desc: 'Watch source/index.ts + dev env' },
11
+ { cmd: 'build', desc: 'Bundle to dist/ (tmp.yml layout)' },
12
+ { cmd: 'start', desc: 'Run production dist/index.js' },
13
+ { cmd: 'test', desc: 'Run tests folder from tmp.yml' },
14
+ ]
15
+
16
+ const COMMAND_GROUPS = [
17
+ {
18
+ title: 'Develop',
19
+ items: [
20
+ { cmd: 'dev', desc: 'Watch TypeScript entry + dev env files' },
21
+ { cmd: 'build', desc: 'Bun bundle + optional tsc → dist/' },
22
+ { cmd: 'start', aliases: 'start:dist', desc: 'Run paths.dist/index.js (prod)' },
23
+ { cmd: 'test', desc: 'Run project tests (paths.tests)' },
24
+ ],
25
+ },
26
+ {
27
+ title: 'Project',
28
+ items: [
29
+ { cmd: 'create', hint: '<name> [path]', desc: 'Scaffold template · optional parent dir' },
30
+ { cmd: 'tmp', desc: 'Ensure tmp.yml exists (runtime config seed)' },
31
+ { cmd: 'hooks install', desc: 'Install .git/hooks pre-commit version check' },
32
+ { cmd: 'hooks status', desc: 'Show whether pre-commit hook is installed' },
33
+ { cmd: 'sync-toolchain', desc: 'Sync tsconfig include/outDir/@/* from tmp.yml' },
34
+ ],
35
+ },
36
+ {
37
+ title: 'Diagnostics',
38
+ items: [
39
+ { cmd: 'doctor', desc: 'Runtime · git · @xrystal/core version alignment' },
40
+ { cmd: 'version', desc: 'CLI tool vs project package.json versions' },
41
+ ],
42
+ },
43
+ {
44
+ title: 'Release',
45
+ items: [
46
+ { cmd: 'tag', desc: 'Tag HEAD from package.json (+ core npm publish)' },
47
+ ],
48
+ },
49
+ ]
50
+
51
+ const SECTION_COLORS = {
52
+ Develop: chalk.bold.cyan,
53
+ Project: chalk.bold.green,
54
+ Diagnostics: chalk.bold.yellow,
55
+ Release: chalk.bold.magenta,
56
+ }
57
+
58
+ function termWidth() {
59
+ return Math.min(100, Math.max(56, process.stdout.columns || 80))
60
+ }
61
+
62
+ function commandLabel(item) {
63
+ const alias = item.aliases ? chalk.dim(` · ${item.aliases}`) : ''
64
+ const hint = item.hint ? chalk.dim(` ${item.hint}`) : ''
65
+ return `${chalk.bold.cyan(item.cmd)}${hint}${alias}`
66
+ }
67
+
68
+ function formatTreeLines(items) {
69
+ const lines = []
70
+ for (const item of items) {
71
+ lines.push(` ${LIST_BULLET} ${commandLabel(item)} ${chalk.gray(item.desc)}`)
72
+ }
73
+ return lines.join('\n')
74
+ }
75
+
76
+ /** Bare `xcore` — banner altında kısa, işe yarayan komutlar. */
77
+ export function printQuickStartGuide({ cliName = 'xcore' } = {}) {
78
+ console.log(chalk.bold.yellow('\n Quick start'))
79
+ console.log(formatTreeLines(QUICK_COMMANDS))
80
+ console.log('')
81
+ console.log(` ${chalk.dim('tip')} ${chalk.bold.white(`${cliName} -h`)} ${chalk.gray('· all commands & options')}`)
82
+ console.log(` ${chalk.dim('tip')} ${chalk.bold.white(`${cliName} doctor`)} ${chalk.gray('· verify install & versions')}`)
83
+ console.log('')
84
+ }
85
+
86
+ function formatOptionsSection(cliName) {
87
+ const items = [
88
+ { cmd: '-V, --version', desc: 'Show @xrystal/core CLI version' },
89
+ { cmd: '-h, --help', desc: 'Show full command list' },
90
+ ]
91
+ const lines = [
92
+ chalk.bold.white('\n Options'),
93
+ formatTreeLines(items.map(({ cmd, desc }) => ({ cmd, desc }))),
94
+ '',
95
+ chalk.bold.white(' Aliases'),
96
+ chalk.gray(` ${CLI_BIN_NAMES.join(' · ')}`),
97
+ '',
98
+ chalk.gray(` ${brandTitle()} ${chalk.dim('·')} loaders · tmp.yml · dto · i18n · multi-protocol`),
99
+ chalk.gray(` docs: ${cliName} help <command>`),
100
+ '',
101
+ ]
102
+ return lines.join('\n')
103
+ }
104
+
105
+ /** `xcore -h` — gruplu, renkli, kompakt tam liste. */
106
+ export function formatRootHelp({ cliName = 'xcore' } = {}) {
107
+ const sections = COMMAND_GROUPS.map((group) => {
108
+ const paint = SECTION_COLORS[group.title] ?? chalk.bold.white
109
+ return `${paint(`\n ${group.title}`)}\n${formatTreeLines(group.items)}`
110
+ })
111
+
112
+ return [
113
+ chalk.bold.white(`\n Usage`),
114
+ chalk.gray(` ${cliName} [options] [command]`),
115
+ ...sections,
116
+ formatOptionsSection(cliName),
117
+ ].join('\n')
118
+ }
119
+
120
+ export function formatCreateHelp({ cliName = 'xcore' } = {}) {
121
+ const examples = [
122
+ { cmd: `${cliName} create my-api`, desc: '→ ./my-api (current folder)' },
123
+ { cmd: `${cliName} create my-api ..`, desc: '→ ../my-api' },
124
+ { cmd: `${cliName} create my-api ~/services`, desc: '→ ~/services/my-api' },
125
+ { cmd: `${cliName} create .`, desc: '→ init in current directory' },
126
+ ]
127
+ return [
128
+ chalk.bold.white('\n Usage'),
129
+ chalk.gray(` ${cliName} create ${chalk.cyan('<project-name>')} ${chalk.dim('[target-path]')}`),
130
+ '',
131
+ chalk.bold.yellow(' project-name'),
132
+ ` ${LIST_BULLET} ${chalk.gray('Required folder name, or')} ${chalk.cyan('.')} ${chalk.gray('to use the target directory itself')}`,
133
+ '',
134
+ chalk.bold.yellow(' target-path'),
135
+ ` ${LIST_BULLET} ${chalk.gray('Optional parent directory · default:')} ${chalk.white('cwd')}`,
136
+ '',
137
+ chalk.bold.white(' Examples'),
138
+ formatTreeLines(examples.map(({ cmd, desc }) => ({ cmd, desc }))),
139
+ '',
140
+ ].join('\n')
141
+ }
142
+
143
+ export function formatCreateCommandHelp({ cliName = 'xcore' } = {}) {
144
+ return [
145
+ formatCreateHelp({ cliName }),
146
+ chalk.bold.white(' Options'),
147
+ ` ${LIST_BULLET} ${chalk.bold.cyan('-f, --force')} ${chalk.gray('Allow scaffold in a non-empty directory')}`,
148
+ '',
149
+ ].join('\n')
150
+ }
151
+
152
+ export function isCreateHelpRequest(argv = process.argv) {
153
+ const args = argv.slice(2)
154
+ if (args[0] !== 'create') return false
155
+ if (args.length === 2 && ['-h', '--help'].includes(args[1])) return true
156
+ return false
157
+ }
158
+
159
+ export function isRootHelpRequest(argv = process.argv) {
160
+ const args = argv.slice(2)
161
+ if (!args.length) return false
162
+ if (args.length === 1 && ['-h', '--help', 'help'].includes(args[0])) return true
163
+ return false
164
+ }
@@ -1,12 +1,23 @@
1
1
  import path from 'node:path'
2
2
 
3
+ /**
4
+ * Resolve scaffold target directory.
5
+ *
6
+ * @param {string} projectName Folder name or `.` for current directory
7
+ * @param {string | undefined} targetDir Optional parent path (default: cwd)
8
+ */
3
9
  export function resolveCreateTarget(projectName, targetDir) {
4
10
  const cwd = process.cwd()
5
- const name = (projectName ?? '.').trim()
11
+ const name = String(projectName ?? '').trim()
12
+
13
+ if (!name) {
14
+ throw new Error('project-name is required')
15
+ }
6
16
 
7
17
  if (name === '.' || name === './') {
18
+ const parent = targetDir ? path.resolve(cwd, targetDir) : cwd
8
19
  return {
9
- targetPath: path.resolve(targetDir ? path.resolve(cwd, targetDir) : cwd),
20
+ targetPath: parent,
10
21
  isCurrentDir: true,
11
22
  }
12
23
  }
@@ -17,3 +28,8 @@ export function resolveCreateTarget(projectName, targetDir) {
17
28
  isCurrentDir: false,
18
29
  }
19
30
  }
31
+
32
+ export function formatCreateTargetPreview(projectName, targetDir) {
33
+ const { targetPath, isCurrentDir } = resolveCreateTarget(projectName, targetDir)
34
+ return { targetPath, isCurrentDir, label: isCurrentDir ? targetPath : targetPath }
35
+ }
@@ -0,0 +1,142 @@
1
+ import { execSync } from 'node:child_process'
2
+ import fs from 'node:fs'
3
+ import path from 'node:path'
4
+ import { fileURLToPath } from 'node:url'
5
+
6
+ import { isCorePackageName } from './build-config.mjs'
7
+ import { syncProjectToolchain } from './toolchain-config.mjs'
8
+ import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
9
+
10
+ const CLI_BIN_DIR = path.dirname(fileURLToPath(import.meta.url))
11
+ const CLI_GENERATED_SCHEMA = path.join(CLI_BIN_DIR, '.generated/tmp-schema.mjs')
12
+ const CLI_SCHEMA_SOURCE = 'source/utils/helpers/tmp/tmp-schema.ts'
13
+
14
+ const CORE_EXPORT_SUBPATHS = [
15
+ 'utils',
16
+ 'loader',
17
+ 'loader/controller',
18
+ 'loader/dto',
19
+ 'project',
20
+ ]
21
+
22
+ export function resolveDistLayout(root = process.cwd()) {
23
+ const { layout } = ensureTmpFile(root)
24
+ const distRel = relativeFromRoot(root, layout.pathsAbs.dist).replace(/\\/g, '/')
25
+ const distPrefix = distRel.startsWith('./') ? distRel : `./${distRel}`
26
+
27
+ return {
28
+ layout,
29
+ distRel,
30
+ distPrefix,
31
+ distAbs: layout.pathsAbs.dist,
32
+ rootFolderPath: layout.rootFolderPath,
33
+ distSegment: layout.paths.dist,
34
+ }
35
+ }
36
+
37
+ export function buildCorePackageExports(distPrefix) {
38
+ const base = distPrefix.replace(/\/$/, '')
39
+ const mainEntry = `${base}/project/index`
40
+ const exports = {
41
+ './tsconfig.base.json': './tsconfig.base.json',
42
+ '.': {
43
+ types: `${mainEntry}.d.ts`,
44
+ default: `${mainEntry}.js`,
45
+ },
46
+ }
47
+
48
+ for (const sub of CORE_EXPORT_SUBPATHS) {
49
+ exports[`./${sub}`] = {
50
+ types: `${base}/${sub}/index.d.ts`,
51
+ default: `${base}/${sub}/index.js`,
52
+ }
53
+ }
54
+
55
+ return exports
56
+ }
57
+
58
+ const CORE_PUBLISH_FILES_STATIC = ['x/bin', 'x/tmp.yml', 'x/assets', 'tsconfig.base.json', 'README.md']
59
+
60
+ function normalizeFilesList(files, distRel) {
61
+ const distEntry = distRel.replace(/^\.\//, '')
62
+ const base = [...CORE_PUBLISH_FILES_STATIC]
63
+ if (!base.includes(distEntry)) base.unshift(distEntry)
64
+ return base
65
+ }
66
+
67
+ function stablePackageShape(pkg) {
68
+ return {
69
+ main: pkg.main,
70
+ types: pkg.types,
71
+ exports: pkg.exports,
72
+ files: pkg.files,
73
+ }
74
+ }
75
+
76
+ export function syncCliTmpSchema(root = process.cwd(), { force = false } = {}) {
77
+ const srcAbs = path.join(root, CLI_SCHEMA_SOURCE)
78
+ if (!fs.existsSync(srcAbs)) {
79
+ return { synced: false, reason: 'missing source' }
80
+ }
81
+
82
+ const outDir = path.dirname(CLI_GENERATED_SCHEMA)
83
+ const needsSync = force
84
+ || !fs.existsSync(CLI_GENERATED_SCHEMA)
85
+ || fs.statSync(srcAbs).mtimeMs > fs.statSync(CLI_GENERATED_SCHEMA).mtimeMs
86
+
87
+ if (!needsSync) return { synced: false, reason: 'up-to-date', out: CLI_GENERATED_SCHEMA }
88
+
89
+ fs.mkdirSync(outDir, { recursive: true })
90
+ execSync(
91
+ `bun build "${srcAbs}" --outfile "${CLI_GENERATED_SCHEMA}" --target node --format esm`,
92
+ { cwd: root, stdio: 'pipe' },
93
+ )
94
+ fs.writeFileSync(path.join(outDir, '.generated-from'), `${CLI_SCHEMA_SOURCE}\n`)
95
+
96
+ return { synced: true, out: CLI_GENERATED_SCHEMA }
97
+ }
98
+
99
+ export function syncPackageManifest(root = process.cwd(), { write = true } = {}) {
100
+ const pkgPath = path.join(root, 'package.json')
101
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
102
+
103
+ if (!isCorePackageName(pkg.name)) {
104
+ return { synced: false, reason: 'not @xrystal/core' }
105
+ }
106
+
107
+ const { distPrefix, distRel } = resolveDistLayout(root)
108
+ const next = {
109
+ ...pkg,
110
+ main: `${distPrefix}/project/index.js`,
111
+ types: `${distPrefix}/project/index.d.ts`,
112
+ exports: buildCorePackageExports(distPrefix),
113
+ files: normalizeFilesList(pkg.files, distRel),
114
+ }
115
+
116
+ const changed = JSON.stringify(stablePackageShape(pkg)) !== JSON.stringify(stablePackageShape(next))
117
+ if (write && changed) {
118
+ fs.writeFileSync(pkgPath, `${JSON.stringify(next, null, 2)}\n`)
119
+ }
120
+
121
+ return { synced: true, wrote: write && changed, distPrefix, distRel, changed }
122
+ }
123
+
124
+ /** tmp.yml → toolchain + CLI schema (+ core package exports on build/release). */
125
+ export function ensureProjectArtifacts(root = process.cwd(), options = {}) {
126
+ const {
127
+ writeToolchain = false,
128
+ writeManifest = false,
129
+ forceSchema = false,
130
+ } = options
131
+
132
+ const schema = syncCliTmpSchema(root, { force: forceSchema })
133
+ const toolchain = syncProjectToolchain(root, { write: writeToolchain })
134
+ let manifest = { synced: false, reason: 'skipped' }
135
+
136
+ const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
137
+ if (isCorePackageName(pkg.name) && writeManifest) {
138
+ manifest = syncPackageManifest(root, { write: true })
139
+ }
140
+
141
+ return { schema, toolchain, manifest }
142
+ }