@xrystal/core 3.55.66 → 3.55.68

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
@@ -268,7 +268,22 @@ bun run dev
268
268
  **Docker / Compose:** Image `CMD ["bun", "xry", "start"]` (dev: `xry dev`). Runtime skips `x/environments` when `/.dockerenv` or k8s is detected (optional override: `XRY_RUNTIME=container|docker|k8s`). Compose: `env_file:` on `x/docker/docker-compose*.yml` — not `COPY` env into the image.
269
269
  | `xry test` | Run `x/tests` | `x/tests` çalıştır |
270
270
  | `xry doctor` | CLI, runtime, package health | CLI, runtime, paket uyumu |
271
- | `xry tag` | **This repo only** — tag + npm publish (`@xrystal/core`) | **Sadece core** — servislerde çalışmaz / git tag yok |
271
+ | `xry tag` | Core → npm publish · service → `v<CalVer>` git tag | Core npm · servis GHCR tag |
272
+ | `bun run release:patch` | Core SemVer patch · service CalVer (+pN) | Core patch · servis CalVer patch |
273
+ | `bun run release:minor` | **Core only** (`-xrystal-core`) | **Sadece core** |
274
+ | `bun run release:major` | **Core only** | **Sadece core** |
275
+
276
+ ### Release scripts (general — tek kaynak)
277
+
278
+ | Repo | `package.json` scripts | Bump |
279
+ |---|---|---|
280
+ | **`-xrystal-core`** | `release:patch`, `release:minor`, `release:major`, `tag` | SemVer |
281
+ | **`api-*-svc`** (deployed) | `release:patch`, `tag` | CalVer (branch → UTC + `pN`) |
282
+ | **`api-gpt-svc`** (template, no cluster deploy) | `release:patch`, `minor`, `major`, `tag` | SemVer **or** CalVer — `version` şekline göre CLI |
283
+
284
+ **EN:** Deployed services: patch + tag only. **`api-gpt-svc`** is the full script template (minor/major when `package.json` is SemVer; CalVer repos use patch only in practice).
285
+
286
+ **TR:** Canlı servis: `bun run release:patch` → commit → `bun run tag`. Yeni servis / örnek: `api-gpt-svc` `package.json` scripts bloğunu kopyala.
272
287
 
273
288
  ---
274
289
 
@@ -877,9 +892,9 @@ class ChatController extends Controller {
877
892
 
878
893
  ## Maintainer note / Geliştirici notu
879
894
 
880
- **EN:** This repo is the `@xrystal/core` source. Bump `package.json` → commit → `xry tag` (runs prepare + pushes `vX.Y.Z`; GitHub Publish workflow releases to npm). Consumers only need `bun add @xrystal/core`.
895
+ **EN:** See **Release scripts (general)**. CalVer npm script örneği yalnız **`api-gpt-svc`** template’inde.
881
896
 
882
897
 
883
898
  **npm CI (`E401` / invalid token):** GitHub → repo **Settings → Environments → NPM** → secret **`TOKEN`** = [npm Granular Access Token](https://www.npmjs.com/settings/~youruser/tokens) with **Publish** on package `@xrystal/core` (or whole `@xrystal` scope). Classic automation tokens that bypass 2FA are being restricted — prefer **Granular** + **Publish**. After rotate: re-run failed **Publish Core Library NPM** workflow or push empty commit / re-tag. Stage flow: workflow runs `npm stage publish` → approve on npmjs.com (`npm stage list` / Approve with 2FA).
884
899
 
885
- **TR:** Bu repo `@xrystal/core` kaynağıdır. `package.json` bump → commit → `xry tag` (prepare + `vX.Y.Z` push; GitHub Publish → npm). Tüketici için sadece `bun add @xrystal/core` yeter.
900
+ **TR:** Yukarıdaki genel tablo. Serviste `release:minor|major` yok — yalnız CalVer patch.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.55.66",
4
+ "version": "3.55.68",
5
5
  "description": "Runtime framework and CLI for API services, frontends, and multi-repo workspaces",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -84,6 +84,9 @@
84
84
  "build:dev": "node x/bin/main-cli.js dev",
85
85
  "start": "node x/bin/main-cli.js start",
86
86
  "tag": "node x/bin/scripts/tag.mjs",
87
+ "release:patch": "node x/bin/scripts/release-bump.mjs patch",
88
+ "release:minor": "node x/bin/scripts/release-bump.mjs minor",
89
+ "release:major": "node x/bin/scripts/release-bump.mjs major",
87
90
  "version:check": "node x/bin/scripts/version-check.mjs",
88
91
  "hooks:install": "node x/bin/scripts/install-git-hooks.mjs"
89
92
  },
@@ -123,4 +126,4 @@
123
126
  "typescript": "~5.9.3",
124
127
  "typescript-eslint": "^8.62.1"
125
128
  }
