@xrystal/core 3.51.6 → 3.52.1

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 (121) hide show
  1. package/README.md +35 -1
  2. package/package.json +2 -1
  3. package/x/bin/commands/create.mjs +44 -0
  4. package/x/bin/commands/projects.mjs +53 -0
  5. package/x/bin/commands/sync.mjs +49 -1
  6. package/x/bin/commands/tmp.mjs +1 -1
  7. package/x/bin/helpers/.generated/.generated-from +2 -0
  8. package/x/bin/helpers/.generated/seed-from-tmp.mjs +25 -31
  9. package/x/bin/helpers/.generated/tmp-schema.mjs +156 -96
  10. package/x/bin/helpers/.generated/workspace.mjs +402 -0
  11. package/x/bin/helpers/.generated/xrystal-home-registry.mjs +310 -0
  12. package/x/bin/helpers/build-config.mjs +3 -2
  13. package/x/bin/helpers/cli-help.mjs +3 -1
  14. package/x/bin/helpers/project-artifacts.mjs +10 -0
  15. package/x/bin/helpers/tmp-config.mjs +13 -12
  16. package/x/bin/helpers/tmp-layout.mjs +28 -52
  17. package/x/bin/helpers/tmp-schema.mjs +9 -3
  18. package/x/bin/helpers/workspace-resolve.mjs +11 -0
  19. package/x/bin/helpers/workspace-scaffold.mjs +23 -0
  20. package/x/bin/helpers/xrystal-registry.mjs +13 -0
  21. package/x/bin/main-cli.js +2 -0
  22. package/x/dist/index.js +5 -1
  23. package/x/dist/loader/clients/index.js +22 -1
  24. package/x/dist/loader/configs/index.js +97 -1
  25. package/x/dist/loader/controller/index.js +267 -1
  26. package/x/dist/loader/dto/index.js +92 -1
  27. package/x/dist/loader/events/index.js +39 -1
  28. package/x/dist/loader/index.js +13 -1
  29. package/x/dist/loader/kafka/index.js +142 -1
  30. package/x/dist/loader/kafka/resolve-ssl.js +23 -1
  31. package/x/dist/loader/localizations/index.js +46 -1
  32. package/x/dist/loader/logger/index.js +229 -2
  33. package/x/dist/loader/mongo/index.js +52 -1
  34. package/x/dist/loader/mongo/resolve-connect.js +16 -1
  35. package/x/dist/loader/redis/index.js +57 -1
  36. package/x/dist/loader/redis/resolve-socket.js +31 -1
  37. package/x/dist/loader/registry/index.js +1 -1
  38. package/x/dist/loader/service/index.js +7 -1
  39. package/x/dist/loader/system/index.js +26 -1
  40. package/x/dist/project/index.js +51 -1
  41. package/x/dist/utils/constants/defaults.json +3 -1
  42. package/x/dist/utils/constants/index.d.ts +1 -0
  43. package/x/dist/utils/constants/index.js +42 -1
  44. package/x/dist/utils/constants/package-root.js +6 -1
  45. package/x/dist/utils/helpers/configs/index.js +1 -1
  46. package/x/dist/utils/helpers/context/controller-store.js +12 -1
  47. package/x/dist/utils/helpers/context/index.js +24 -1
  48. package/x/dist/utils/helpers/core/handlebars-resolve.js +15 -1
  49. package/x/dist/utils/helpers/core/index.js +46 -1
  50. package/x/dist/utils/helpers/core/paths.js +78 -1
  51. package/x/dist/utils/helpers/core/tmp-layout.d.ts +4 -4
  52. package/x/dist/utils/helpers/core/tmp-layout.js +229 -1
  53. package/x/dist/utils/helpers/date/index.js +48 -1
  54. package/x/dist/utils/helpers/dispatch/index.js +53 -1
  55. package/x/dist/utils/helpers/dto/index.js +10 -1
  56. package/x/dist/utils/helpers/filters/index.js +44 -1
  57. package/x/dist/utils/helpers/framework/index.js +18 -1
  58. package/x/dist/utils/helpers/handlers/adapters.js +41 -1
  59. package/x/dist/utils/helpers/handlers/execute.js +82 -1
  60. package/x/dist/utils/helpers/handlers/index.js +31 -1
  61. package/x/dist/utils/helpers/hash/crypto.js +22 -1
  62. package/x/dist/utils/helpers/id/index.js +24 -1
  63. package/x/dist/utils/helpers/index.d.ts +1 -0
  64. package/x/dist/utils/helpers/index.js +28 -1
  65. package/x/dist/utils/helpers/ip/index.js +21 -1
  66. package/x/dist/utils/helpers/is/index.js +35 -1
  67. package/x/dist/utils/helpers/kafka-loader-options/index.js +14 -1
  68. package/x/dist/utils/helpers/locales/index.js +82 -1
  69. package/x/dist/utils/helpers/logger-layer/index.js +33 -1
  70. package/x/dist/utils/helpers/math/index.js +14 -1
  71. package/x/dist/utils/helpers/middleware/index.js +36 -1
  72. package/x/dist/utils/helpers/node-env/index.js +20 -1
  73. package/x/dist/utils/helpers/objects/index.js +55 -1
  74. package/x/dist/utils/helpers/path/index.js +5 -1
  75. package/x/dist/utils/helpers/path/resolve-alias-path.d.ts +1 -1
  76. package/x/dist/utils/helpers/path/resolve-alias-path.js +62 -1
  77. package/x/dist/utils/helpers/protocol/index.d.ts +1 -1
  78. package/x/dist/utils/helpers/protocol/index.js +100 -1
  79. package/x/dist/utils/helpers/protocol/options.js +13 -1
  80. package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +3 -1
  81. package/x/dist/utils/helpers/registry/index.js +103 -1
  82. package/x/dist/utils/helpers/runtime/dto-access.js +5 -1
  83. package/x/dist/utils/helpers/runtime/dto-types.js +1 -1
  84. package/x/dist/utils/helpers/runtime/index.js +2 -1
  85. package/x/dist/utils/helpers/runtime/shutdown.js +36 -1
  86. package/x/dist/utils/helpers/state/index.js +185 -1
  87. package/x/dist/utils/helpers/state/props-from-tmp.js +46 -1
  88. package/x/dist/utils/helpers/state/request-key-guard.js +43 -1
  89. package/x/dist/utils/helpers/state/scopes.js +69 -1
  90. package/x/dist/utils/helpers/string/index.js +9 -1
  91. package/x/dist/utils/helpers/timer/index.js +5 -1
  92. package/x/dist/utils/helpers/tmp/index.d.ts +2 -2
  93. package/x/dist/utils/helpers/tmp/index.js +8 -1
  94. package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +14 -1
  95. package/x/dist/utils/helpers/tmp/path-normalize.js +27 -1
  96. package/x/dist/utils/helpers/tmp/runtime-tmp.js +42 -1
  97. package/x/dist/utils/helpers/tmp/seed-from-tmp.d.ts +2 -2
  98. package/x/dist/utils/helpers/tmp/seed-from-tmp.js +62 -1
  99. package/x/dist/utils/helpers/tmp/tmp-interpolate.js +22 -1
  100. package/x/dist/utils/helpers/tmp/tmp-loader.js +56 -1
  101. package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +35 -23
  102. package/x/dist/utils/helpers/tmp/tmp-schema.js +211 -1
  103. package/x/dist/utils/helpers/tmp/tmp-watch.js +23 -1
  104. package/x/dist/utils/helpers/tmp/toolchain-heal.js +157 -2
  105. package/x/dist/utils/helpers/validates/index.js +20 -1
  106. package/x/dist/utils/helpers/workspace/index.d.ts +42 -0
  107. package/x/dist/utils/helpers/workspace/index.js +222 -0
  108. package/x/dist/utils/helpers/xrystal-home/registry.d.ts +32 -0
  109. package/x/dist/utils/helpers/xrystal-home/registry.js +92 -0
  110. package/x/dist/utils/index.js +3 -1
  111. package/x/dist/utils/models/classes/class.clients.js +142 -1
  112. package/x/dist/utils/models/classes/class.interfaces.js +10 -1
  113. package/x/dist/utils/models/classes/class.service-locator.js +16 -1
  114. package/x/dist/utils/models/classes/class.tmp-file-loader.js +61 -1
  115. package/x/dist/utils/models/classes/class.x.js +181 -1
  116. package/x/dist/utils/models/enums/index.d.ts +9 -1
  117. package/x/dist/utils/models/enums/index.js +169 -1
  118. package/x/dist/utils/models/index.js +9 -1
  119. package/x/dist/utils/models/types/index.js +2 -1
  120. package/x/templates/api-service/tmp.yml +59 -0
  121. package/x/tmp.yml +7 -50
