@xrystal/core 3.52.6 → 3.52.9

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.52.6",
4
+ "version": "3.52.9",
5
5
  "description": "microservice runtime library",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -26,7 +26,9 @@ export function registerCreateCommand(cli, { cliName = CLI_PRIMARY_NAME, runtime
26
26
  .command('create <project-name> [target-path]')
27
27
  .description('Scaffold new service from GitHub template')
28
28
  .option('-f, --force', 'Allow creating in a non-empty directory')
29
- .option('--workspace', 'Scaffold multi-repo workspace (root tmp.yml + api/admin/web folders)')
29
+ .option('--workspace', 'Scaffold multi-repo workspace (root tmp.yml + api/web/mobile folders)')
30
+ .option('--web', 'Inside a workspace: create under web/ (frontend slot)')
31
+ .option('--mobile', 'Inside a workspace: create under mobile/')
30
32
  .action(async (projectName, targetDir, options) => {
31
33
  const name = projectName?.trim()
32
34
  if (!name) {
@@ -66,19 +68,19 @@ export function registerCreateCommand(cli, { cliName = CLI_PRIMARY_NAME, runtime
66
68
  })
67
69
  console.log(chalk.green('\n✓ Workspace ready\n'))
68
70
  console.log(chalk.gray(` tmp: ${path.relative(process.cwd(), result.tmpPath) || result.tmpPath}`))
69
- console.log(chalk.gray(' outer tmp: ./tmp.yml (workspace) · inner: each api|admin|web project'))
71
+ console.log(chalk.gray(' outer tmp: ./tmp.yml (workspace) · inner: each api|web|mobile project'))
70
72
  if (result.general) {
71
73
  console.log(chalk.green(' api/general: monolith scaffold (gpt template)'))
72
74
  console.log(chalk.gray(` tmp: ${path.relative(process.cwd(), result.general.tmpFilePath) || result.general.tmpFilePath}`))
73
75
  }
74
- console.log(chalk.gray(' link more services into api/ or admin|web (frontend)'))
76
+ console.log(chalk.gray(' link frontends under web/ (incl. admin) or mobile/'))
75
77
  console.log(chalk.gray(' telepresence: .env.telepresence.example + x/environments/.env.telepresence'))
76
78
  console.log(chalk.cyan(`\n cd ${path.relative(process.cwd(), result.root) || result.root}`))
77
79
  try {
78
80
  syncRegistryFromPath(result.root)
79
81
  console.log(chalk.gray(' registered in ~/.xrystal'))
80
82
  } catch {}
81
- console.log(chalk.cyan(` ${cliName} sync`))
83
+ console.log(chalk.cyan(` ${cliName} sync --all`))
82
84
  console.log(chalk.cyan(` ${cliName} telepresence dev general`))
83
85
  printCommandFooter({ version })
84
86
  } catch (error) {
@@ -88,15 +90,33 @@ export function registerCreateCommand(cli, { cliName = CLI_PRIMARY_NAME, runtime
88
90
  return
89
91
  }
90
92
 
93
+ const slot = options.mobile ? 'mobile' : options.web ? 'web' : 'api'
94
+
91
95
  let targetPath
92
96
  let isCurrentDir
97
+ let workspaceRoot
98
+ let inWorkspace
93
99
  try {
94
- ;({ targetPath, isCurrentDir } = resolveCreateTarget(name, targetDir))
100
+ ;({
101
+ targetPath,
102
+ isCurrentDir,
103
+ workspaceRoot,
104
+ inWorkspace,
105
+ slot: resolvedSlot,
106
+ } = resolveCreateTarget(name, targetDir, { slot }))
95
107
  } catch (error) {
96
108
  console.error(chalk.red(`\n✗ ${error.message}\n`))
97
109
  process.exit(1)
98
110
  }
99
111
 
112
+ if (inWorkspace) {
113
+ const version = readCliPackageJson().version
114
+ printCommandHeader({ cliName, command: 'create (workspace link)', version })
115
+ console.log(chalk.gray(` workspace: ${workspaceRoot}`))
116
+ console.log(chalk.gray(` slot: ${resolvedSlot}/`))
117
+ console.log(chalk.gray(` target: ${targetPath}`))
118
+ }
119
+
100
120
  if (fs.existsSync(targetPath)) {
101
121
  const entries = fs.readdirSync(targetPath)
102
122
  if (entries.length > 0 && !options.force) {
@@ -174,6 +194,16 @@ export function registerCreateCommand(cli, { cliName = CLI_PRIMARY_NAME, runtime
174
194
  console.log('')
175
195
  }
176
196
 
197
+ if (inWorkspace) {
198
+ try {
199
+ syncRegistryFromPath(workspaceRoot)
200
+ console.log(chalk.gray(' registered in ~/.xrystal'))
201
+ } catch {
202
+ }
203
+ console.log(chalk.gray(` next: ${cliName} sync --all (from workspace root)`))
204
+ printCommandFooter({ version: readCliPackageJson().version })
205
+ }
206
+
177
207
  const relativePath = path.relative(process.cwd(), targetPath)
178
208
  if (relativePath && relativePath !== '.') console.log(chalk.cyan(` cd ${relativePath}`))
179
209
  console.log(chalk.cyan(` ${devCommand}\n`))
@@ -3,137 +3,103 @@ import path from 'node:path'
3
3
 
4
4
  import { printCommandFooter, printCommandHeader } from '../helpers/banner.mjs'
5
5
  import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
6
- import { getProjectRoot, readCliPackageJson } from '../helpers/project-root.mjs'
7
- import { auditTsconfigAlignment, syncProjectToolchain } from '../helpers/toolchain-config.mjs'
6
+ import { readCliPackageJson } from '../helpers/project-root.mjs'
8
7
  import { ensureTmpFile } from '../helpers/tmp-layout.mjs'
9
8
  import { ensureTmpSchemaVersion } from '../helpers/tmp-schema-version.mjs'
10
- import { findEntries, findWorkspaceRoot } from '../helpers/workspace-resolve.mjs'
11
- import { syncCliRuntime } from '../helpers/project-artifacts.mjs'
12
- import { syncCoreDependency } from '../helpers/sync-core-dependency.mjs'
13
- import { packageDefaults } from '../helpers/package-defaults.mjs'
14
9
  import { syncRegistryFromPath } from '../helpers/xrystal-registry.mjs'
10
+ import { resolveSyncScope } from '../helpers/sync-scope.mjs'
11
+ import { printSyncProjectResult, syncOneProject } from '../helpers/sync-project.mjs'
12
+ import { formatSyncHelp } from '../helpers/cli-help.mjs'
15
13
 
16
- /** Sync tsconfig include/outDir/@/* from project tmp.yml. */
14
+ /** Sync tsconfig + @xrystal/core pin from tmp.yml layout. */
17
15
  export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
18
16
  const run = (options) => {
19
- const cwd = process.cwd()
20
- const workspaceRoot = findWorkspaceRoot(cwd)
21
17
  const coreVersion = readCliPackageJson().version
22
18
 
23
- if (workspaceRoot) {
24
- const entries = findEntries(workspaceRoot)
25
- printCommandHeader({ cliName, command: 'sync', version: coreVersion })
26
- console.log(chalk.gray(` workspace: ${workspaceRoot}`))
27
- console.log(chalk.gray(` entries: ${entries.length}`))
19
+ let scope
20
+ try {
21
+ scope = resolveSyncScope(process.cwd(), { ...options, cliName })
22
+ } catch (error) {
23
+ console.error(chalk.red(`\n✗ ${error.message}\n`))
24
+ process.exit(1)
25
+ }
26
+
27
+ printCommandHeader({ cliName, command: 'sync', version: coreVersion })
28
+ console.log(chalk.gray(` scope: ${scope.label} (${scope.mode})`))
29
+ if (scope.workspaceRoot) {
30
+ console.log(chalk.gray(` workspace: ${scope.workspaceRoot}`))
31
+ }
32
+ console.log(chalk.gray(` projects: ${scope.entries.length}`))
28
33
 
29
- const wsTmp = path.join(workspaceRoot, 'tmp.yml')
34
+ if (scope.mode === 'workspace-all' && scope.workspaceRoot) {
35
+ const wsTmp = path.join(scope.workspaceRoot, 'tmp.yml')
30
36
  if (!options.dryRun) {
31
37
  const wsSchema = ensureTmpSchemaVersion(wsTmp)
32
- if (wsSchema.patched) console.log(chalk.green(` outer tmp end.version → ${wsSchema.schemaVersion} (schema)`))
38
+ if (wsSchema.patched) {
39
+ console.log(chalk.green(` outer tmp end.version → ${wsSchema.schemaVersion} (schema)`))
40
+ }
33
41
  }
42
+ }
34
43
 
35
- if (entries.length === 0) {
36
- console.log(chalk.yellow('\n no linked projects under api/admin/web yet'))
37
- printCommandFooter({ version: coreVersion })
38
- return
44
+ if (scope.entries.length === 0) {
45
+ console.log(chalk.yellow('\n no projects to sync'))
46
+ if (scope.mode === 'workspace-all') {
47
+ console.log(chalk.gray(' link services under api/ web/ mobile/ then re-run'))
39
48
  }
49
+ printCommandFooter({ version: coreVersion })
50
+ return
51
+ }
40
52
 
41
- let failed = 0
42
- for (const entry of entries) {
43
- console.log(chalk.cyan(`\n→ ${entry.name} (${entry.type})`))
44
- console.log(chalk.gray(` path: ${entry.path}`))
45
- if (options.dryRun) {
46
- const preview = syncProjectToolchain(entry.path, { write: false })
47
- console.log(chalk.gray(` would update ${preview.tsconfigRel ?? 'tsconfig.json'}`))
48
- const core = syncCoreDependency(entry.path, coreVersion, { dryRun: true })
49
- if (core.synced) {
50
- console.log(chalk.gray(` would pin ${packageDefaults.packageName}@${coreVersion} (from ${core.current ?? core.declared})`))
51
- } else if (core.reason === 'up-to-date') {
52
- console.log(chalk.gray(` ${packageDefaults.packageName}@${coreVersion} (ok)`))
53
- }
54
- continue
55
- }
56
- try {
57
- syncCliRuntime(entry.path, { force: false })
58
- const result = syncProjectToolchain(entry.path, { write: true })
59
- console.log(result.created
60
- ? chalk.green(` created ${result.tsconfigRel}`)
61
- : chalk.green(` updated ${result.tsconfigRel}`))
62
- const core = syncCoreDependency(entry.path, coreVersion, { dryRun: options.dryRun })
63
- if (core.synced) {
64
- const label = options.dryRun
65
- ? chalk.gray(` would pin ${packageDefaults.packageName}@${coreVersion}`)
66
- : chalk.green(` pinned ${packageDefaults.packageName}@${coreVersion}`)
67
- console.log(label)
68
- } else if (core.reason === 'up-to-date') {
69
- console.log(chalk.gray(` ${packageDefaults.packageName}@${coreVersion} (ok)`))
70
- }
71
- if (!options.dryRun) {
72
- const schema = ensureTmpSchemaVersion(entry.tmp)
73
- if (schema.patched) console.log(chalk.green(` inner tmp end.version → ${schema.schemaVersion} (schema)`))
74
- }
75
- } catch (error) {
76
- failed += 1
77
- console.log(chalk.red(` failed: ${error.message}`))
78
- }
53
+ let failed = 0
54
+ for (const entry of scope.entries) {
55
+ if (options.dryRun) {
56
+ const preview = syncOneProject(entry, coreVersion, { dryRun: true, tmpPath: entry.tmp ?? null })
57
+ printSyncProjectResult(preview)
58
+ continue
59
+ }
60
+
61
+ let tmpPath = entry.tmp ?? null
62
+ if (!tmpPath && scope.mode === 'standalone') {
63
+ tmpPath = ensureTmpFile(entry.path).tmpFilePath
79
64
  }
65
+
66
+ const result = syncOneProject(entry, coreVersion, { dryRun: false, tmpPath })
67
+ printSyncProjectResult(result)
68
+ if (result.failed) failed += 1
69
+ }
70
+
71
+ if (scope.mode === 'workspace-all' && scope.workspaceRoot && !options.dryRun) {
80
72
  try {
81
- syncRegistryFromPath(workspaceRoot)
82
- console.log(chalk.gray(' registry updated (~/.xrystal)'))
73
+ syncRegistryFromPath(scope.workspaceRoot)
74
+ console.log(chalk.gray('\n registry updated (~/.xrystal)'))
83
75
  } catch (error) {
84
- console.log(chalk.yellow(` registry skipped: ${error.message}`))
85
- }
86
- if (failed) {
87
- console.log(chalk.red(`\n sync finished with ${failed} error(s)`))
88
- printCommandFooter({ version: coreVersion })
89
- process.exit(1)
76
+ console.log(chalk.yellow(`\n registry skipped: ${error.message}`))
90
77
  }
91
- console.log(chalk.green('\n workspace sync done'))
92
- printCommandFooter({ version: coreVersion })
93
- return
94
78
  }
95
79
 
96
- const root = getProjectRoot()
97
- const auditBefore = auditTsconfigAlignment(root)
98
-
99
- printCommandHeader({ cliName, command: 'sync', version: coreVersion })
100
- console.log(chalk.gray(` root: ${root}`))
101
-
102
- const lo = auditBefore.layoutOptions ?? {}
103
- console.log(chalk.gray(' from tmp.yml:'))
104
- console.log(chalk.gray(` paths.root: ${lo.rootFolderPath ?? '—'}`))
105
- console.log(chalk.gray(` paths.source: ${lo.mainFolderPath ?? '—'}`))
106
- console.log(chalk.gray(` paths.special.dist: ${lo.pathsDist ?? '—'}`))
80
+ if (scope.hintAll) {
81
+ console.log(chalk.dim(`\n tip: ${scope.hintAll}`))
82
+ }
107
83
 
108
- if (options.dryRun) {
109
- const preview = syncProjectToolchain(root, { write: false })
110
- console.log(chalk.gray('\n would write tsconfig.json:'))
111
- console.log(chalk.gray(` include: ${JSON.stringify(preview.merged.include)}`))
112
- console.log(chalk.gray(` outDir: ${preview.merged.compilerOptions.outDir}`))
113
- console.log(chalk.gray(` paths: ${JSON.stringify(preview.merged.compilerOptions.paths)}`))
114
- console.log(chalk.gray(`\n bunfig → ${preview.paths.bunfigAliasLine}`))
84
+ if (failed) {
85
+ console.log(chalk.red(`\n sync finished with ${failed} error(s)`))
115
86
  printCommandFooter({ version: coreVersion })
116
- return
87
+ process.exit(1)
117
88
  }
118
89
 
119
- const layout = ensureTmpFile(root)
120
- const result = syncProjectToolchain(root, { write: true })
121
- const schema = ensureTmpSchemaVersion(layout.tmpFilePath)
122
- if (schema.patched) console.log(chalk.green(` tmp end.version → ${schema.schemaVersion} (schema)`))
123
- console.log(result.created
124
- ? chalk.green(` created ${result.tsconfigRel}`)
125
- : chalk.green(` updated ${result.tsconfigRel}`))
126
- console.log(chalk.gray(` include → ${JSON.stringify(result.merged.include)}`))
127
- console.log(chalk.gray(` outDir → ${result.merged.compilerOptions.outDir}`))
128
- console.log(chalk.yellow(`\n bunfig.toml [resolve.alias]: ${result.paths.bunfigAliasLine}`))
90
+ console.log(chalk.green('\n sync done'))
129
91
  printCommandFooter({ version: coreVersion })
130
92
  }
131
93
 
132
94
  cli
133
95
  .command('sync')
134
96
  .alias('sync-toolchain')
135
- .description('Sync tsconfig + @xrystal/core pin (workspace: all inner tmp projects + ~/.xrystal registry)')
97
+ .description('Sync tsconfig + @xrystal/core for current project (use --all inside a workspace for every link)')
136
98
  .option('--dry-run', 'Preview without writing')
99
+ .option('--self', 'Inside a workspace: sync only the current linked project')
100
+ .option('--all', 'Inside a workspace: sync all api/web/mobile linked projects + registry')
101
+ .option('--workspace', 'Alias for --all')
102
+ .addHelpText('after', () => formatSyncHelp({ cliName }))
137
103
  .action(run)
138
104
  }
139
105
 
@@ -15,6 +15,7 @@ import {
15
15
  import { formatLoaderSummary, summarizeLoaders } from '../helpers/tmp-config.mjs'
16
16
  import { packageDefaults } from '../helpers/package-defaults.mjs'
17
17
  import { ensureTmpSchemaVersion, readTmpSchemaVersion } from '../helpers/tmp-schema-version.mjs'
18
+ import { resolveProjectContext } from '../helpers/project-context.mjs'
18
19
 
19
20
  export function registerTmpCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
20
21
  cli
@@ -41,7 +42,9 @@ export function registerTmpCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
41
42
  const rel = relativeFromRoot(root, result.tmpFilePath)
42
43
  const schema = ensureTmpSchemaVersion(result.tmpFilePath)
43
44
 
45
+ const ctx = resolveProjectContext()
44
46
  printCommandHeader({ cliName, command: 'tmp', version })
47
+ console.log(chalk.gray(` scope: ${ctx.label}`))
45
48
  console.log(chalk.gray(` root: ${root}`))
46
49
  console.log(result.created ? chalk.green(` created ${rel}`) : chalk.gray(` ok ${rel}`))
47
50
  const schemaVersion = readTmpSchemaVersion(result.tmpFilePath)
@@ -291,16 +291,36 @@ function resolveMergedPaths(configs) {
291
291
  tmpRelPath: `${root}/${tmpName}`.replace(/\/+/g, "/")
292
292
  };
293
293
  }
294
+ function readWorkspaceGlobalBlock(global) {
295
+ const pathsRaw = isRecord2(global.paths) ? global.paths : {};
296
+ const root = typeof pathsRaw.root === "string" && pathsRaw.root.trim() ? pathsRaw.root.trim() : ".";
297
+ const optionsRaw = isRecord2(global.options) ? global.options : undefined;
298
+ return {
299
+ type: "workspace" /* WORKSPACE */,
300
+ runtime: "bun" /* BUN */,
301
+ framework: "",
302
+ paths: {
303
+ root,
304
+ tmp: typeof pathsRaw.tmp === "string" ? pathsRaw.tmp : "tmp.yml"
305
+ },
306
+ vars: isRecord2(global.vars) ? { ...global.vars } : {},
307
+ options: optionsRaw ? { fileWatchIntervalMs: readWatchIntervalValue(optionsRaw.fileWatchIntervalMs) } : undefined
308
+ };
309
+ }
294
310
  function readTmpGlobalBlock(configs) {
295
311
  const global = isRecord2(configs?.global) ? configs.global : {};
296
312
  const varsRaw = isRecord2(global.vars) ? global.vars : {};
297
313
  const typeRaw = global.type;
314
+ const type = typeRaw !== undefined ? normalizeGlobalType(typeRaw) : undefined;
315
+ if (type === "workspace" /* WORKSPACE */) {
316
+ return readWorkspaceGlobalBlock(global);
317
+ }
298
318
  if (typeof global.framework !== "string" || !global.framework.trim()) {
299
319
  throw new Error(`${defaults_default.packageName}: configs.global.framework is required`);
300
320
  }
301
321
  return {
302
322
  runtime: normalizeRuntime(global.runtime),
303
- type: typeRaw !== undefined ? normalizeGlobalType(typeRaw) : undefined,
323
+ type,
304
324
  framework: global.framework.trim(),
305
325
  paths: readTmpGlobalPathsBlock(configs),
306
326
  vars: { ...varsRaw },
@@ -370,6 +390,15 @@ function resolveTmpRuntimeConfigs(tmp) {
370
390
  assertNoLegacyTmpKeys(configs);
371
391
  const global = readTmpGlobalBlock(configs);
372
392
  const depends = readTmpDependsBlock(configs);
393
+ if (global.type === "workspace" /* WORKSPACE */) {
394
+ return {
395
+ global: { ...global, build: {} },
396
+ depends: buildNormalizedDepends(depends),
397
+ deploymentName: resolveTmpDeploymentName(tmp),
398
+ rootFolderPath: ".",
399
+ tmpRelPath: global.paths.tmp ?? "tmp.yml"
400
+ };
401
+ }
373
402
  const merged = resolveMergedPaths(configs);
374
403
  return {
375
404
  global: {
@@ -176,8 +176,8 @@ var TMP_FILE = "tmp.yml";
176
176
  var SKIP_DIRS = new Set(["node_modules", ".git", "dist", ".turbo", "coverage"]);
177
177
  var DEFAULT_FOLDER_STRUCTURE = {
178
178
  api: "api",
179
- admin: "admin",
180
- web: "web"
179
+ web: "web",
180
+ mobile: "mobile"
181
181
  };
182
182
  function parseScalar(raw) {
183
183
  const trimmed = raw.trim();
@@ -211,18 +211,28 @@ function readTmpFile(filePath) {
211
211
  }
212
212
  function parseFolderStructure(text) {
213
213
  const fsBlock = text.match(/folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1] ?? "";
214
+ if (/^[ \t]+admin:/m.test(fsBlock)) {
215
+ throw new Error("configs.folder-structure.admin removed — put admin panels under web/ (e.g. web/admin-ui)");
216
+ }
214
217
  const readSlot = (key) => {
215
- const scalar = fsBlock.match(new RegExp(`^[ ]+${key}:s*(.+?)(?:s+#.*)?$`, "m"));
218
+ const scalar = fsBlock.match(new RegExp(`^[ ]+${key}:\\s*(.+?)(?:\\s+#.*)?$`, "m"));
216
219
  if (scalar)
217
220
  return parseScalar(scalar[1]);
218
221
  return DEFAULT_FOLDER_STRUCTURE[key];
219
222
  };
220
223
  return {
221
224
  api: readSlot("api"),
222
- admin: readSlot("admin"),
223
- web: readSlot("web")
225
+ web: readSlot("web"),
226
+ mobile: readSlot("mobile")
224
227
  };
225
228
  }
229
+ function workspaceDiscoverySlots(fsMap) {
230
+ return [
231
+ { slot: "api", folder: fsMap.api, frontendOnly: false },
232
+ { slot: "web", folder: fsMap.web, frontendOnly: true },
233
+ { slot: "mobile", folder: fsMap.mobile, frontendOnly: true }
234
+ ];
235
+ }
226
236
  function entryName(meta) {
227
237
  const project = (meta.projectName ?? "").trim();
228
238
  return project || null;
@@ -313,9 +323,8 @@ function findEntries(workspaceRoot) {
313
323
  const fsMap = wsMeta.folderStructure;
314
324
  const entries = [];
315
325
  const seen = new Set;
316
- const slots = ["api", "admin", "web"];
317
- for (const slot of slots) {
318
- const folder = path2.join(workspaceRoot, fsMap[slot]);
326
+ for (const { slot, folder: folderRel, frontendOnly } of workspaceDiscoverySlots(fsMap)) {
327
+ const folder = path2.join(workspaceRoot, folderRel);
319
328
  for (const tmpPath of walkTmpUnder(folder)) {
320
329
  if (path2.resolve(tmpPath) === path2.join(workspaceRoot, TMP_FILE))
321
330
  continue;
@@ -323,7 +332,7 @@ function findEntries(workspaceRoot) {
323
332
  const kind = entryType(meta, slot);
324
333
  if (kind === "workspace" /* WORKSPACE */)
325
334
  continue;
326
- if (slot !== "api" && kind !== "frontend" /* FRONTEND */)
335
+ if (frontendOnly && kind !== "frontend" /* FRONTEND */)
327
336
  continue;
328
337
  if (kind !== "api-service" /* API_SERVICE */ && kind !== "frontend" /* FRONTEND */)
329
338
  continue;
@@ -370,17 +379,10 @@ function workspaceTmpTemplate(projectName) {
370
379
  configs:
371
380
  global:
372
381
  type: workspace
373
- runtime: bun
374
- framework: bun
375
- paths:
376
- root: .
377
- tmp: tmp.yml
378
- options:
379
- fileWatchIntervalMs: 500
380
382
  folder-structure:
381
383
  api: api
382
- admin: admin
383
384
  web: web
385
+ mobile: mobile
384
386
 
385
387
  kubeconfig: ~/.kube/config
386
388
 
@@ -391,6 +393,7 @@ end:
391
393
  export {
392
394
  workspaceTmpTemplate,
393
395
  workspaceProjectName,
396
+ workspaceDiscoverySlots,
394
397
  resolveEntryPath,
395
398
  readWorkspaceGlobalTmp,
396
399
  readWorkspaceCoreTmp,
@@ -7,12 +7,12 @@ import { brandTitle } from './banner.mjs'
7
7
  import { packageDefaults } from './package-defaults.mjs'
8
8
 
9
9
  const QUICK_COMMANDS = [
10
- { cmd: 'project', desc: 'Where am I? workspace / service / core library context' },
11
- { cmd: 'create <name> --workspace', desc: 'Outer tmp + api/general + admin/web' },
12
- { cmd: 'tmp', desc: 'Ensure tmp.yml (inner x/ or outer ./ workspace)' },
13
- { cmd: 'sync', desc: 'Inner tsconfig + pin @xrystal/core · registry if workspace' },
14
- { cmd: 'workspaces', desc: 'Global registry ~/.xrystal (not repo tmp)' },
15
- { cmd: 'tp dev', hint: '<deploy>', desc: 'Telepresence local intercept' },
10
+ { cmd: 'project', desc: 'Where am I? workspace root · linked service · standalone' },
11
+ { cmd: 'sync', desc: 'This project: tsconfig + @xrystal/core pin' },
12
+ { cmd: 'sync --all', desc: 'Inside workspace: every linked api/web/mobile project' },
13
+ { cmd: 'tmp', desc: 'Ensure tmp.yml for current scope (inner x/ or outer ./)' },
14
+ { cmd: 'create <name> --workspace', desc: 'Outer tmp + api/general + web/mobile slots' },
15
+ { cmd: 'workspaces', desc: 'Global registry ~/.xrystal (not repo tmp.yml)' },
16
16
  { cmd: 'dev / build / doctor', desc: 'Develop & diagnostics' },
17
17
  ]
18
18
 
@@ -36,8 +36,9 @@ const COMMAND_GROUPS = [
36
36
  {
37
37
  title: 'Workspace',
38
38
  items: [
39
- { cmd: 'create <name> --workspace', desc: 'Outer ./tmp.yml + api/general inner monolith + admin/web' },
40
- { cmd: 'sync', desc: 'All inner projects: tsconfig + @xrystal/core pin + registry rescan' },
39
+ { cmd: 'create <name> --workspace', desc: 'Outer ./tmp.yml + api/general + web/mobile (admin under web/)' },
40
+ { cmd: 'sync --all', desc: 'From root or any link: all api/web/mobile + ~/.xrystal registry' },
41
+ { cmd: 'workspaces [list|sync]', desc: 'Inspect/rescan global registry (separate from xry sync)' },
41
42
  { cmd: 'telepresence dev <deploy>', aliases: 'tp dev', desc: 'Intercept cluster pod → local dev' },
42
43
  { cmd: 'telepresence connect', aliases: 'tp connect', desc: 'Connect Telepresence to dev/test namespace' },
43
44
  ],
@@ -46,7 +47,9 @@ const COMMAND_GROUPS = [
46
47
  title: 'Project',
47
48
  items: [
48
49
  { cmd: 'create', hint: '<name> [path]', desc: 'Standalone service (gpt template + inner x/tmp.yml)' },
49
- { cmd: 'tmp', desc: 'Ensure inner/outer tmp.yml · end.version = schema (currently 1)' },
50
+ { cmd: 'sync', desc: 'Current project only: tsconfig + @xrystal/core pin + tmp schema' },
51
+ { cmd: 'sync --self', desc: 'Inside workspace: explicit current linked project only' },
52
+ { cmd: 'tmp', desc: 'Ensure tmp.yml for current folder scope · end.version = schema' },
50
53
  { cmd: 'hooks install', desc: 'Install .git/hooks pre-commit version check' },
51
54
  { cmd: 'hooks status', desc: 'Show whether pre-commit hook is installed' },
52
55
  ],
@@ -93,6 +96,24 @@ function formatTreeLines(items) {
93
96
  return lines.join('\n')
94
97
  }
95
98
 
99
+ export function formatSyncHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
100
+ const rows = [
101
+ { ctx: 'Standalone service', cmd: `${cliName} sync`, effect: 'tsconfig + pin @xrystal/core + tmp schema' },
102
+ { ctx: 'Workspace root', cmd: `${cliName} sync`, effect: 'all linked projects + registry (same as --all)' },
103
+ { ctx: 'Inside api/web/mobile', cmd: `${cliName} sync`, effect: 'current project only (default)' },
104
+ { ctx: 'Inside api/web/mobile', cmd: `${cliName} sync --all`, effect: 'every linked project + registry' },
105
+ { ctx: 'Global registry only', cmd: `${cliName} workspaces sync`, effect: 'rescan ~/.xrystal from cwd' },
106
+ ]
107
+ const lines = rows.map((row) => ` ${chalk.gray(row.ctx.padEnd(22))} ${chalk.cyan(row.cmd)}\n${' '.repeat(26)}${chalk.gray(row.effect)}`)
108
+ return [
109
+ chalk.bold.white('\n Sync scope'),
110
+ ...lines,
111
+ '',
112
+ chalk.gray(' xry project — shows which row applies to your cwd'),
113
+ '',
114
+ ].join('\n')
115
+ }
116
+
96
117
  /** Bare CLI — banner altında kısa, işe yarayan komutlar. */
97
118
  export function printQuickStartGuide({ cliName = CLI_PRIMARY_NAME } = {}) {
98
119
  console.log(chalk.bold.yellow('\n Quick start'))
@@ -141,10 +162,11 @@ export function formatRootHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
141
162
 
142
163
  export function formatCreateHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
143
164
  const examples = [
144
- { cmd: `${cliName} create demo --workspace`, desc: '→ workspace + api/general + admin/web' },
145
- { cmd: `${cliName} create my-api`, desc: '→ ./my-api (current folder)' },
146
- { cmd: `${cliName} create my-api ..`, desc: '→ ../my-api' },
147
- { cmd: `${cliName} create my-api ~/services`, desc: '→ ~/services/my-api' },
165
+ { cmd: `${cliName} create demo --workspace`, desc: '→ workspace + api/general + web/mobile' },
166
+ { cmd: `${cliName} create my-api`, desc: '→ ./my-api (or workspace/api/my-api if inside ws)' },
167
+ { cmd: `${cliName} create my-api ..`, desc: '→ ../my-api (standalone parent folder)' },
168
+ { cmd: `${cliName} create my-api ~/ws`, desc: '→ ~/ws/api/my-api when ~/ws is a workspace' },
169
+ { cmd: `${cliName} create ui --web`, desc: '→ workspace/web/ui when inside a workspace' },
148
170
  { cmd: `${cliName} create .`, desc: '→ init in current directory' },
149
171
  ]
150
172
  return [
@@ -1,12 +1,32 @@
1
+ import fs from 'node:fs'
1
2
  import path from 'node:path'
2
3
 
4
+ import {
5
+ DEFAULT_FOLDER_STRUCTURE,
6
+ findWorkspaceRoot,
7
+ readTmpFile,
8
+ } from './workspace-resolve.mjs'
9
+
10
+ function resolveReal(input) {
11
+ const resolved = path.resolve(input)
12
+ try {
13
+ return fs.realpathSync.native(resolved)
14
+ } catch {
15
+ return resolved
16
+ }
17
+ }
18
+
3
19
  /**
4
20
  * Resolve scaffold target directory.
5
21
  *
22
+ * When cwd or target-path sits inside a workspace, services land under
23
+ * api|web|mobile automatically (default slot: api).
24
+ *
6
25
  * @param {string} projectName Folder name or `.` for current directory
7
26
  * @param {string | undefined} targetDir Optional parent path (default: cwd)
27
+ * @param {{ slot?: 'api' | 'web' | 'mobile' }} options
8
28
  */
9
- export function resolveCreateTarget(projectName, targetDir) {
29
+ export function resolveCreateTarget(projectName, targetDir, { slot = 'api' } = {}) {
10
30
  const cwd = process.cwd()
11
31
  const name = String(projectName ?? '').trim()
12
32
 
@@ -19,17 +39,41 @@ export function resolveCreateTarget(projectName, targetDir) {
19
39
  return {
20
40
  targetPath: parent,
21
41
  isCurrentDir: true,
42
+ workspaceRoot: findWorkspaceRoot(parent),
43
+ slot: null,
44
+ inWorkspace: Boolean(findWorkspaceRoot(parent)),
22
45
  }
23
46
  }
24
47
 
25
48
  const base = targetDir ? path.resolve(cwd, targetDir) : cwd
49
+ const workspaceRoot = findWorkspaceRoot(base)
50
+
51
+ if (workspaceRoot) {
52
+ const wsRoot = resolveReal(workspaceRoot)
53
+ const wsTmp = path.join(wsRoot, 'tmp.yml')
54
+ const fsMap = readTmpFile(wsTmp).folderStructure
55
+ const slotFolder = fsMap[slot] ?? DEFAULT_FOLDER_STRUCTURE[slot]
56
+ const slotRoot = path.join(wsRoot, slotFolder)
57
+ const targetPath = resolveReal(path.join(slotRoot, name))
58
+
59
+ return {
60
+ targetPath,
61
+ isCurrentDir: false,
62
+ workspaceRoot: wsRoot,
63
+ slot,
64
+ inWorkspace: true,
65
+ }
66
+ }
67
+
26
68
  return {
27
- targetPath: path.join(base, name),
69
+ targetPath: resolveReal(path.join(base, name)),
28
70
  isCurrentDir: false,
71
+ workspaceRoot: null,
72
+ slot: null,
73
+ inWorkspace: false,
29
74
  }
30
75
  }
31
76
 
32
- export function formatCreateTargetPreview(projectName, targetDir) {
33
- const { targetPath, isCurrentDir } = resolveCreateTarget(projectName, targetDir)
34
- return { targetPath, isCurrentDir, label: isCurrentDir ? targetPath : targetPath }
77
+ export function formatCreateTargetPreview(projectName, targetDir, options = {}) {
78
+ return resolveCreateTarget(projectName, targetDir, options)
35
79
  }