126
- }
129
+ }
@@ -1,8 +1,18 @@
1
1
  import chalk from 'chalk'
2
2
  import { readCliPackageJson, readProjectPackageJson } from '../helpers/project-root.mjs'
3
3
  import { requireServiceRoot, exitOnCliContextError, CliContextError } from '../helpers/cli-context-guard.mjs'
4
- import { compareSemver, getVersionState, resolveVersionBaseline, runTagRelease } from '../scripts/version-check.mjs'
4
+ import {
5
+ assertVersionFormat,
6
+ compareSemver,
7
+ getVersionState,
8
+ resolveVersionBaseline,
9
+ runTagRelease,
10
+ } from '../scripts/version-check.mjs'
5
11
  import { isCorePackageProject } from '../scripts/release-prepare.mjs'
12
+ import { runCalverTagPush, assertCalverFormat, detectCalverEnv, bumpCalverPatch } from '../scripts/calver.mjs'
13
+ import { bumpSemverLevel, resolveReleaseMode } from '../scripts/release-bump.mjs'
14
+ import fs from 'node:fs'
15
+ import path from 'node:path'
6
16
  import { packageDefaults } from '../helpers/package-defaults.mjs'
7
17
  import { CLI_PRIMARY_NAME, PACKAGE_NAME } from '../helpers/cli-identity.mjs'
8
18
 