@@ -8,7 +8,8 @@ import { getRuntimeTooling, RuntimeEnum, BundlerEnum, detectCliHostRuntime } fro
8
8
  import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
9
9
  import {
10
10
  normalizeTmpDocument,
11
- readTmpServiceBlock,
11
+ readTmpDependsBlock,
12
+ readTmpBuildBlock,
12
13
  readTmpGlobalBlock,
13
14
  normalizeBundler,
14
15
  resolveEffectiveBundler,
@@ -56,7 +57,7 @@ export function readTmpBuildContext(root) {
56
57
  const ensured = ensureTmpFile(root)
57
58
  const tmp = normalizeTmpDocument(yaml.parse(fs.readFileSync(ensured.tmpFilePath, 'utf8')))
58
59
  const configs = tmp.configs ?? {}
59
- const build = readTmpServiceBlock(configs).build ?? {}
60
+ const build = readTmpBuildBlock(configs)
60
61
  const global = readTmpGlobalBlock(configs)
61
62
  const bundler = resolveEffectiveBundler(normalizeBundler(build.bundler), global.runtime)
62
63
  return { layout: ensured.layout, configs, build, global, runtime: global.runtime, bundler }
@@ -31,7 +31,8 @@ const COMMAND_GROUPS = [
31
31
  { cmd: 'tmp', desc: 'Ensure tmp.yml exists (runtime config seed)' },
32
32
  { cmd: 'hooks install', desc: 'Install .git/hooks pre-commit version check' },
33
33
  { cmd: 'hooks status', desc: 'Show whether pre-commit hook is installed' },
34
- { cmd: 'sync', desc: 'Force-sync tsconfig from tmp.yml (auto-heals otherwise)' },
34
+ { cmd: 'sync', desc: 'Sync tsconfig for project or all workspace entries' },
35
+ { cmd: 'projects', desc: 'List ~/.xrystal registry (workspaces + linked projects)' },
35
36
  ],
36
37
  },
37
38
  {
@@ -121,6 +122,7 @@ export function formatRootHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
121
122
 
122
123
  export function formatCreateHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
123
124
  const examples = [
125
+ { cmd: `${cliName} create demo --workspace`, desc: '→ workspace with api/admin/panel/web' },
124
126
  { cmd: `${cliName} create my-api`, desc: '→ ./my-api (current folder)' },
125
127
  { cmd: `${cliName} create my-api ..`, desc: '→ ../my-api' },
126
128
  { cmd: `${cliName} create my-api ~/services`, desc: '→ ~/services/my-api' },
@@ -19,6 +19,14 @@ function cliGeneratedModules() {
19
19
  source: `${main}/utils/helpers/tmp/tmp-schema.ts`,
20
20
  outfile: path.join(CLI_GENERATED_DIR, 'tmp-schema.mjs'),
21
21
  },
22
+ {
23
+ source: `${main}/utils/helpers/xrystal-home/registry.ts`,
24
+ outfile: path.join(CLI_GENERATED_DIR, 'xrystal-home-registry.mjs'),
25
+ },
26
+ {
27
+ source: `${main}/utils/helpers/workspace/index.ts`,
28
+ outfile: path.join(CLI_GENERATED_DIR, 'workspace.mjs'),
29
+ },
22
30
  {
23
31
  source: `${main}/utils/helpers/tmp/seed-from-tmp.ts`,
24
32
  outfile: path.join(CLI_GENERATED_DIR, 'seed-from-tmp.mjs'),
@@ -78,10 +86,12 @@ export function buildCorePackageExports(distPrefix) {
78
86
  function corePublishFilesStatic() {
79
87
  const root = packageDefaults.packageRootFolder
80
88
  const tmpName = `${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`
89
+ const apiTemplateDir = "x/templates"
81
90
  return [
82
91
  `${root}/bin`,
83
92
  `${root}/${tmpName}`,
84
93
  `${root}/assets`,
94
+ apiTemplateDir,
85
95
  'tsconfig.base.json',
86
96
  'README.md',
87
97
  ]
@@ -1,4 +1,4 @@
1
- import { readTmpServiceBlock } from './tmp-schema.mjs'
1
+ import { readTmpDependsBlock, readTmpGlobalBlock } from './tmp-schema.mjs'
2
2
  import { packageDefaults } from './package-defaults.mjs'
3
3
  const PROTOCOL_ALIASES = {
4
4
  http: 'http',
@@ -24,20 +24,21 @@ export function resolveProtocolsFromConfig(configs = {}) {
24
24
 
25
25
  export function summarizeLoaders(tmp = {}) {
26
26
  const configs = tmp.configs ?? {}
27
- const service = configs.service ?? readTmpServiceBlock(configs)
27
+ const global = readTmpGlobalBlock(configs)
28
+ const depends = configs.depends ?? readTmpDependsBlock(configs)
28
29
 
29
30
  return {
30
- framework: service.framework ?? packageDefaults.framework,
31
- protocols: resolveProtocolsFromConfig(service),
32
- service: service.name,
31
+ framework: global.framework ?? packageDefaults.framework,
32
+ protocols: resolveProtocolsFromConfig(depends),
33
+ project: tmp.project?.name ?? '-',
33
34
  items: [
34
- service.loaders?.dto && { key: 'dto', detail: formatLoaderDetail(service.loaders?.dto) },
35
- service.loaders?.loggers && { key: 'loggers', detail: formatLoaderDetail(service.loaders?.loggers) },
36
- service.loaders?.localization && { key: 'localization', detail: formatLoaderDetail(service.loaders?.localization) },
37
- service.loaders?.configs && { key: 'configs', detail: formatLoaderDetail(service.loaders?.configs) },
38
- service.loaders?.controller && Object.keys(service.loaders?.controller).length > 0 && {
35
+ depends.loaders?.dto && { key: 'dto', detail: formatLoaderDetail(depends.loaders?.dto) },
36
+ depends.loaders?.loggers && { key: 'loggers', detail: formatLoaderDetail(depends.loaders?.loggers) },
37
+ depends.loaders?.localization && { key: 'localization', detail: formatLoaderDetail(depends.loaders?.localization) },
38
+ depends.loaders?.configs && { key: 'configs', detail: formatLoaderDetail(depends.loaders?.configs) },
39
+ depends.loaders?.controller && Object.keys(depends.loaders?.controller).length > 0 && {
39
40
  key: 'controller',
40
- detail: formatLoaderDetail(service.loaders?.controller),
41
+ detail: formatLoaderDetail(depends.loaders?.controller),
41
42
  },
42
43
  ].filter(Boolean),
43
44
  }
@@ -60,7 +61,7 @@ export function formatLoaderSummary(summary) {
60
61
  `framework: ${summary.framework}`,
61
62
  `protocols: ${summary.protocols.join(', ')}`,
62
63
  ]
63
- if (summary.service) lines.push(`service: ${summary.service}`)
64
+ if (summary.project) lines.push(`project: ${summary.project}`)
64
65
  for (const item of summary.items) {
65
66
  lines.push(`${item.key}: ${item.detail}`)
66
67
  }
@@ -5,7 +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
+ import { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, resolveMergedPaths, resolveTmpAbsPath } from './tmp-schema.mjs'
9
9
 
10
10
  function formatTmpTarget(name, ext) {
11
11
  return `${name}${ext.startsWith('.') ? ext : `.${ext}`}`
@@ -49,8 +49,13 @@ export function assertCoreTmpGuard(projectRoot, tmpFilePath) {
49
49
  function findStrayCoreTmpFiles(projectRoot, canonicalPath) {
50
50
  const resolvedRoot = path.resolve(projectRoot)
51
51
  const canonical = path.resolve(canonicalPath)
52
+ const templatesPrefix = `${packageDefaults.packageRootFolder}/templates/`
52
53
  return findAllFilesRecursively(resolvedRoot, packageDefaults.tmpBaseName, packageDefaults.tmpExtension)
53
- .filter((filePath) => path.resolve(filePath) !== canonical)
54
+ .filter((filePath) => {
55
+ if (path.resolve(filePath) === canonical) return false
56
+ const rel = path.relative(resolvedRoot, filePath).replace(/\\/g, '/')
57
+ return !rel.startsWith(templatesPrefix)
58
+ })
54
59
  }
55
60
 
56
61
  export function ensureCoreTmpEntry(projectRoot = process.cwd(), options = {}) {
@@ -91,39 +96,17 @@ function resolveTmpFilePath(projectRoot, tmpFileName, ext) {
91
96
  return findFileRecursively(resolvedRoot, tmpFileName, ext)
92
97
  }
93
98
 
94
- export function resolveRootFolderPath(tmp, tmpFilePath, projectRoot) {
99
+ export function resolveRootFolderPath(tmp, _tmpFilePath, _projectRoot) {
95
100
  const configs = normalizeTmpDocument(tmp ?? {}).configs ?? {}
96
- const service = readTmpServiceBlock(configs)
97
-
98
- if (service.paths?.root?.trim()) {
99
- return normalizeRootFolder(service.paths.root)
100
- }
101
-
102
- if (typeof tmp?.project?.name === 'string' && tmp.project.name.trim()) {
103
- return tmp.project.name.trim()
104
- }
105
-
106
- const relativeDir = path.relative(
107
- path.resolve(projectRoot),
108
- path.dirname(path.resolve(tmpFilePath)),
109
- )
110
- if (relativeDir && relativeDir !== '.') {
111
- return relativeDir
112
- }
113
-
114
- return packageDefaults.packageRootFolder
101
+ return normalizeRootFolder(resolveMergedPaths(configs).root)
115
102
  }
116
103
 
117
104
  export function resolveLayoutPaths(configs) {
118
- return resolveServiceLayoutPaths(readTmpServiceBlock(configs))
105
+ return resolveMergedPaths(configs).special
119
106
  }
120
107
 
121
108
  export function resolveMainFolderPath(configs) {
122
- const source = readTmpServiceBlock(configs).paths?.source
123
- if (typeof source === 'string' && source.trim()) {
124
- return normalizeSourceFolder(source)
125
- }
126
- return packageDefaults.mainSourceFolder
109
+ return normalizeSourceFolder(resolveMergedPaths(configs).source)
127
110
  }
128
111
 
129
112
  export function buildTmpLayout(projectRoot, tmp, tmpFilePath) {
@@ -183,7 +166,10 @@ export function resolveTmpLayoutOrDefaults(projectRoot = process.cwd()) {
183
166
  return buildTmpLayout(projectRoot, readTmpFile(tmpFilePath), tmpFilePath)
184
167
  }
185
168
 
186
- export function ownerTmpFilePath(projectRoot = process.cwd(), layout) {
169
+ export function ownerTmpFilePath(projectRoot = process.cwd(), layout, configs) {
170
+ if (configs) {
171
+ return resolveTmpAbsPath(projectRoot, configs)
172
+ }
187
173
  const resolved = layout ?? resolveTmpLayoutOrDefaults(projectRoot)
188
174
  return path.join(
189
175
  resolved.rootFolderAbs,
@@ -196,7 +182,7 @@ export function relativeFromRoot(projectRoot, absolutePath) {
196
182
  return rel.startsWith('.') ? rel : `./${rel}`
197
183
  }
198
184
 
199
- export function ensureTmpFile(projectRoot = process.cwd(), { patchServiceName = true } = {}) {
185
+ export function ensureTmpFile(projectRoot = process.cwd(), { patchProjectName = true, templatePath } = {}) {
200
186
  const resolvedRoot = path.resolve(projectRoot)
201
187
 
202
188
  if (isCorePackageRoot(resolvedRoot)) {
@@ -233,38 +219,28 @@ export function ensureTmpFile(projectRoot = process.cwd(), { patchServiceName =
233
219
  }
234
220
  }
235
221
 
236
- const templatePath = getBundledCoreTmpPath()
237
- if (!fs.existsSync(templatePath)) {
222
+ const resolvedTemplate = templatePath ?? getBundledCoreTmpPath()
223
+ if (!fs.existsSync(resolvedTemplate)) {
238
224
  throw new Error(`${packageDefaults.packageName} bundled ${packageDefaults.packageRootFolder}/tmp.yml not found in package`)
239
225
  }
240
226
 
241
- const layout = buildTmpLayout(resolvedRoot, null, null)
242
- fs.mkdirSync(layout.rootFolderAbs, { recursive: true })
243
-
244
- const targetPath = path.join(
245
- layout.rootFolderAbs,
246
- formatTmpTarget(packageDefaults.tmpBaseName, packageDefaults.tmpExtension),
247
- )
227
+ let content = fs.readFileSync(resolvedTemplate, 'utf8')
228
+ const templateDoc = readTmpFile(resolvedTemplate)
229
+ const templateConfigs = templateDoc.configs ?? {}
230
+ const targetPath = ownerTmpFilePath(resolvedRoot, undefined, templateConfigs)
231
+ fs.mkdirSync(path.dirname(targetPath), { recursive: true })
248
232
 
249
- let content = fs.readFileSync(templatePath, 'utf8')
250
- if (patchServiceName) {
233
+ if (patchProjectName) {
251
234
  try {
252
235
  const pkgPath = path.join(resolvedRoot, 'package.json')
253
236
  if (fs.existsSync(pkgPath)) {
254
237
  const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
255
- const serviceName = typeof pkg.name === 'string'
256
- ? pkg.name.replace(/^@/, '').replace(/\//g, '-')
238
+ const projectName = typeof pkg.name === 'string'
239
+ ? pkg.name.replace(/^@/, '').replace(/\//g, '-').replace(/-svc$/, '')
257
240
  : null
258
- if (serviceName) {
241
+ if (projectName) {
259
242
  const tmp = yaml.parse(content)
260
- const configs = tmp.configs ?? {}
261
- const service = configs.service
262
- if (typeof service === 'object' && service !== null && !Array.isArray(service)) {
263
- service.name = serviceName
264
- } else {
265
- configs.service = { name: serviceName }
266
- }
267
- tmp.configs = configs
243
+ tmp.project = { name: projectName }
268
244
  content = yaml.stringify(tmp)
269
245
  }
270
246
  }
@@ -4,11 +4,17 @@ export {
4
4
  normalizeTmpDocument,
5
5
  normalizeRuntime,
6
6
  normalizeBundler,
7
+ normalizeGlobalType,
7
8
  resolveEffectiveBundler,
8
- readTmpCoreBlock,
9
- readTmpServiceBlock,
9
+ readTmpDependsBlock,
10
+ readTmpBuildBlock,
10
11
  readTmpGlobalBlock,
12
+ assertNoLegacyTmpKeys,
13
+ resolveTmpDeploymentName,
14
+ readTmpGlobalPathsBlock,
11
15
  applyTmpGlobalVars,
12
- resolveServiceLayoutPaths,
16
+ resolveMergedPaths,
13
17
  resolveTmpRuntimeConfigs,
18
+ resolveProjectRootFromTmpPath,
19
+ resolveTmpAbsPath,
14
20
  } from './.generated/tmp-schema.mjs'
@@ -0,0 +1,11 @@
1
+ export {
2
+ DEFAULT_FOLDER_STRUCTURE,
3
+ findApiServices,
4
+ findEntries,
5
+ findWorkspaceRoot,
6
+ normalizeGlobalType,
7
+ readWorkspaceCoreTmp,
8
+ resolveEntryPath,
9
+ workspaceProjectName,
10
+ workspaceTmpTemplate,
11
+ } from './.generated/workspace.mjs'
@@ -0,0 +1,23 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+
4
+ import { DEFAULT_FOLDER_STRUCTURE, workspaceTmpTemplate } from './workspace-resolve.mjs'
5
+
6
+ export function scaffoldWorkspace(targetPath, projectName) {
7
+ const resolved = path.resolve(targetPath)
8
+ fs.mkdirSync(resolved, { recursive: true })
9
+
10
+ const tmpPath = path.join(resolved, 'tmp.yml')
11
+ if (fs.existsSync(tmpPath)) {
12
+ throw new Error(`workspace tmp.yml already exists: ${tmpPath}`)
13
+ }
14
+
15
+ fs.writeFileSync(tmpPath, workspaceTmpTemplate(projectName))
16
+ fs.writeFileSync(path.join(resolved, '.gitignore'), '.env.telepresence\n.env.local\n.env.private\n')
17
+
18
+ for (const dir of Object.values(DEFAULT_FOLDER_STRUCTURE)) {
19
+ fs.mkdirSync(path.join(resolved, dir), { recursive: true })
20
+ }
21
+
22
+ return { root: resolved, tmpPath }
23
+ }
@@ -0,0 +1,13 @@
1
+ export {
2
+ ensureXrystalHome,
3
+ entryToRegistryProject,
4
+ listRegistryProjects,
5
+ readRegistry,
6
+ registryFilePath,
7
+ resolveXrystalHome,
8
+ scanWorkspace,
9
+ syncRegistryFromPath,
10
+ upsertWorkspace,
11
+ writeRegistry,
12
+ XRYSTAL_HOME_DIR,
13
+ } from './.generated/xrystal-home-registry.mjs'
package/x/bin/main-cli.js CHANGED
@@ -8,6 +8,7 @@ import { registerDoctorCommand } from './commands/doctor.mjs'
8
8
  import { registerProjectCommands } from './commands/project.mjs'
9
9
  import { registerTmpCommand } from './commands/tmp.mjs'
10
10
  import { registerSyncCommand } from './commands/sync.mjs'
11
+ import { registerProjectsCommand } from './commands/projects.mjs'
11
12
  import { registerTagCommand, registerVersionCommand } from './commands/release.mjs'
12
13
  import { registerHooksCommand } from './commands/hooks.mjs'
13
14
  import { printBanner, shouldShowBanner } from './helpers/banner.mjs'
@@ -66,6 +67,7 @@ registerTagCommand(cli, cliContext)
66
67
  registerDoctorCommand(cli, cliContext)
67
68
  registerTmpCommand(cli, cliContext)
68
69
  registerSyncCommand(cli, cliContext)
70
+ registerProjectsCommand(cli, cliContext)
69
71
  registerHooksCommand(cli, cliContext)
70
72
  registerProjectCommands(cli, cliContext)
71
73
 
package/x/dist/index.js CHANGED
@@ -1 +1,5 @@
1
- import a from"./project/index.js";await(async()=>{await a({})})();
1
+ import coreLoader from './project/index.js';
2
+ // => core => xrystal
3
+ await (async () => {
4
+ await coreLoader({});
5
+ })();
@@ -1 +1,22 @@
1
- import{BaseApiClient as t,CoreClientsEnum as s}from "../../utils/index.js";import{bindLoaderTmpSync as i}from "../../utils/index.js";export default class Clients{_instances={};#s;constructor({configs:n}){this.#s=n}async onInit(){await this.syncFromTmp();i(this)}syncFromTmp=async()=>{this._instances[s.BASE_API_CLIENT]=new t({clientName:s.BASE_API_CLIENT,baseURL:this.#s.all.baseApiUri||""})};get instances(){return this._instances}}
1
+ import { BaseApiClient, CoreClientsEnum } from "../../utils/index.js";
2
+ import { bindLoaderTmpSync } from '../../utils/index.js';
3
+ export default class Clients {
4
+ _instances = {};
5
+ #configs;
6
+ constructor({ configs }) {
7
+ this.#configs = configs;
8
+ }
9
+ async onInit() {
10
+ await this.syncFromTmp();
11
+ bindLoaderTmpSync(this);
12
+ }
13
+ syncFromTmp = async () => {
14
+ this._instances[CoreClientsEnum.BASE_API_CLIENT] = new BaseApiClient({
15
+ clientName: CoreClientsEnum.BASE_API_CLIENT,
16
+ baseURL: this.#configs.all.baseApiUri || '',
17
+ });
18
+ };
19
+ get instances() {
20
+ return this._instances;
21
+ }
22
+ }
@@ -1 +1,97 @@
1
- import x from"node:path";import W from"lodash";import{pathToFileURL as F}from"node:url";import{Constants as X}from "../../utils/constants/index.js";import{resolveTmpLoadPath as K}from "../../utils/helpers/path/resolve-alias-path.js";import{bindLoaderTmpSync as R}from "../../utils/helpers/tmp/loader-tmp-sync.js";import{normalizeNodeEnv as I}from "../../utils/helpers/node-env/index.js";import{readKafkaLoaderOptions as S}from "../../utils/helpers/kafka-loader-options/index.js";export default class Configs{publicFolderName=X.publicFolderName;kafkaLogsTopic=X.kafkaLogsTopic;#A;#q;constructor({system:A}){this.#A=A;return new Proxy(this,{get:(G,H)=>{return G[H]||G.config?.[H]}})}onInit=async()=>{await this.syncFromTmp();R(this)};syncFromTmp=async()=>{const A=process.cwd(),q=this.#A.tmp,G=q.configs.service.loaders.configs.loadPath,H=K(G,q,A),Y=import(F(H).href);this.#q={worker:process.env.WORKER==="true"?!0:!1,mode:process.env.MODE,nodeEnv:I("development"),debug:process.env.SYSTEM_LOGGER_LAYER??"",https:process.env.HTTPS??"false",httpsfileEncoding:process.env.ENCODING||"utf8",httpsCertfile:process.env.HTTPS_CERT_FILE??"",httpsKeyfile:process.env.HTTPS_KEY_FILE??"",rootFolderPath:q.configs.rootFolderPath||"x",projectName:q.project.name,serviceName:q.configs.service.name??"",projectNamePrefixEnv:process.env.PROJECT_NAME_PREFIX||"",projectNameEnv:process.env.PROJECT_NAME||"",projectNameSuffixEnv:process.env.PROJECT_NAME_SUFFIX||"",systemStaticFolderPath:x.resolve(q.configs.rootFolderPath,this.publicFolderName),systemLoggerLayer:process.env.SYSTEM_LOGGER_LAYER??"info",isKafkaPassive:!S(q.configs.service.loaders).enabled,kafkaClientId:q.configs.service.name??"",kafkaBrokers:process.env.KAFKA_BROKERS??"",kafkaUsername:process.env.KAFKA_USERNAME??"",kafkaPassword:process.env.KAFKA_PASSWORD??"",kafkaTopics:[],kafkaLogsTopic:this.kafkaLogsTopic,isRedisPassive:process.env.IS_REDIS_PASSIVE==="true"?!0:!1,redisUri:process.env.REDIS_URI??"",isMongoPassive:process.env.IS_MONGODB_PASSIVE==="true"?!0:!1,mongodbUri:process.env.MONGODB_URI??"",isRegistryEnabled:process.env.IS_REGISTRY_ENABLED==="true",registryMongodbUri:process.env.REGISTRY_MONGODB_URI??"",baseApiUri:process.env.HTTPS==="true"?process.env.SYSTEM_HTTPS_BASE_API_URI??"":process.env.SYSTEM_BASE_API_URI??"",port:Number(process.env.PORT),internalSecret:process.env.INTERNAL_SECRET??"",secret:process.env.SECRET??"",cwd:A,env:I("development")};try{const B=await Y,Z=B?.default||B?.configs||B||{},J=W.mergeWith({},this.#q,Z,(Q,$)=>{if(W.isArray(Q))return Q.concat($)}),M=I(J.nodeEnv??J.env??"development");this.#q=Object.freeze({...J,nodeEnv:M,env:M})}catch{const B=I(this.#q.nodeEnv??this.#q.env??"development");this.#q=Object.freeze({...this.#q,nodeEnv:B,env:B})}};setConfig(A){const q=Object.assign(this.#q,A);this.#q=Object.freeze(q)}_(A){return this.#q[A]}get all(){return this.#q}}
1
+ import path from 'node:path';
2
+ import _ from 'lodash';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { Constants } from '../../utils/constants/index.js';
5
+ import { resolveTmpLoadPath } from '../../utils/helpers/path/resolve-alias-path.js';
6
+ import { bindLoaderTmpSync } from '../../utils/helpers/tmp/loader-tmp-sync.js';
7
+ import { normalizeNodeEnv } from '../../utils/helpers/node-env/index.js';
8
+ import { readKafkaLoaderOptions } from '../../utils/helpers/kafka-loader-options/index.js';
9
+ export default class Configs {
10
+ publicFolderName = Constants.publicFolderName;
11
+ kafkaLogsTopic = Constants.kafkaLogsTopic;
12
+ #system;
13
+ #config;
14
+ constructor({ system }) {
15
+ this.#system = system;
16
+ const proxy = new Proxy(this, {
17
+ get: (target, prop) => {
18
+ return target[prop] || target.config?.[prop];
19
+ }
20
+ });
21
+ return proxy;
22
+ }
23
+ onInit = async () => {
24
+ await this.syncFromTmp();
25
+ bindLoaderTmpSync(this);
26
+ };
27
+ syncFromTmp = async () => {
28
+ const cwd = process.cwd();
29
+ const tmp = this.#system.tmp;
30
+ const extendConfigs = tmp.configs.service.loaders.configs.loadPath;
31
+ const fullPath = resolveTmpLoadPath(extendConfigs, tmp, cwd);
32
+ const fileUrl = pathToFileURL(fullPath).href;
33
+ const modulePromise = import(fileUrl);
34
+ this.#config = {
35
+ worker: process.env.WORKER === 'true' ? true : false || false,
36
+ mode: process.env.MODE,
37
+ nodeEnv: normalizeNodeEnv(process.env.NODE_ENV),
38
+ debug: process.env.SYSTEM_LOGGER_LAYER ?? '',
39
+ https: process.env.HTTPS ?? 'false',
40
+ httpsfileEncoding: process.env.ENCODING || 'utf8',
41
+ httpsCertfile: process.env.HTTPS_CERT_FILE ?? '',
42
+ httpsKeyfile: process.env.HTTPS_KEY_FILE ?? '',
43
+ rootFolderPath: tmp.configs.rootFolderPath || 'x',
44
+ projectName: tmp.project.name,
45
+ serviceName: tmp.configs.service.name ?? "",
46
+ projectNamePrefixEnv: process.env.PROJECT_NAME_PREFIX || '',
47
+ projectNameEnv: process.env.PROJECT_NAME || '',
48
+ projectNameSuffixEnv: process.env.PROJECT_NAME_SUFFIX || '',
49
+ systemStaticFolderPath: path.resolve(tmp.configs.rootFolderPath, this.publicFolderName),
50
+ systemLoggerLayer: process.env.SYSTEM_LOGGER_LAYER ?? 'info',
51
+ isKafkaPassive: !readKafkaLoaderOptions(tmp.configs.service.loaders).enabled,
52
+ kafkaClientId: tmp.configs.service.name ?? "",
53
+ kafkaBrokers: process.env.KAFKA_BROKERS ?? '',
54
+ kafkaUsername: process.env.KAFKA_USERNAME ?? '',
55
+ kafkaPassword: process.env.KAFKA_PASSWORD ?? '',
56
+ kafkaTopics: [],
57
+ kafkaLogsTopic: this.kafkaLogsTopic,
58
+ isRedisPassive: process.env.IS_REDIS_PASSIVE === 'true' ? true : false,
59
+ redisUri: process.env.REDIS_URI ?? '',
60
+ isMongoPassive: process.env.IS_MONGODB_PASSIVE === 'true' ? true : false,
61
+ mongodbUri: process.env.MONGODB_URI ?? '',
62
+ isRegistryEnabled: process.env.IS_REGISTRY_ENABLED === 'true',
63
+ registryMongodbUri: process.env.REGISTRY_MONGODB_URI ?? '',
64
+ baseApiUri: process.env.HTTPS === 'true' ? (process.env.SYSTEM_HTTPS_BASE_API_URI ?? '') : (process.env.SYSTEM_BASE_API_URI ?? ''),
65
+ port: Number(process.env.PORT),
66
+ internalSecret: process.env.INTERNAL_SECRET ?? '',
67
+ secret: process.env.SECRET ?? '',
68
+ cwd,
69
+ env: normalizeNodeEnv(process.env.NODE_ENV),
70
+ };
71
+ try {
72
+ const moduleData = await modulePromise;
73
+ const importedConfigs = moduleData?.default || moduleData?.configs || moduleData || {};
74
+ const merged = _.mergeWith({}, this.#config, importedConfigs, (objValue, srcValue) => {
75
+ if (_.isArray(objValue)) {
76
+ return objValue.concat(srcValue);
77
+ }
78
+ });
79
+ const nodeEnv = normalizeNodeEnv(merged.nodeEnv ?? merged.env ?? process.env.NODE_ENV);
80
+ this.#config = Object.freeze({ ...merged, nodeEnv, env: nodeEnv });
81
+ }
82
+ catch {
83
+ const nodeEnv = normalizeNodeEnv(this.#config.nodeEnv ?? this.#config.env ?? process.env.NODE_ENV);
84
+ this.#config = Object.freeze({ ...this.#config, nodeEnv, env: nodeEnv });
85
+ }
86
+ };
87
+ setConfig(newConfigs) {
88
+ const mergedDObj = Object.assign(this.#config, newConfigs);
89
+ this.#config = Object.freeze(mergedDObj);
90
+ }
91
+ _(key) {
92
+ return this.#config[key];
93
+ }
94
+ get all() {
95
+ return this.#config;
96
+ }
97
+ }