@xrystal/core 3.52.4 → 3.52.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,25 +3,25 @@
3
3
  > **EN** — Microservice runtime: Express or Elysia HTTP, DI loaders, live `tmp.yml`, standardized API responses.
4
4
  > **TR** — Microservice runtime: Express veya Elysia HTTP, DI loader'lar, canlı `tmp.yml`, standart API cevapları.
5
5
 
6
- **CLI:** `xry` · **Version:** `3.52.4` · [npm](https://www.npmjs.com/package/@xrystal/core)
6
+ **CLI:** `xry` · **Version:** `3.52.5` · [npm](https://www.npmjs.com/package/@xrystal/core)
7
7
 
8
8
  ---
9
9
 
10
10
  ## Platform services / Platform servisleri
11
11
 
12
- **EN:** Consumer microservices in `../services/` — pin `@xrystal/core` to the latest published minor (currently **3.52.4**).
12
+ **EN:** Consumer microservices in `../services/` — pin `@xrystal/core` to the latest published minor (currently **3.52.5**).
13
13
 
14
- **TR:** `../services/` altındaki tüketen microservice'ler — `@xrystal/core` sürümünü npm latest ile hizala (şu an **3.52.4**).
14
+ **TR:** `../services/` altındaki tüketen microservice'ler — `@xrystal/core` sürümünü npm latest ile hizala (şu an **3.52.5**).
15
15
 
16
16
  | Repo folder | `tmp.yml` name | Role | Service pkg | `@xrystal/core` |
17
17
  |-------------|----------------|------|-------------|-----------------|
18
- | `api-core-svc` | `core` | Core domain API | `1.0.24` | `3.52.4` |
19
- | `api-cron-svc` | `crons` | Scheduled jobs / Kafka queue worker | `0.1.25` | `3.52.4` |
20
- | `api-gateway-svc` | `gateway` | Edge gateway, routing, cache, Mongo config | `2.0.49` | `3.52.4` |
21
- | `api-gpt-svc` | `gpt` | GPT / AI features | `1.0.22` | `3.52.4` |
22
- | `api-iam-svc` | `iam` | Identity & access management | `0.7.26` | `3.52.4` |
23
- | `api-log-svc` | `log` | Logging service | `1.0.20` | `3.52.4` |
24
- | `api-websocket-svc` | `websocket` | WebSocket / realtime | `0.8.31` | `3.52.4` |
18
+ | `api-core-svc` | `core` | Core domain API | `1.0.24` | `3.52.5` |
19
+ | `api-cron-svc` | `crons` | Scheduled jobs / Kafka queue worker | `0.1.25` | `3.52.5` |
20
+ | `api-gateway-svc` | `gateway` | Edge gateway, routing, cache, Mongo config | `2.0.49` | `3.52.5` |
21
+ | `api-gpt-svc` | `gpt` | GPT / AI features | `1.0.22` | `3.52.5` |
22
+ | `api-iam-svc` | `iam` | Identity & access management | `0.7.26` | `3.52.5` |
23
+ | `api-log-svc` | `log` | Logging service | `1.0.20` | `3.52.5` |
24
+ | `api-websocket-svc` | `websocket` | WebSocket / realtime | `0.8.31` | `3.52.5` |
25
25
 
26
26
  **SSL / TLS helpers** (since 3.49.0): import from loader subpaths, not `@xrystal/core/utils`:
27
27
 
@@ -35,7 +35,7 @@ import { resolveMongoConnectOptions } from '@xrystal/core/loader/mongo'
35
35
 
36
36
  ```bash
37
37
  cd ../services/api-<name>-svc
38
- bun add @xrystal/core@3.52.4
38
+ bun add @xrystal/core@3.52.5
39
39
  bun run build
40
40
  ```
41
41
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.52.4",
4
+ "version": "3.52.5",
5
5
  "description": "microservice runtime library",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -60,17 +60,28 @@ export function registerCreateCommand(cli, { cliName = CLI_PRIMARY_NAME, runtime
60
60
  try {
61
61
  const version = readCliPackageJson().version
62
62
  printCommandHeader({ cliName, command: 'create (workspace)', version })
63
- const result = scaffoldWorkspace(targetPath, name)
63
+ const result = scaffoldWorkspace(targetPath, name, {
64
+ coreVersion: version,
65
+ installCommand,
66
+ cliName,
67
+ })
64
68
  console.log(chalk.green('\n✓ Workspace ready\n'))
65
69
  console.log(chalk.gray(` tmp: ${path.relative(process.cwd(), result.tmpPath) || result.tmpPath}`))
70
+ console.log(chalk.gray(` end.version: ${version}`))
66
71
  console.log(chalk.gray(' folders: api/, admin/, web/'))
67
- console.log(chalk.gray(' link services into api/ (type optional) or admin|web (type: frontend)'))
72
+ if (result.general) {
73
+ console.log(chalk.green(' api/general: monolith scaffold (gpt template)'))
74
+ console.log(chalk.gray(` tmp: ${path.relative(process.cwd(), result.general.tmpFilePath) || result.general.tmpFilePath}`))
75
+ }
76
+ console.log(chalk.gray(' link more services into api/ or admin|web (frontend)'))
77
+ console.log(chalk.gray(' telepresence: .env.telepresence.example + x/environments/.env.telepresence'))
68
78
  console.log(chalk.cyan(`\n cd ${path.relative(process.cwd(), result.root) || result.root}`))
69
79
  try {
70
80
  syncRegistryFromPath(result.root)
71
81
  console.log(chalk.gray(' registered in ~/.xrystal'))
72
82
  } catch {}
73
83
  console.log(chalk.cyan(` ${cliName} sync`))
84
+ console.log(chalk.cyan(` ${cliName} telepresence dev general`))
74
85
  printCommandFooter({ version })
75
86
  } catch (error) {
76
87
  console.error(chalk.red(`\n✗ ${error.message}\n`))
@@ -1,9 +1,12 @@
1
1
  import chalk from 'chalk'
2
+ import path from 'node:path'
2
3
 
3
4
  import { printCommandFooter, printCommandHeader } from '../helpers/banner.mjs'
4
5
  import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
5
6
  import { getProjectRoot, readCliPackageJson } from '../helpers/project-root.mjs'
6
7
  import { auditTsconfigAlignment, syncProjectToolchain } from '../helpers/toolchain-config.mjs'
8
+ import { ensureTmpFile } from '../helpers/tmp-layout.mjs'
9
+ import { patchTmpEndVersion } from '../helpers/tmp-end-version.mjs'
7
10
  import { findEntries, findWorkspaceRoot } from '../helpers/workspace-resolve.mjs'
8
11
  import { syncCliRuntime } from '../helpers/project-artifacts.mjs'
9
12
  import { syncCoreDependency } from '../helpers/sync-core-dependency.mjs'
@@ -23,6 +26,12 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
23
26
  console.log(chalk.gray(` workspace: ${workspaceRoot}`))
24
27
  console.log(chalk.gray(` entries: ${entries.length}`))
25
28
 
29
+ const wsTmp = path.join(workspaceRoot, 'tmp.yml')
30
+ if (!options.dryRun) {
31
+ const wsEnd = patchTmpEndVersion(wsTmp, coreVersion)
32
+ if (wsEnd.patched) console.log(chalk.green(` workspace end.version → ${coreVersion}`))
33
+ }
34
+
26
35
  if (entries.length === 0) {
27
36
  console.log(chalk.yellow('\n no linked projects under api/admin/web yet'))
28
37
  printCommandFooter({ version: coreVersion })
@@ -56,9 +65,13 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
56
65
  ? chalk.gray(` would pin ${packageDefaults.packageName}@${coreVersion}`)
57
66
  : chalk.green(` pinned ${packageDefaults.packageName}@${coreVersion}`)
58
67
  console.log(label)
59
- } else if (core.reason === 'up-to-date') {
68
+ } else if (core.reason === 'up-to-date') {
60
69
  console.log(chalk.gray(` ${packageDefaults.packageName}@${coreVersion} (ok)`))
61
70
  }
71
+ if (!options.dryRun) {
72
+ const end = patchTmpEndVersion(entry.tmp, coreVersion)
73
+ if (end.patched) console.log(chalk.green(` end.version → ${coreVersion}`))
74
+ }
62
75
  } catch (error) {
63
76
  failed += 1
64
77
  console.log(chalk.red(` failed: ${error.message}`))
@@ -104,6 +117,9 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
104
117
  }
105
118
 
106
119
  const result = syncProjectToolchain(root, { write: true })
120
+ const layout = ensureTmpFile(root)
121
+ const end = patchTmpEndVersion(layout.tmpFilePath, coreVersion)
122
+ if (end.patched) console.log(chalk.green(` end.version → ${coreVersion}`))
107
123
  console.log(result.created
108
124
  ? chalk.green(` created ${result.tsconfigRel}`)
109
125
  : chalk.green(` updated ${result.tsconfigRel}`))
@@ -0,0 +1,134 @@
1
+ import { execSync } from 'node:child_process'
2
+ import fs from 'node:fs'
3
+ import path from 'node:path'
4
+ import chalk from 'chalk'
5
+
6
+ import { printCommandFooter, printCommandHeader } from '../helpers/banner.mjs'
7
+ import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
8
+ import { readCliPackageJson } from '../helpers/project-root.mjs'
9
+ import {
10
+ ensureServiceTelepresenceEnv,
11
+ resolveTelepresenceServiceDir,
12
+ TELEPRESENCE_DEPLOYMENTS,
13
+ } from '../helpers/telepresence-layout.mjs'
14
+ import { findWorkspaceRoot } from '../helpers/workspace-resolve.mjs'
15
+
16
+ function resolveInfraHelper(name) {
17
+ const envRoot = process.env.XRYSTAL_INFRA_DIR ?? process.env.XRYSTAL_INFRA_ROOT
18
+ const candidates = [
19
+ envRoot,
20
+ path.resolve(process.cwd(), '../-infrastructure-'),
21
+ path.resolve(process.cwd(), '../../-infrastructure-'),
22
+ ].filter(Boolean)
23
+
24
+ for (const root of candidates) {
25
+ const script = path.join(root, 'scripts', 'helpers', name)
26
+ if (fs.existsSync(script)) return script
27
+ }
28
+ return null
29
+ }
30
+
31
+ function runHelper(scriptPath, args, { cwd } = {}) {
32
+ execSync(`bash "${scriptPath}" ${args.map((a) => JSON.stringify(a)).join(' ')}`, {
33
+ cwd: cwd ?? process.cwd(),
34
+ stdio: 'inherit',
35
+ env: process.env,
36
+ })
37
+ }
38
+
39
+ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
40
+ const tp = cli
41
+ .command('telepresence')
42
+ .alias('tp')
43
+ .description('Local Telepresence intercept against cluster (dev/test)')
44
+ .addHelpText(
45
+ 'after',
46
+ `
47
+ ${chalk.gray('Examples:')}
48
+ ${cliName} telepresence connect
49
+ ${cliName} tp dev general
50
+ ${cliName} tp dev gateway 3000
51
+ ${cliName} telepresence quit
52
+
53
+ ${chalk.gray('Deploy names:')} ${TELEPRESENCE_DEPLOYMENTS.join(', ')}
54
+ ${chalk.gray('Set')} XRYSTAL_INFRA_DIR ${chalk.gray('to point at -infrastructure- repo (optional).')}
55
+ `,
56
+ )
57
+
58
+ tp
59
+ .command('connect')
60
+ .description('Connect local machine to cluster namespace (default NS=dev)')
61
+ .option('--ns <namespace>', 'Kubernetes namespace', 'dev')
62
+ .action((options) => {
63
+ const version = readCliPackageJson().version
64
+ printCommandHeader({ cliName, command: 'telepresence connect', version })
65
+ const script = resolveInfraHelper('telepresence-connect.sh')
66
+ if (!script) {
67
+ console.error(chalk.red('\n✗ telepresence-connect.sh not found — set XRYSTAL_INFRA_DIR\n'))
68
+ process.exit(1)
69
+ }
70
+ process.env.NS = options.ns
71
+ runHelper(script, [`NS=${options.ns}`])
72
+ printCommandFooter({ version })
73
+ })
74
+
75
+ tp
76
+ .command('quit')
77
+ .description('Disconnect Telepresence')
78
+ .action(() => {
79
+ const version = readCliPackageJson().version
80
+ printCommandHeader({ cliName, command: 'telepresence quit', version })
81
+ const script = resolveInfraHelper('telepresence-quit.sh')
82
+ if (!script) {
83
+ console.error(chalk.red('\n✗ telepresence-quit.sh not found — set XRYSTAL_INFRA_DIR\n'))
84
+ process.exit(1)
85
+ }
86
+ runHelper(script, [])
87
+ printCommandFooter({ version })
88
+ })
89
+
90
+ tp
91
+ .command('dev <deploy> [port]')
92
+ .description('Intercept cluster deployment and run local dev server')
93
+ .allowUnknownOption()
94
+ .action((deploy, port, _options, command) => {
95
+ const version = readCliPackageJson().version
96
+ const deployName = String(deploy ?? '').trim()
97
+ if (!TELEPRESENCE_DEPLOYMENTS.includes(deployName)) {
98
+ console.error(chalk.red(`\n✗ Unknown deploy "${deployName}"\n`))
99
+ console.error(chalk.gray(` Use: ${TELEPRESENCE_DEPLOYMENTS.join(', ')}\n`))
100
+ process.exit(1)
101
+ }
102
+
103
+ printCommandHeader({ cliName, command: `telepresence dev ${deployName}`, version })
104
+
105
+ const workspaceRoot = findWorkspaceRoot(process.cwd())
106
+ let svcDir = resolveTelepresenceServiceDir(workspaceRoot ?? process.cwd(), deployName)
107
+ if (!svcDir && workspaceRoot) {
108
+ svcDir = resolveTelepresenceServiceDir(path.dirname(workspaceRoot), deployName)
109
+ }
110
+ if (!svcDir) {
111
+ svcDir = process.cwd()
112
+ }
113
+
114
+ ensureServiceTelepresenceEnv(svcDir)
115
+ console.log(chalk.gray(` service: ${svcDir}`))
116
+ console.log(chalk.gray(` env: x/environments/.env.telepresence\n`))
117
+
118
+ const intercept = resolveInfraHelper('telepresence-intercept.sh')
119
+ if (!intercept) {
120
+ console.error(chalk.red('\n✗ telepresence-intercept.sh not found — set XRYSTAL_INFRA_DIR\n'))
121
+ process.exit(1)
122
+ }
123
+
124
+ const portArg = port && /^\d+$/.test(String(port)) ? String(port) : '3000'
125
+ const rest = command.args.slice(port && /^\d+$/.test(String(port)) ? 2 : 1)
126
+ const localCmd = rest.length ? rest : ['bun', 'run', 'dev']
127
+ const args = [deployName, portArg, '--', ...localCmd]
128
+
129
+ process.env.NS = process.env.NS ?? 'dev'
130
+ if (workspaceRoot) process.env.XRYSTAL_WORKSPACE = workspaceRoot
131
+ runHelper(intercept, args, { cwd: svcDir })
132
+ printCommandFooter({ version })
133
+ })
134
+ }
@@ -14,6 +14,7 @@ import {
14
14
  } from '../helpers/tmp-layout.mjs'
15
15
  import { formatLoaderSummary, summarizeLoaders } from '../helpers/tmp-config.mjs'
16
16
  import { packageDefaults } from '../helpers/package-defaults.mjs'
17
+ import { patchTmpEndVersion, readTmpEndVersion } from '../helpers/tmp-end-version.mjs'
17
18
 
18
19
  export function registerTmpCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
19
20
  cli
@@ -38,10 +39,18 @@ export function registerTmpCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
38
39
 
39
40
  const result = ensureTmpFile(root)
40
41
  const rel = relativeFromRoot(root, result.tmpFilePath)
42
+ const endPatch = patchTmpEndVersion(result.tmpFilePath, version)
41
43
 
42
44
  printCommandHeader({ cliName, command: 'tmp', version })
43
45
  console.log(chalk.gray(` root: ${root}`))
44
46
  console.log(result.created ? chalk.green(` created ${rel}`) : chalk.gray(` ok ${rel}`))
47
+ const endVersion = readTmpEndVersion(result.tmpFilePath)
48
+ if (endVersion) {
49
+ const endLabel = endPatch.patched
50
+ ? chalk.green(` end.version → ${endVersion}`)
51
+ : chalk.gray(` end.version: ${endVersion}`)
52
+ console.log(endLabel)
53
+ }
45
54
 
46
55
  try {
47
56
  const tmp = yaml.parse(fs.readFileSync(result.tmpFilePath, 'utf8'))
@@ -362,7 +362,7 @@ function readWorkspaceGlobalTmp(workspaceRoot) {
362
362
  return match ? { fileWatchIntervalMs: Number(match[1]) } : {};
363
363
  }
364
364
  var readWorkspaceCoreTmp = readWorkspaceGlobalTmp;
365
- function workspaceTmpTemplate(projectName) {
365
+ function workspaceTmpTemplate(projectName, coreVersion = "0.0.0") {
366
366
  return `project:
367
367
  name: ${projectName}
368
368
 
@@ -380,6 +380,11 @@ configs:
380
380
  api: api
381
381
  admin: admin
382
382
  web: web
383
+
384
+ kubeconfig: ~/.kube/config
385
+
386
+ end:
387
+ version: ${coreVersion}
383
388
  `;
384
389
  }
385
390
  export {
@@ -27,8 +27,10 @@ const COMMAND_GROUPS = [
27
27
  {
28
28
  title: 'Workspace',
29
29
  items: [
30
- { cmd: 'create <name> --workspace', desc: 'Scaffold workspace (tmp.yml + api/admin/web folders)' },
31
- { cmd: 'sync', desc: 'Sync all linked projects in workspace + update ~/.xrystal' },
30
+ { cmd: 'create <name> --workspace', desc: 'Scaffold workspace + api/general monolith (gpt template)' },
31
+ { cmd: 'sync', desc: 'Sync linked projects, end.version, @xrystal/core pin + ~/.xrystal' },
32
+ { cmd: 'telepresence dev <deploy>', aliases: 'tp dev', desc: 'Intercept cluster pod → local dev (general, gateway, …)' },
33
+ { cmd: 'telepresence connect', aliases: 'tp connect', desc: 'Connect Telepresence to dev/test namespace' },
32
34
  { cmd: 'workspaces [list|sync]', desc: 'List registered workspaces and linked projects' },
33
35
  { cmd: 'workspaces sync', aliases: 'projects sync', desc: 'Rescan cwd workspace into ~/.xrystal' },
34
36
  ],
@@ -0,0 +1,61 @@
1
+ import { execSync } from 'node:child_process'
2
+ import fs from 'node:fs'
3
+ import path from 'node:path'
4
+ import yaml from 'yaml'
5
+
6
+ import { Constants } from '../constants/index.mjs'
7
+ import { ensureTmpFile } from './tmp-layout.mjs'
8
+ import { patchTmpEndVersion } from './tmp-end-version.mjs'
9
+ import { setupProjectGitHooks } from '../scripts/install-git-hooks.mjs'
10
+
11
+ function patchTmpProjectName(tmpFilePath, projectName) {
12
+ const doc = yaml.parse(fs.readFileSync(tmpFilePath, 'utf8'))
13
+ doc.project = { ...(doc.project ?? {}), name: projectName }
14
+ fs.writeFileSync(tmpFilePath, yaml.stringify(doc))
15
+ }
16
+
17
+ export function scaffoldServiceFromTemplate(targetPath, {
18
+ projectName,
19
+ templateRepoUri = Constants.templateRepoUri,
20
+ installCommand,
21
+ cliName,
22
+ coreVersion,
23
+ setupHooks = true,
24
+ } = {}) {
25
+ const resolved = path.resolve(targetPath)
26
+ if (fs.existsSync(resolved)) {
27
+ const entries = fs.readdirSync(resolved)
28
+ if (entries.length > 0) {
29
+ throw new Error(`Target directory is not empty: ${resolved}`)
30
+ }
31
+ fs.rmdirSync(resolved)
32
+ }
33
+
34
+ fs.mkdirSync(path.dirname(resolved), { recursive: true })
35
+ execSync(`git clone --depth 1 ${templateRepoUri} "${resolved}"`, { stdio: 'ignore' })
36
+
37
+ const gitFolder = path.join(resolved, '.git')
38
+ if (fs.existsSync(gitFolder)) fs.rmSync(gitFolder, { recursive: true, force: true })
39
+
40
+ try {
41
+ execSync('git init', { cwd: resolved, stdio: 'ignore' })
42
+ } catch {
43
+ }
44
+
45
+ const tmpResult = ensureTmpFile(resolved)
46
+ patchTmpProjectName(tmpResult.tmpFilePath, projectName)
47
+ patchTmpEndVersion(tmpResult.tmpFilePath, coreVersion)
48
+
49
+ execSync(installCommand, { cwd: resolved, stdio: 'inherit' })
50
+
51
+ let hooks = null
52
+ if (setupHooks) {
53
+ try {
54
+ hooks = setupProjectGitHooks(resolved, { cliName })
55
+ } catch {
56
+ hooks = { skipped: true }
57
+ }
58
+ }
59
+
60
+ return { root: resolved, tmpFilePath: tmpResult.tmpFilePath, hooks }
61
+ }
@@ -52,10 +52,16 @@ export function syncCoreDependency(root, targetVersion, { dryRun = false } = {})
52
52
  }
53
53
 
54
54
  const packageManager = resolveProjectPackageManager(root)
55
- execSync(`${packageManager} add ${packageDefaults.packageName}@${targetVersion}`, {
56
- cwd: root,
57
- stdio: 'inherit',
58
- })
55
+ const addCmd = `${packageManager} add ${packageDefaults.packageName}@${targetVersion}`
56
+ try {
57
+ execSync(addCmd, { cwd: root, stdio: 'inherit' })
58
+ } catch (error) {
59
+ if (packageManager !== 'npm') {
60
+ execSync(`npm add ${packageDefaults.packageName}@${targetVersion}`, { cwd: root, stdio: 'inherit' })
61
+ } else {
62
+ throw error
63
+ }
64
+ }
59
65
 
60
66
  return { synced: true, declared, current, targetVersion }
61
67
  }
@@ -0,0 +1,61 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+
4
+ const TELEPRESENCE_ENV_EXAMPLE = `# Telepresence intercept env — copied to x/environments/.env.telepresence per service
5
+ # Used by: telepresence intercept --env-file .env.telepresence
6
+ NS=dev
7
+ TELEPRESENCE_INTERCEPT_HEADER=x-intercept-who
8
+ # TELEPRESENCE_DEV_ID=your-id
9
+ `
10
+
11
+ const SERVICE_TELEPRESENCE_ENV = `# Auto-scaffolded for local intercept (xry telepresence dev)
12
+ NS=dev
13
+ NODE_ENV=dev
14
+ TELEPRESENCE_INTERCEPT_HEADER=x-intercept-who
15
+ `
16
+
17
+ export function writeWorkspaceTelepresenceFiles(workspaceRoot) {
18
+ const root = path.resolve(workspaceRoot)
19
+ const examplePath = path.join(root, '.env.telepresence.example')
20
+ if (!fs.existsSync(examplePath)) {
21
+ fs.writeFileSync(examplePath, TELEPRESENCE_ENV_EXAMPLE)
22
+ }
23
+ return { examplePath }
24
+ }
25
+
26
+ export function ensureServiceTelepresenceEnv(serviceRoot) {
27
+ const root = path.resolve(serviceRoot)
28
+ const envDir = path.join(root, 'x', 'environments')
29
+ const envPath = path.join(envDir, '.env.telepresence')
30
+ fs.mkdirSync(envDir, { recursive: true })
31
+ if (!fs.existsSync(envPath)) {
32
+ fs.writeFileSync(envPath, SERVICE_TELEPRESENCE_ENV)
33
+ }
34
+ return envPath
35
+ }
36
+
37
+ /** Deploy name (tmp project.name) → workspace api folder name */
38
+ export const TELEPRESENCE_DEPLOYMENTS = Object.freeze([
39
+ 'general',
40
+ 'gateway',
41
+ 'iam',
42
+ 'core',
43
+ 'websocket',
44
+ 'crons',
45
+ 'log',
46
+ 'gpt',
47
+ ])
48
+
49
+ export function resolveTelepresenceServiceDir(workspaceRoot, deployName) {
50
+ const apiRoot = path.join(path.resolve(workspaceRoot), 'api')
51
+ const slug = String(deployName ?? '').trim()
52
+ if (!slug) return null
53
+
54
+ const direct = path.join(apiRoot, slug)
55
+ if (fs.existsSync(path.join(direct, 'x', 'tmp.yml'))) return direct
56
+
57
+ const suffixed = path.join(apiRoot, `api-${slug}-svc`)
58
+ if (fs.existsSync(path.join(suffixed, 'x', 'tmp.yml'))) return suffixed
59
+
60
+ return null
61
+ }
@@ -0,0 +1,35 @@
1
+ import fs from 'node:fs'
2
+ import yaml from 'yaml'
3
+
4
+ /** tmp.yml end.version tracks @xrystal/core CLI semver (not a schema id). */
5
+ export function readTmpEndVersion(tmpFilePath) {
6
+ if (!fs.existsSync(tmpFilePath)) return null
7
+ const doc = yaml.parse(fs.readFileSync(tmpFilePath, 'utf8'))
8
+ const raw = doc?.end?.version
9
+ if (raw === undefined || raw === null || raw === '') return null
10
+ return String(raw).trim()
11
+ }
12
+
13
+ export function patchTmpEndVersion(tmpFilePath, coreVersion, { write = true } = {}) {
14
+ if (!fs.existsSync(tmpFilePath)) {
15
+ return { patched: false, reason: 'missing tmp.yml' }
16
+ }
17
+
18
+ const version = String(coreVersion ?? '').trim()
19
+ if (!version) {
20
+ return { patched: false, reason: 'empty version' }
21
+ }
22
+
23
+ const doc = yaml.parse(fs.readFileSync(tmpFilePath, 'utf8'))
24
+ const prev = doc?.end?.version != null ? String(doc.end.version).trim() : null
25
+ if (prev === version) {
26
+ return { patched: false, reason: 'up-to-date', version, previous: prev }
27
+ }
28
+
29
+ doc.end = { ...(doc.end ?? {}), version }
30
+ if (write) {
31
+ fs.writeFileSync(tmpFilePath, yaml.stringify(doc))
32
+ }
33
+
34
+ return { patched: true, version, previous: prev }
35
+ }
@@ -4,7 +4,8 @@ import yaml from 'yaml'
4
4
 
5
5
  import { packageDefaults } from '../paths.mjs'
6
6
  import { findAllFilesRecursively, findFileRecursively } from './index.mjs'
7
- import { getBundledCoreTmpPath } from './project-root.mjs'
7
+ import { patchTmpEndVersion } from './tmp-end-version.mjs'
8
+ import { readCliPackageJson } from './project-root.mjs'
8
9
  import { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, resolveMergedPaths, resolveTmpAbsPath } from './tmp-schema.mjs'
9
10
 
10
11
  function formatTmpTarget(name, ext) {
@@ -249,6 +250,12 @@ export function ensureTmpFile(projectRoot = process.cwd(), { patchProjectName =
249
250
  }
250
251
 
251
252
  fs.writeFileSync(targetPath, content)
253
+
254
+ try {
255
+ patchTmpEndVersion(targetPath, readCliPackageJson().version)
256
+ } catch {
257
+ }
258
+
252
259
  return {
253
260
  tmpFilePath: targetPath,
254
261
  created: true,
@@ -2,8 +2,18 @@ import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
 
4
4
  import { DEFAULT_FOLDER_STRUCTURE, workspaceTmpTemplate } from './workspace-resolve.mjs'
5
+ import { scaffoldServiceFromTemplate } from './scaffold-service.mjs'
6
+ import { ensureServiceTelepresenceEnv, writeWorkspaceTelepresenceFiles } from './telepresence-layout.mjs'
7
+ import { patchTmpEndVersion } from './tmp-end-version.mjs'
8
+ import { syncRegistryFromPath } from './xrystal-registry.mjs'
5
9
 
6
- export function scaffoldWorkspace(targetPath, projectName) {
10
+ export function scaffoldWorkspace(targetPath, projectName, {
11
+ coreVersion,
12
+ installCommand,
13
+ cliName,
14
+ scaffoldGeneral = true,
15
+ templateRepoUri,
16
+ } = {}) {
7
17
  const resolved = path.resolve(targetPath)
8
18
  fs.mkdirSync(resolved, { recursive: true })
9
19
 
@@ -12,12 +22,37 @@ export function scaffoldWorkspace(targetPath, projectName) {
12
22
  throw new Error(`workspace tmp.yml already exists: ${tmpPath}`)
13
23
  }
14
24
 
15
- fs.writeFileSync(tmpPath, workspaceTmpTemplate(projectName))
16
- fs.writeFileSync(path.join(resolved, '.gitignore'), '.env.telepresence\n.env.local\n.env.private\n')
25
+ fs.writeFileSync(tmpPath, workspaceTmpTemplate(projectName, coreVersion))
26
+ fs.writeFileSync(path.join(resolved, '.gitignore'), '.env.telepresence\n.env.local\n.env.private\nnode_modules/\n')
27
+
28
+ writeWorkspaceTelepresenceFiles(resolved)
17
29
 
18
30
  for (const dir of Object.values(DEFAULT_FOLDER_STRUCTURE)) {
19
31
  fs.mkdirSync(path.join(resolved, dir), { recursive: true })
20
32
  }
21
33
 
22
- return { root: resolved, tmpPath }
34
+ let general = null
35
+ if (scaffoldGeneral) {
36
+ const generalPath = path.join(resolved, DEFAULT_FOLDER_STRUCTURE.api, 'general')
37
+ general = scaffoldServiceFromTemplate(generalPath, {
38
+ projectName: 'general',
39
+ templateRepoUri,
40
+ installCommand,
41
+ cliName,
42
+ coreVersion,
43
+ })
44
+ ensureServiceTelepresenceEnv(generalPath)
45
+ }
46
+
47
+ try {
48
+ syncRegistryFromPath(resolved)
49
+ } catch {
50
+ }
51
+
52
+ return { root: resolved, tmpPath, general }
53
+ }
54
+
55
+ export function patchWorkspaceTmpEndVersion(workspaceRoot, coreVersion) {
56
+ const tmpPath = path.join(path.resolve(workspaceRoot), 'tmp.yml')
57
+ return patchTmpEndVersion(tmpPath, coreVersion)
23
58
  }
package/x/bin/main-cli.js CHANGED
@@ -10,6 +10,7 @@ import { registerTmpCommand } from './commands/tmp.mjs'
10
10
  import { registerSyncCommand } from './commands/sync.mjs'
11
11
  import { registerProjectsCommand, registerWorkspacesCommand } from './commands/projects.mjs'
12
12
  import { registerTagCommand, registerVersionCommand } from './commands/release.mjs'
13
+ import { registerTelepresenceCommand } from './commands/telepresence.mjs'
13
14
  import { registerHooksCommand } from './commands/hooks.mjs'
14
15
  import { printBanner, shouldShowBanner } from './helpers/banner.mjs'
15
16
  import { formatRootHelp, formatCreateCommandHelp, isCreateHelpRequest, isRootHelpRequest, printQuickStartGuide } from './helpers/cli-help.mjs'
@@ -70,6 +71,7 @@ registerSyncCommand(cli, cliContext)
70
71
  registerWorkspacesCommand(cli, cliContext)
71
72
  registerProjectsCommand(cli, cliContext)
72
73
  registerHooksCommand(cli, cliContext)
74
+ registerTelepresenceCommand(cli, cliContext)
73
75
  registerProjectCommands(cli, cliContext)
74
76
 
75
77
  cli.parseAsync(process.argv).catch((error) => {
@@ -39,4 +39,4 @@ export declare function readWorkspaceGlobalTmp(workspaceRoot: string): {
39
39
  fileWatchIntervalMs?: number;
40
40
  };
41
41
  /** @deprecated */ export declare const readWorkspaceCoreTmp: typeof readWorkspaceGlobalTmp;
42
- export declare function workspaceTmpTemplate(projectName: string): string;
42
+ export declare function workspaceTmpTemplate(projectName: string, coreVersion?: string): string;
@@ -200,7 +200,7 @@ export function readWorkspaceGlobalTmp(workspaceRoot) {
200
200
  return match ? { fileWatchIntervalMs: Number(match[1]) } : {};
201
201
  }
202
202
  /** @deprecated */ export const readWorkspaceCoreTmp = readWorkspaceGlobalTmp;
203
- export function workspaceTmpTemplate(projectName) {
203
+ export function workspaceTmpTemplate(projectName, coreVersion = '0.0.0') {
204
204
  return `project:
205
205
  name: ${projectName}
206
206
 
@@ -218,5 +218,10 @@ configs:
218
218
  api: api
219
219
  admin: admin
220
220
  web: web
221
+
222
+ kubeconfig: ~/.kube/config
223
+
224
+ end:
225
+ version: ${coreVersion}
221
226
  `;
222
227
  }
@@ -56,4 +56,4 @@ configs:
56
56
  controller:
57
57
 
58
58
  end:
59
- version: 1
59
+ version: "3.52.4"
package/x/tmp.yml CHANGED
@@ -24,4 +24,4 @@ configs:
24
24
  fileWatchIntervalMs: 500
25
25
 
26
26
  end:
27
- version: 1
27
+ version: "3.52.5"