@@ -16,24 +26,23 @@ export function registerTagCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
16
26
  .action(async (options) => {
17
27
  try {
18
28
  const { root } = requireServiceRoot(process.cwd(), { cliName, command: 'tag' })
19
- if (!isCorePackageProject(root)) {
20
- throw new CliContextError(
21
- `\`xry tag\` is only for ${packageDefaults.packageName} (library). Services do not create git tags here.`,
22
- {
23
- hints: [
24
- 'cd to -xrystal-core and bump package.json → commit → xry tag',
25
- 'Service images: CalVer via platform release (see infra versioning.mdc)',
26
- `${cliName} version — check package.json in this repo`,
27
- ],
28
- },
29
- )
29
+ if (isCorePackageProject(root)) {
30
+ await runTagRelease({
31
+ dryRun: options.dryRun,
32
+ requireClean: options.strictClean,
33
+ skipPrepare: options.skipPrepare,
34
+ root,
35
+ })
36
+ } else {
37
+ const version = getVersionState('HEAD', root).committed.version
38
+ const calverEnv = detectCalverEnv(version)
39
+ if (calverEnv) {
40
+ assertCalverFormat(version, calverEnv)
41
+ } else {
42
+ assertVersionFormat(version)
43
+ }
44
+ runCalverTagPush({ root, dryRun: options.dryRun })
30
45
  }
31
- await runTagRelease({
32
- dryRun: options.dryRun,
33
- requireClean: options.strictClean,
34
- skipPrepare: options.skipPrepare,
35
- root,
36
- })
37
46
  if (!options.dryRun) {
38
47
  console.log(chalk.green('\n✓ Tag pushed.\n'))
39
48
  }
@@ -45,6 +54,55 @@ export function registerTagCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
45
54
  })
46
55
  }
47
56
 
57
+ function writePackageVersion(root, version) {
58
+ const pkgPath = path.join(root, 'package.json')
59
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
60
+ pkg.version = version
61
+ fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`)
62
+ }
63
+
64
+ export function registerReleaseBumpCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
65
+ const bump = cli.command('release').description('Bump package.json (core SemVer · service CalVer patch)')
66
+
67
+ for (const level of ['patch', 'minor', 'major']) {
68
+ bump
69
+ .command(level)
70
+ .description(
71
+ level === 'patch'
72
+ ? 'SemVer or CalVer patch (from package.json version shape)'
73
+ : 'SemVer minor/major (CalVer repos: patch only)',
74
+ )
75
+ .option('--dry-run', 'Print next version only')
76
+ .action((options) => {
77
+ try {
78
+ const { root } = requireServiceRoot(process.cwd(), { cliName, command: `release ${level}` })
79
+ const mode = resolveReleaseMode(root)
80
+ const state = getVersionState('HEAD', root)
81
+ let next
82
+ if (mode === 'semver') {
83
+ next = bumpSemverLevel(state.disk.version, level)
84
+ } else {
85
+ if (level !== 'patch') {
86
+ throw new Error('CalVer — only patch. package.json SemVer (2.0.x) ise minor/major açılır.')
87
+ }
88
+ next = bumpCalverPatch(root).next
89
+ }
90
+ if (options.dryRun) {
91
+ console.log(chalk.bold(next))
92
+ return
93
+ }
94
+ writePackageVersion(root, next)
95
+ console.log(chalk.green(`package.json → ${next}`))
96
+ console.log(chalk.gray('Commit package.json, then: xry tag'))
97
+ } catch (error) {
98
+ if (error?.name === 'CliContextError') exitOnCliContextError(error)
99
+ console.error(chalk.red(`\n✗ ${error.message}\n`))
100
+ process.exit(1)
101
+ }
102
+ })
103
+ }
104
+ }
105
+
48
106
  export function registerVersionCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
49
107
  cli
50
108
  .command('version')
@@ -13,6 +13,7 @@ import {
13
13
  } from '../helpers/telepresence-runtime.mjs'
14
14
  import {
15
15
  ensureServiceTelepresenceEnv,
16
+ resolveTelepresenceDeployFromCwd,
16
17
  resolveTelepresenceServiceDir,
17
18
  TELEPRESENCE_DEPLOYMENTS,
18
19
  } from '../helpers/telepresence-layout.mjs'
@@ -32,6 +33,73 @@ function parsePort(value) {
32
33
  return value && /^\d+$/.test(String(value)) ? String(value) : '3000'
33
34
  }
34
35
 
36
+ function resolveInterceptTarget(deploy, port, command) {
37
+ let deployName = String(deploy ?? '').trim()
38
+ let portArg = '3000'
39
+
40
+ if (deployName && /^\d+$/.test(deployName)) {
41
+ portArg = deployName
42
+ deployName = ''
43
+ }
44
+ if (port !== undefined && port !== null && String(port).trim() !== '') {
45
+ if (/^\d+$/.test(String(port))) {
46
+ portArg = String(port)
47
+ } else if (!deployName) {
48
+ deployName = String(port).trim()
49
+ }
50
+ }
51
+
52
+ let serviceRootHint = null
53
+ if (!deployName) {
54
+ const resolved = resolveTelepresenceDeployFromCwd(process.cwd())
55
+ deployName = resolved.deploy
56
+ serviceRootHint = resolved.serviceRoot
57
+ }
58
+
59
+ if (!TELEPRESENCE_DEPLOYMENTS.includes(deployName)) {
60
+ console.error(chalk.red(`\n✗ Unknown deploy "${deployName}"\n`))
61
+ console.error(chalk.gray(` Use: ${TELEPRESENCE_DEPLOYMENTS.join(', ')}\n`))
62
+ process.exit(1)
63
+ }
64
+
65
+ return { deployName, portArg, serviceRootHint }
66
+ }
67
+
68
+ function resolveLocalCmd(command) {
69
+ const raw = command?.args ?? []
70
+ let offset = 0
71
+ const first = raw[0] != null ? String(raw[0]).trim() : ''
72
+ const second = raw[1] != null ? String(raw[1]).trim() : ''
73
+ if (first && (TELEPRESENCE_DEPLOYMENTS.includes(first) || /^\d+$/.test(first))) offset++
74
+ if (second && /^\d+$/.test(second)) offset++
75
+ return raw.length > offset ? raw.slice(offset) : ['xry', 'dev']
76
+ }
77
+
78
+ function runConnect(options, { cliName, commandLabel }) {
79
+ const version = readCliPackageJson().version
80
+ printCommandHeader({ cliName, command: commandLabel, version })
81
+ try {
82
+ const code = connectTelepresence({ ns: options.ns, cwd: process.cwd() })
83
+ if (code !== 0) process.exit(code)
84
+ } catch (err) {
85
+ console.error(chalk.red(`\n✗ ${err.message}\n`))
86
+ process.exit(1)
87
+ }
88
+ printCommandFooter({ version })
89
+ }
90
+
91
+ function runQuit({ cliName, commandLabel }) {
92
+ const version = readCliPackageJson().version
93
+ printCommandHeader({ cliName, command: commandLabel, version })
94
+ try {
95
+ quitTelepresence()
96
+ } catch (err) {
97
+ console.error(chalk.red(`\n✗ ${err.message}\n`))
98
+ process.exit(1)
99
+ }
100
+ printCommandFooter({ version })
101
+ }
102
+
35
103
  export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
36
104
  const tp = cli
37
105
  .command('telepresence')
@@ -41,48 +109,31 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
41
109
  'after',
42
110
  `
43
111
  ${chalk.gray('Examples:')}
44
- ${cliName} tp connect --ns dev
45
- ${cliName} tp intercept general --ns dev
46
- ${cliName} tp dev gateway 3000 --ns test
47
- ${cliName} telepresence quit
112
+ ${cliName} tp start --ns dev
113
+ ${cliName} tp intercept
114
+ ${cliName} tp intercept gateway 3000 --ns dev
115
+ ${cliName} tp stop
48
116
  ${cliName} tp install
49
117
 
50
- ${chalk.gray('intercept/dev')} = local intercept + run process (NOT the k8s namespace)
118
+ ${chalk.gray('start/stop')} = connect / quit session
119
+ ${chalk.gray('intercept')} = omit deploy in service repo → project.name from x/tmp.yml
51
120
  ${chalk.gray('--ns')} = Kubernetes namespace (default: dev)
52
- ${chalk.gray('<deploy>')} = ${TELEPRESENCE_DEPLOYMENTS.join(', ')}
121
+ ${chalk.gray('<deploy>')} = optional — ${TELEPRESENCE_DEPLOYMENTS.join(', ')}
53
122
  ${chalk.gray('kubeconfig:')} workspace tmp.yml, KUBECONFIG, data/k3s/cluster.kubeconfig
54
123
  `,
55
124
  )
56
125
 
57
- tp.command('connect')
58
- .description('Connect local machine to cluster namespace')
59
- .option('--ns <namespace>', 'Kubernetes namespace', 'dev')
60
- .action((options) => {
61
- const version = readCliPackageJson().version
62
- printCommandHeader({ cliName, command: 'telepresence connect', version })
63
- try {
64
- const code = connectTelepresence({ ns: options.ns, cwd: process.cwd() })
65
- if (code !== 0) process.exit(code)
66
- } catch (err) {
67
- console.error(chalk.red(`\n✗ ${err.message}\n`))
68
- process.exit(1)
69
- }
70
- printCommandFooter({ version })
126
+ const connectOptions = (cmd) =>
127
+ cmd.option('--ns <namespace>', 'Kubernetes namespace', 'dev').action((options) => {
128
+ runConnect(options, { cliName, commandLabel: 'tp start' })
71
129
  })
72
130
 
73
- tp.command('quit')
74
- .description('Disconnect Telepresence')
75
- .action(() => {
76
- const version = readCliPackageJson().version
77
- printCommandHeader({ cliName, command: 'telepresence quit', version })
78
- try {
79
- quitTelepresence()
80
- } catch (err) {
81
- console.error(chalk.red(`\n✗ ${err.message}\n`))
82
- process.exit(1)
83
- }
84
- printCommandFooter({ version })
85
- })
131
+ connectOptions(tp.command('start').description('Connect Telepresence to cluster (alias: connect)').alias('connect'))
132
+
133
+ tp.command('stop')
134
+ .description('Disconnect Telepresence (alias: quit)')
135
+ .alias('quit')
136
+ .action(() => runQuit({ cliName, commandLabel: 'tp stop' }))
86
137
 
87
138
  tp.command('install')
88
139
  .description('Install Telepresence OSS client (~2.31.x, matches cluster chart)')
@@ -96,27 +147,24 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
96
147
 
97
148
  tp.command('intercept')
98
149
  .alias('dev')
99
- .description('Intercept cluster deployment and run local process (--ns = k8s namespace, not this subcommand name)')
100
- .argument('<deploy>', `Deployment name (${TELEPRESENCE_DEPLOYMENTS.join(', ')})`)
150
+ .description('Intercept deployment → local process (deploy optional in service repo)')
151
+ .argument('[deploy]', `Deployment name (default: project.name in x/tmp.yml) — ${TELEPRESENCE_DEPLOYMENTS.join(', ')}`)
101
152
  .argument('[port]', 'Local listen port', '3000')
102
153
  .option('--ns <namespace>', 'Kubernetes namespace', 'dev')
103
154
  .allowUnknownOption()
104
155
  .allowExcessArguments()
105
156
  .action((deploy, port, options, command) => {
106
157
  const version = readCliPackageJson().version
107
- const deployName = String(deploy ?? '').trim()
108
158
  const ns = String(options.ns ?? 'dev').trim() || 'dev'
159
+ const { deployName, portArg, serviceRootHint } = resolveInterceptTarget(deploy, port, command)
160
+ const localCmd = resolveLocalCmd(command)
109
161
 
110
- if (!TELEPRESENCE_DEPLOYMENTS.includes(deployName)) {
111
- console.error(chalk.red(`\n✗ Unknown deploy "${deployName}"\n`))
112
- console.error(chalk.gray(` Use: ${TELEPRESENCE_DEPLOYMENTS.join(', ')}\n`))
113
- process.exit(1)
114
- }
115
-
116
- printCommandHeader({ cliName, command: `telepresence intercept ${deployName}`, version })
162
+ printCommandHeader({ cliName, command: `tp intercept ${deployName}`, version })
117
163
 
118
164
  const workspaceRoot = findWorkspaceRoot(process.cwd())
119
- let svcDir = resolveTelepresenceServiceDir(workspaceRoot ?? process.cwd(), deployName)
165
+ let svcDir =
166
+ serviceRootHint ??
167
+ resolveTelepresenceServiceDir(workspaceRoot ?? process.cwd(), deployName)
120
168
  if (!svcDir && workspaceRoot) {
121
169
  svcDir = resolveTelepresenceServiceDir(path.dirname(workspaceRoot), deployName)
122
170
  }
@@ -132,11 +180,6 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
132
180
  console.log(chalk.gray(` ns: ${ns}`))
133
181
  console.log(chalk.gray(` service: ${svcDir}`))
134
182
  console.log(chalk.gray(` env: ${env.envRel}${env.created ? chalk.green(' (created)') : ''}\n`))
135
-
136
- const portArg = parsePort(port)
137
- const rest = command.args.slice(/^\d+$/.test(String(port ?? '')) ? 2 : 1)
138
- const localCmd = rest.length ? rest : ['xry', 'dev']
139
-
140
183
  console.log(chalk.gray(` local port: ${portArg} (pod container :3000)`))
141
184
 
142
185
  try {
@@ -51,8 +51,9 @@ function commandGroups() {
51
51
  { cmd: 'sync --all', desc: t('quick.syncAll') },
52
52
  { cmd: 'workspaces [list|sync]', desc: t('quick.workspaces') },
53
53
  { cmd: 'watch install', desc: 'OS service — survives reboot (launchd / systemd user)' },
54
- { cmd: 'telepresence intercept <deploy> --ns dev', aliases: 'tp dev', desc: 'Intercept cluster pod → local process (dev = alias, --ns = namespace)' },
55
- { cmd: 'telepresence connect --ns dev', aliases: 'tp connect', desc: 'Connect Telepresence to cluster namespace' },
54
+ { cmd: 'tp start --ns dev', aliases: 'tp connect', desc: 'Connect Telepresence to cluster namespace' },
55
+ { cmd: 'tp stop', aliases: 'tp quit', desc: 'Disconnect Telepresence' },
56
+ { cmd: 'tp intercept [deploy] --ns dev', aliases: 'tp dev', desc: 'Intercept — omit deploy in service repo (uses x/tmp.yml project.name)' },
56
57
  { cmd: 'telepresence install', aliases: 'tp install', desc: 'Install Telepresence OSS client (~2.31.x)' },
57
58
  ],
58
59
  },
@@ -77,7 +78,9 @@ function commandGroups() {
77
78
  {
78
79
  title: t('sections.release'),
79
80
  items: [
80
- { cmd: 'tag', desc: 'Tag HEAD from package.json (+ core npm publish)' },
81
+ { cmd: 'release patch', desc: 'Bump package.json — core SemVer · service CalVer pN' },
82
+ { cmd: 'release minor|major', desc: '@xrystal/core SemVer only' },
83
+ { cmd: 'tag', desc: 'Core npm publish · service v<CalVer> git tag' },
81
84
  ],
82
85
  },
83
86
  ]
@@ -1,6 +1,8 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
 
4
+ import yaml from 'yaml'
5
+
4
6
  const TELEPRESENCE_ENV_EXAMPLE = `# Telepresence intercept env — copied to x/environments/.env.telepresence per service
5
7
  # Used by: telepresence intercept --env-file .env.telepresence
6
8
  NS=dev
@@ -48,6 +50,48 @@ export const TELEPRESENCE_DEPLOYMENTS = Object.freeze([
48
50
  'gpt',
49
51
  ])
50
52
 
53
+ /** Walk up from cwd to a directory containing x/tmp.yml (service repo root). */
54
+ export function findServiceRootFromCwd(cwd = process.cwd()) {
55
+ let dir = path.resolve(cwd)
56
+ for (let depth = 0; depth < 16; depth++) {
57
+ if (fs.existsSync(path.join(dir, 'x', 'tmp.yml'))) return dir
58
+ const parent = path.dirname(dir)
59
+ if (parent === dir) break
60
+ dir = parent
61
+ }
62
+ return null
63
+ }
64
+
65
+ /** project.name from inner x/tmp.yml — must match TELEPRESENCE_DEPLOYMENTS. */
66
+ export function readDeployNameFromServiceRoot(serviceRoot) {
67
+ const tmpPath = path.join(path.resolve(serviceRoot), 'x', 'tmp.yml')
68
+ if (!fs.existsSync(tmpPath)) return null
69
+ let doc
70
+ try {
71
+ doc = yaml.parse(fs.readFileSync(tmpPath, 'utf8'))
72
+ } catch {
73
+ return null
74
+ }
75
+ const name = String(doc?.project?.name ?? '').trim()
76
+ if (!name) return null
77
+ if (!TELEPRESENCE_DEPLOYMENTS.includes(name)) {
78
+ throw new Error(
79
+ `tmp project.name "${name}" is not a known deploy (${TELEPRESENCE_DEPLOYMENTS.join(', ')}).`,
80
+ )
81
+ }
82
+ return name
83
+ }
84
+
85
+ export function resolveTelepresenceDeployFromCwd(cwd = process.cwd()) {
86
+ const root = findServiceRootFromCwd(cwd)
87
+ if (!root) {
88
+ throw new Error(
89
+ 'No x/tmp.yml in this tree — cd into a service repo or pass deploy: xry tp intercept <gateway|iam|…>',
90
+ )
91
+ }
92
+ return { deploy: readDeployNameFromServiceRoot(root), serviceRoot: root }
93
+ }
94
+
51
95
  export function resolveTelepresenceServiceDir(workspaceRoot, deployName) {
52
96
  const apiRoot = path.join(path.resolve(workspaceRoot), 'api')
53
97
  const slug = String(deployName ?? '').trim()
package/x/bin/main-cli.js CHANGED
@@ -10,7 +10,7 @@ import { registerProjectCommands } from './commands/project.mjs'
10
10
  import { registerTmpCommand } from './commands/tmp.mjs'
11
11
  import { registerSyncCommand } from './commands/sync.mjs'
12
12
  import { registerProjectsCommand, registerWorkspacesCommand } from './commands/projects.mjs'
13
- import { registerTagCommand, registerVersionCommand } from './commands/release.mjs'
13
+ import { registerTagCommand, registerVersionCommand, registerReleaseBumpCommand } from './commands/release.mjs'
14
14
  import { registerTelepresenceCommand } from './commands/telepresence.mjs'
15
15
  import { registerHooksCommand } from './commands/hooks.mjs'
16
16
  import { registerWatchCommand } from './commands/watch.mjs'
@@ -83,6 +83,7 @@ cli
83
83
 
84
84
  registerCreateCommand(cli, cliContext)
85
85
  registerVersionCommand(cli, cliContext)
86
+ registerReleaseBumpCommand(cli, cliContext)
86
87
  registerTagCommand(cli, cliContext)
87
88
  registerDoctorCommand(cli, cliContext)
88
89
  registerTmpCommand(cli, cliContext)
@@ -98,11 +99,7 @@ registerTelepresenceCommand(cli, cliContext)
98
99
  registerProjectCommands(cli, cliContext)
99
100
 
100
101
  cli.parseAsync(process.argv).catch((error) => {
101
- const message = error instanceof Error && error.message ? error.message : 'Command failed.'
102
- if (error instanceof Error && error.name === 'InfraPreflightFailed') {
103
- process.exit(1)
104
- }
105
- console.error(chalk.red(`\n✗ ${message}\n`))
102
+ console.error(chalk.red(`\n✗ ${error.message}\n`))
106
103
  process.exit(1)
107
104
  })
108
105
 
@@ -0,0 +1,130 @@
1
+ import { execSync } from 'node:child_process'
2
+ import { getVersionState, readDiskPackageJson, run } from './version-check.mjs'
3
+
4
+ const CALVER_RELEASE = /^(\d{2})\.(\d{2})\.(\d{2})$/
5
+ const CALVER_DEV = /^(\d{2})\.(\d{2})\.(\d{2})-dev-p(\d+)$/
6
+ const CALVER_STAG = /^(\d{2})\.(\d{2})\.(\d{2})-stag-p(\d+)$/
7
+
8
+ export function utcCalverDate() {
9
+ const d = new Date()
10
+ const yy = String(d.getUTCFullYear()).slice(-2)
11
+ const mm = String(d.getUTCMonth() + 1).padStart(2, '0')
12
+ const dd = String(d.getUTCDate()).padStart(2, '0')
13
+ return `${yy}.${mm}.${dd}`
14
+ }
15
+
16
+ function runGit(cmd, root) {
17
+ return execSync(cmd, { cwd: root, encoding: 'utf8', stdio: 'pipe' }).trim()
18
+ }
19
+
20
+ function gitTagExists(tagName, root) {
21
+ try {
22
+ runGit(`git rev-parse refs/tags/${tagName}^{commit}`, root)
23
+ return true
24
+ } catch {
25
+ try {
26
+ return runGit(`git ls-remote --tags origin refs/tags/${tagName}`, root).length > 0
27
+ } catch {
28
+ return false
29
+ }
30
+ }
31
+ }
32
+
33
+ export function detectCalverEnv(version) {
34
+ const v = String(version).trim()
35
+ if (CALVER_DEV.test(v)) return 'dev'
36
+ if (CALVER_STAG.test(v)) return 'stag'
37
+ if (CALVER_RELEASE.test(v)) return 'prod'
38
+ return null
39
+ }
40
+
41
+ export function assertCalverFormat(version, env) {
42
+ const v = String(version).trim()
43
+ if (env === 'prod' && !CALVER_RELEASE.test(v)) {
44
+ throw new Error(`Invalid prod CalVer "${v}" — expected YY.MM.DD`)
45
+ }
46
+ if (env === 'dev' && !CALVER_DEV.test(v)) {
47
+ throw new Error(`Invalid dev CalVer "${v}" — expected YY.MM.DD-dev-pN`)
48
+ }
49
+ if (env === 'stag' && !CALVER_STAG.test(v)) {
50
+ throw new Error(`Invalid stag CalVer "${v}" — expected YY.MM.DD-stag-pN`)
51
+ }
52
+ }
53
+
54
+ /**
55
+ * @param {'dev'|'stag'|'prod'} env
56
+ */
57
+ /** Branch or current package.json CalVer suffix → dev | stag | prod */
58
+ export function resolveCalverEnv(root = process.cwd()) {
59
+ const branch = getVersionState('HEAD', root).branch
60
+ if (branch === 'dev') return 'dev'
61
+ if (branch === 'staging') return 'stag'
62
+ if (branch === 'prod') return 'prod'
63
+
64
+ const fromPkg = detectCalverEnv(readDiskPackageJson(root).version)
65
+ if (fromPkg) return fromPkg
66
+
67
+ throw new Error(
68
+ `Cannot infer CalVer env — checkout dev | staging | prod, or set package.json to YY.MM.DD-dev-pN / -stag-pN / YY.MM.DD.`,
69
+ )
70
+ }
71
+
72
+ /** Next image tag for current env (patch step = next free pN on UTC day). */
73
+ export function bumpCalverPatch(root = process.cwd()) {
74
+ const env = resolveCalverEnv(root)
75
+ const next = nextCalverVersion(env, root)
76
+ assertCalverFormat(next, env)
77
+ return { next, env }
78
+ }
79
+
80
+ export function nextCalverVersion(env, root = process.cwd()) {
81
+ const date = utcCalverDate()
82
+ if (env === 'prod') {
83
+ const version = date
84
+ const tagName = `v${version}`
85
+ if (gitTagExists(tagName, root)) {
86
+ throw new Error(`Git tag ${tagName} already exists — prod release is one tag per UTC day`)
87
+ }
88
+ return version
89
+ }
90
+ const mid = env === 'dev' ? '-dev-p' : '-stag-p'
91
+ let n = 1
92
+ while (gitTagExists(`v${date}${mid}${n}`, root)) {
93
+ n += 1
94
+ }
95
+ return `${date}${mid}${n}`
96
+ }
97
+
98
+ export function gitTagFromCalver(version) {
99
+ return version.startsWith('v') ? version : `v${version}`
100
+ }
101
+
102
+ export function runCalverTagPush({ root, dryRun = false } = {}) {
103
+ const state = getVersionState('HEAD', root)
104
+ const version = state.committed.version
105
+
106
+ if (!state.isPackageJsonClean) {
107
+ throw new Error('Commit package.json before tagging.')
108
+ }
109
+ if (!state.versionMatch) {
110
+ throw new Error('package.json on disk does not match HEAD — commit first.')
111
+ }
112
+
113
+ const tagName = gitTagFromCalver(version)
114
+ if (gitTagExists(tagName, root)) {
115
+ throw new Error(`Tag ${tagName} already exists.`)
116
+ }
117
+
118
+ const branch = state.branch
119
+ if (dryRun) {
120
+ console.log(`[dry-run] git tag ${tagName}`)
121
+ console.log(`[dry-run] git push origin ${branch}`)
122
+ console.log(`[dry-run] git push origin ${tagName}`)
123
+ return { version, tagName, branch }
124
+ }
125
+
126
+ run(`git tag ${tagName}`, { inherit: true, root })
127
+ run(`git push origin ${branch}`, { inherit: true, root })
128
+ run(`git push origin ${tagName}`, { inherit: true, root })
129
+ return { version, tagName, branch }
130
+ }
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'node:fs'
4
+ import path from 'node:path'
5
+ import chalk from 'chalk'
6
+ import { resolveProjectRoot } from '../helpers/project-root.mjs'
7
+ import { isCorePackageProject } from './release-prepare.mjs'
8
+ import { fileURLToPath } from 'node:url'
9
+ import { parseSemver, getVersionState, readDiskPackageJson } from './version-check.mjs'
10
+ import { bumpCalverPatch, gitTagFromCalver, detectCalverEnv } from './calver.mjs'
11
+
12
+ /** @returns {'semver'|'calver'} */
13
+ export function resolveReleaseMode(root) {
14
+ if (isCorePackageProject(root)) return 'semver'
15
+ const version = readDiskPackageJson(root).version
16
+ if (detectCalverEnv(version)) return 'calver'
17
+ if (parseSemver(version)) return 'semver'
18
+ return 'calver'
19
+ }
20
+
21
+ function writePackageVersion(root, version) {
22
+ const pkgPath = path.join(root, 'package.json')
23
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
24
+ pkg.version = version
25
+ fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`)
26
+ }
27
+
28
+ export function bumpSemverLevel(version, level) {
29
+ const p = parseSemver(version)
30
+ if (!p) {
31
+ throw new Error(`Cannot bump non-semver version "${version}"`)
32
+ }
33
+ if (level === 'patch') {
34
+ return `${p.major}.${p.minor}.${p.patch + 1}`
35
+ }
36
+ if (level === 'minor') {
37
+ return `${p.major}.${p.minor + 1}.0`
38
+ }
39
+ if (level === 'major') {
40
+ return `${p.major + 1}.0.0`
41
+ }
42
+ throw new Error(`Unknown semver level: ${level}`)
43
+ }
44
+
45
+ function printCoreNextSteps(version) {
46
+ console.log(chalk.gray('\nNext (core / npm):'))
47
+ console.log(` git add package.json && git commit -m "Bump library version"`)
48
+ console.log(` bun run tag`)
49
+ console.log(chalk.dim(` git tag will be v${version} after commit\n`))
50
+ }
51
+
52
+ function printServiceNextSteps(version) {
53
+ const tag = gitTagFromCalver(version)
54
+ console.log(chalk.gray('\nNext (service / GHCR):'))
55
+ console.log(` git add package.json && git commit -m "Bump image version"`)
56
+ console.log(` git push origin <branch>`)
57
+ console.log(` bun run tag`)
58
+ console.log(chalk.dim(` pushes ${tag} → CI\n`))
59
+ }
60
+
61
+ async function main() {
62
+ const args = process.argv.slice(2)
63
+ const dryRun = args.includes('--dry-run')
64
+ const level = args.find((a) => !a.startsWith('--'))?.toLowerCase()
65
+
66
+ if (!level || !['patch', 'minor', 'major'].includes(level)) {
67
+ console.error('Usage: release-bump.mjs patch|minor|major')
68
+ console.error(' SemVer: core or service with 2.0.x in package.json')
69
+ console.error(' CalVer: default service — patch only (26.11.11-dev-pN)')
70
+ process.exit(1)
71
+ }
72
+
73
+ const root = resolveProjectRoot()
74
+ const mode = resolveReleaseMode(root)
75
+ const state = getVersionState('HEAD', root)
76
+
77
+ let nextVersion
78
+ let calverEnv
79
+ if (mode === 'semver') {
80
+ nextVersion = bumpSemverLevel(state.disk.version, level)
81
+ } else {
82
+ if (level !== 'patch') {
83
+ throw new Error('CalVer in package.json — only release:patch. (SemVer için version örn. 2.0.32)')
84
+ }
85
+ const bumped = bumpCalverPatch(root)
86
+ nextVersion = bumped.next
87
+ calverEnv = bumped.env
88
+ }
89
+
90
+ console.log(chalk.cyan(`\nRelease bump (${level})`))
91
+ console.log(` root: ${root}`)
92
+ console.log(` mode: ${mode}`)
93
+ if (calverEnv) console.log(` env: ${calverEnv} (branch / package.json)`)
94
+ console.log(` version: ${chalk.bold(nextVersion)}`)
95
+
96
+ if (dryRun) {
97
+ console.log(chalk.gray('[dry-run] no package.json write\n'))
98
+ return
99
+ }
100
+
101
+ writePackageVersion(root, nextVersion)
102
+
103
+ if (isCorePackageProject(root)) {
104
+ printCoreNextSteps(nextVersion)
105
+ } else {
106
+ printServiceNextSteps(nextVersion)
107
+ }
108
+ }
109
+
110
+ const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)
111
+
112
+ if (isMain) {
113
+ main().catch((error) => {
114
+ console.error(chalk.red(`\n✗ ${error.message}\n`))
115
+ process.exit(1)
116
+ })
117
+ }