@xrystal/core 3.52.7 → 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 +1 -1
- package/x/bin/commands/create.mjs +34 -4
- package/x/bin/commands/sync.mjs +2 -2
- package/x/bin/helpers/.generated/tmp-schema.mjs +30 -1
- package/x/bin/helpers/.generated/workspace.mjs +20 -17
- package/x/bin/helpers/cli-help.mjs +11 -10
- package/x/bin/helpers/create-target.mjs +49 -5
- package/x/bin/helpers/project-context.mjs +2 -2
- package/x/bin/helpers/sync-scope.mjs +1 -1
- package/x/bin/helpers/workspace-resolve.mjs +2 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +32 -1
- package/x/dist/utils/helpers/workspace/index.d.ts +10 -3
- package/x/dist/utils/helpers/workspace/index.js +17 -15
package/package.json
CHANGED
|
@@ -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/
|
|
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,12 +68,12 @@ 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|
|
|
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
|
|
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 {
|
|
@@ -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
|
-
;({
|
|
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`))
|
package/x/bin/commands/sync.mjs
CHANGED
|
@@ -44,7 +44,7 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
44
44
|
if (scope.entries.length === 0) {
|
|
45
45
|
console.log(chalk.yellow('\n no projects to sync'))
|
|
46
46
|
if (scope.mode === 'workspace-all') {
|
|
47
|
-
console.log(chalk.gray(' link services under api/
|
|
47
|
+
console.log(chalk.gray(' link services under api/ web/ mobile/ then re-run'))
|
|
48
48
|
}
|
|
49
49
|
printCommandFooter({ version: coreVersion })
|
|
50
50
|
return
|
|
@@ -97,7 +97,7 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
97
97
|
.description('Sync tsconfig + @xrystal/core for current project (use --all inside a workspace for every link)')
|
|
98
98
|
.option('--dry-run', 'Preview without writing')
|
|
99
99
|
.option('--self', 'Inside a workspace: sync only the current linked project')
|
|
100
|
-
.option('--all', 'Inside a workspace: sync all api/
|
|
100
|
+
.option('--all', 'Inside a workspace: sync all api/web/mobile linked projects + registry')
|
|
101
101
|
.option('--workspace', 'Alias for --all')
|
|
102
102
|
.addHelpText('after', () => formatSyncHelp({ cliName }))
|
|
103
103
|
.action(run)
|
|
@@ -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
|
|
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
|
-
|
|
180
|
-
|
|
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}
|
|
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
|
-
|
|
223
|
-
|
|
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
|
|
317
|
-
|
|
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 (
|
|
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,
|
|
@@ -9,9 +9,9 @@ import { packageDefaults } from './package-defaults.mjs'
|
|
|
9
9
|
const QUICK_COMMANDS = [
|
|
10
10
|
{ cmd: 'project', desc: 'Where am I? workspace root · linked service · standalone' },
|
|
11
11
|
{ cmd: 'sync', desc: 'This project: tsconfig + @xrystal/core pin' },
|
|
12
|
-
{ cmd: 'sync --all', desc: 'Inside workspace: every linked api/
|
|
12
|
+
{ cmd: 'sync --all', desc: 'Inside workspace: every linked api/web/mobile project' },
|
|
13
13
|
{ cmd: 'tmp', desc: 'Ensure tmp.yml for current scope (inner x/ or outer ./)' },
|
|
14
|
-
{ cmd: 'create <name> --workspace', desc: 'Outer tmp + api/general +
|
|
14
|
+
{ cmd: 'create <name> --workspace', desc: 'Outer tmp + api/general + web/mobile slots' },
|
|
15
15
|
{ cmd: 'workspaces', desc: 'Global registry ~/.xrystal (not repo tmp.yml)' },
|
|
16
16
|
{ cmd: 'dev / build / doctor', desc: 'Develop & diagnostics' },
|
|
17
17
|
]
|
|
@@ -36,8 +36,8 @@ const COMMAND_GROUPS = [
|
|
|
36
36
|
{
|
|
37
37
|
title: 'Workspace',
|
|
38
38
|
items: [
|
|
39
|
-
{ cmd: 'create <name> --workspace', desc: 'Outer ./tmp.yml + api/general
|
|
40
|
-
{ cmd: 'sync --all', desc: 'From root or any link: all api/
|
|
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
41
|
{ cmd: 'workspaces [list|sync]', desc: 'Inspect/rescan global registry (separate from xry sync)' },
|
|
42
42
|
{ cmd: 'telepresence dev <deploy>', aliases: 'tp dev', desc: 'Intercept cluster pod → local dev' },
|
|
43
43
|
{ cmd: 'telepresence connect', aliases: 'tp connect', desc: 'Connect Telepresence to dev/test namespace' },
|
|
@@ -100,8 +100,8 @@ export function formatSyncHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
100
100
|
const rows = [
|
|
101
101
|
{ ctx: 'Standalone service', cmd: `${cliName} sync`, effect: 'tsconfig + pin @xrystal/core + tmp schema' },
|
|
102
102
|
{ ctx: 'Workspace root', cmd: `${cliName} sync`, effect: 'all linked projects + registry (same as --all)' },
|
|
103
|
-
{ ctx: 'Inside api/
|
|
104
|
-
{ ctx: 'Inside api/
|
|
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
105
|
{ ctx: 'Global registry only', cmd: `${cliName} workspaces sync`, effect: 'rescan ~/.xrystal from cwd' },
|
|
106
106
|
]
|
|
107
107
|
const lines = rows.map((row) => ` ${chalk.gray(row.ctx.padEnd(22))} ${chalk.cyan(row.cmd)}\n${' '.repeat(26)}${chalk.gray(row.effect)}`)
|
|
@@ -162,10 +162,11 @@ export function formatRootHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
162
162
|
|
|
163
163
|
export function formatCreateHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
164
164
|
const examples = [
|
|
165
|
-
{ cmd: `${cliName} create demo --workspace`, desc: '→ workspace + api/general +
|
|
166
|
-
{ cmd: `${cliName} create my-api`, desc: '→ ./my-api (
|
|
167
|
-
{ cmd: `${cliName} create my-api ..`, desc: '→ ../my-api' },
|
|
168
|
-
{ cmd: `${cliName} create 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' },
|
|
169
170
|
{ cmd: `${cliName} create .`, desc: '→ init in current directory' },
|
|
170
171
|
]
|
|
171
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
|
-
|
|
34
|
-
return { targetPath, isCurrentDir, label: isCurrentDir ? targetPath : targetPath }
|
|
77
|
+
export function formatCreateTargetPreview(projectName, targetDir, options = {}) {
|
|
78
|
+
return resolveCreateTarget(projectName, targetDir, options)
|
|
35
79
|
}
|
|
@@ -107,14 +107,14 @@ export function resolveProjectContext(startDir = process.cwd()) {
|
|
|
107
107
|
|
|
108
108
|
const hints = []
|
|
109
109
|
if (kind === 'workspace-root') {
|
|
110
|
-
hints.push('Outer tmp: ./tmp.yml · inner tmp: each api|
|
|
110
|
+
hints.push('Outer tmp: ./tmp.yml · inner tmp: each api|web|mobile project (admin → web/)')
|
|
111
111
|
hints.push('xry sync — all linked projects + ~/.xrystal registry')
|
|
112
112
|
hints.push('xry sync --all — same from any folder under this workspace')
|
|
113
113
|
hints.push('xry workspaces — global registry (~/.xrystal), not repo tmp files')
|
|
114
114
|
} else if (kind === 'workspace-service') {
|
|
115
115
|
hints.push(`Outer workspace: ${workspaceRoot}`)
|
|
116
116
|
hints.push('xry sync — this service only (tsconfig + @xrystal/core pin)')
|
|
117
|
-
hints.push('xry sync --all — every linked api/
|
|
117
|
+
hints.push('xry sync --all — every linked api/web/mobile project + registry')
|
|
118
118
|
hints.push('xry tmp — inner x/tmp.yml · configs.global.type drives loader profile')
|
|
119
119
|
} else {
|
|
120
120
|
hints.push('xry sync — tsconfig + @xrystal/core pin for this repo')
|
|
@@ -66,6 +66,6 @@ export function resolveSyncScope(cwd = process.cwd(), options = {}) {
|
|
|
66
66
|
targetRoot: projectRoot,
|
|
67
67
|
workspaceRoot,
|
|
68
68
|
entries: self ? [self] : [{ path: projectRoot, name: path.basename(projectRoot), type: 'project' }],
|
|
69
|
-
hintAll: `Run ${options.cliName ?? 'xry'} sync --all from here to sync every linked api/
|
|
69
|
+
hintAll: `Run ${options.cliName ?? 'xry'} sync --all from here to sync every linked api/web/mobile project`,
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -94,16 +94,38 @@ export function resolveMergedPaths(configs) {
|
|
|
94
94
|
tmpRelPath: `${root}/${tmpName}`.replace(/\/+/g, '/'),
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
|
+
function readWorkspaceGlobalBlock(global) {
|
|
98
|
+
const pathsRaw = isRecord(global.paths) ? global.paths : {};
|
|
99
|
+
const root = typeof pathsRaw.root === 'string' && pathsRaw.root.trim() ? pathsRaw.root.trim() : '.';
|
|
100
|
+
const optionsRaw = isRecord(global.options) ? global.options : undefined;
|
|
101
|
+
return {
|
|
102
|
+
type: GlobalTypeEnum.WORKSPACE,
|
|
103
|
+
runtime: RuntimeEnum.BUN,
|
|
104
|
+
framework: '',
|
|
105
|
+
paths: {
|
|
106
|
+
root,
|
|
107
|
+
tmp: typeof pathsRaw.tmp === 'string' ? pathsRaw.tmp : 'tmp.yml',
|
|
108
|
+
},
|
|
109
|
+
vars: isRecord(global.vars) ? { ...global.vars } : {},
|
|
110
|
+
options: optionsRaw
|
|
111
|
+
? { fileWatchIntervalMs: readWatchIntervalValue(optionsRaw.fileWatchIntervalMs) }
|
|
112
|
+
: undefined,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
97
115
|
export function readTmpGlobalBlock(configs) {
|
|
98
116
|
const global = isRecord(configs?.global) ? configs.global : {};
|
|
99
117
|
const varsRaw = isRecord(global.vars) ? global.vars : {};
|
|
100
118
|
const typeRaw = global.type;
|
|
119
|
+
const type = typeRaw !== undefined ? normalizeGlobalType(typeRaw) : undefined;
|
|
120
|
+
if (type === GlobalTypeEnum.WORKSPACE) {
|
|
121
|
+
return readWorkspaceGlobalBlock(global);
|
|
122
|
+
}
|
|
101
123
|
if (typeof global.framework !== 'string' || !global.framework.trim()) {
|
|
102
124
|
throw new Error(`${defaults.packageName}: configs.global.framework is required`);
|
|
103
125
|
}
|
|
104
126
|
return {
|
|
105
127
|
runtime: normalizeRuntime(global.runtime),
|
|
106
|
-
type
|
|
128
|
+
type,
|
|
107
129
|
framework: global.framework.trim(),
|
|
108
130
|
paths: readTmpGlobalPathsBlock(configs),
|
|
109
131
|
vars: { ...varsRaw },
|
|
@@ -177,6 +199,15 @@ export function resolveTmpRuntimeConfigs(tmp) {
|
|
|
177
199
|
assertNoLegacyTmpKeys(configs);
|
|
178
200
|
const global = readTmpGlobalBlock(configs);
|
|
179
201
|
const depends = readTmpDependsBlock(configs);
|
|
202
|
+
if (global.type === GlobalTypeEnum.WORKSPACE) {
|
|
203
|
+
return {
|
|
204
|
+
global: { ...global, build: {} },
|
|
205
|
+
depends: buildNormalizedDepends(depends),
|
|
206
|
+
deploymentName: resolveTmpDeploymentName(tmp),
|
|
207
|
+
rootFolderPath: '.',
|
|
208
|
+
tmpRelPath: global.paths.tmp ?? 'tmp.yml',
|
|
209
|
+
};
|
|
210
|
+
}
|
|
180
211
|
const merged = resolveMergedPaths(configs);
|
|
181
212
|
return {
|
|
182
213
|
global: {
|
|
@@ -3,8 +3,8 @@ export declare const TMP_FILE = "tmp.yml";
|
|
|
3
3
|
export declare const SKIP_DIRS: Set<string>;
|
|
4
4
|
export type FolderStructure = {
|
|
5
5
|
api: string;
|
|
6
|
-
admin: string;
|
|
7
6
|
web: string;
|
|
7
|
+
mobile: string;
|
|
8
8
|
};
|
|
9
9
|
export declare const DEFAULT_FOLDER_STRUCTURE: FolderStructure;
|
|
10
10
|
export type TmpMeta = {
|
|
@@ -17,19 +17,26 @@ export type TmpMeta = {
|
|
|
17
17
|
pathsRoot?: string;
|
|
18
18
|
folderStructure: FolderStructure;
|
|
19
19
|
};
|
|
20
|
+
export type WorkspaceSlot = keyof FolderStructure;
|
|
20
21
|
export type WorkspaceEntry = {
|
|
21
22
|
name: string;
|
|
22
23
|
type: GlobalTypeEnum.API_SERVICE | GlobalTypeEnum.FRONTEND;
|
|
23
24
|
path: string;
|
|
24
25
|
tmp: string;
|
|
25
|
-
slot:
|
|
26
|
+
slot: WorkspaceSlot;
|
|
26
27
|
cluster?: string;
|
|
27
28
|
};
|
|
28
29
|
export declare function readTmpFile(filePath: string): TmpMeta;
|
|
29
30
|
export declare function parseFolderStructure(text: string): FolderStructure;
|
|
31
|
+
type DiscoverySlot = {
|
|
32
|
+
slot: WorkspaceSlot;
|
|
33
|
+
folder: string;
|
|
34
|
+
frontendOnly: boolean;
|
|
35
|
+
};
|
|
36
|
+
export declare function workspaceDiscoverySlots(fsMap: FolderStructure): DiscoverySlot[];
|
|
30
37
|
export { normalizeGlobalType } from '../../../utils/helpers/tmp/tmp-schema';
|
|
31
38
|
export declare function entryName(meta: TmpMeta): string | null;
|
|
32
|
-
export declare function entryType(meta: TmpMeta, slot:
|
|
39
|
+
export declare function entryType(meta: TmpMeta, slot: WorkspaceSlot): GlobalTypeEnum | null;
|
|
33
40
|
export declare function findWorkspaceRoot(startDir?: string): string | null;
|
|
34
41
|
export declare function findEntries(workspaceRoot: string): WorkspaceEntry[];
|
|
35
42
|
export declare function findApiServices(workspaceRoot: string): WorkspaceEntry[];
|
|
@@ -6,8 +6,8 @@ export const TMP_FILE = 'tmp.yml';
|
|
|
6
6
|
export const SKIP_DIRS = new Set(['node_modules', '.git', 'dist', '.turbo', 'coverage']);
|
|
7
7
|
export const DEFAULT_FOLDER_STRUCTURE = {
|
|
8
8
|
api: 'api',
|
|
9
|
-
admin: 'admin',
|
|
10
9
|
web: 'web',
|
|
10
|
+
mobile: 'mobile',
|
|
11
11
|
};
|
|
12
12
|
function parseScalar(raw) {
|
|
13
13
|
const trimmed = raw.trim();
|
|
@@ -43,18 +43,28 @@ export function readTmpFile(filePath) {
|
|
|
43
43
|
}
|
|
44
44
|
export function parseFolderStructure(text) {
|
|
45
45
|
const fsBlock = text.match(/folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1] ?? '';
|
|
46
|
+
if (/^[ \t]+admin:/m.test(fsBlock)) {
|
|
47
|
+
throw new Error('configs.folder-structure.admin removed — put admin panels under web/ (e.g. web/admin-ui)');
|
|
48
|
+
}
|
|
46
49
|
const readSlot = (key) => {
|
|
47
|
-
const scalar = fsBlock.match(new RegExp(`^[ \t]+${key}
|
|
50
|
+
const scalar = fsBlock.match(new RegExp(`^[ \t]+${key}:\\s*(.+?)(?:\\s+#.*)?$`, 'm'));
|
|
48
51
|
if (scalar)
|
|
49
52
|
return parseScalar(scalar[1]);
|
|
50
53
|
return DEFAULT_FOLDER_STRUCTURE[key];
|
|
51
54
|
};
|
|
52
55
|
return {
|
|
53
56
|
api: readSlot('api'),
|
|
54
|
-
admin: readSlot('admin'),
|
|
55
57
|
web: readSlot('web'),
|
|
58
|
+
mobile: readSlot('mobile'),
|
|
56
59
|
};
|
|
57
60
|
}
|
|
61
|
+
export function workspaceDiscoverySlots(fsMap) {
|
|
62
|
+
return [
|
|
63
|
+
{ slot: 'api', folder: fsMap.api, frontendOnly: false },
|
|
64
|
+
{ slot: 'web', folder: fsMap.web, frontendOnly: true },
|
|
65
|
+
{ slot: 'mobile', folder: fsMap.mobile, frontendOnly: true },
|
|
66
|
+
];
|
|
67
|
+
}
|
|
58
68
|
export { normalizeGlobalType } from '../../../utils/helpers/tmp/tmp-schema.js';
|
|
59
69
|
export function entryName(meta) {
|
|
60
70
|
const project = (meta.projectName ?? '').trim();
|
|
@@ -149,9 +159,8 @@ export function findEntries(workspaceRoot) {
|
|
|
149
159
|
const fsMap = wsMeta.folderStructure;
|
|
150
160
|
const entries = [];
|
|
151
161
|
const seen = new Set();
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
const folder = path.join(workspaceRoot, fsMap[slot]);
|
|
162
|
+
for (const { slot, folder: folderRel, frontendOnly } of workspaceDiscoverySlots(fsMap)) {
|
|
163
|
+
const folder = path.join(workspaceRoot, folderRel);
|
|
155
164
|
for (const tmpPath of walkTmpUnder(folder)) {
|
|
156
165
|
if (path.resolve(tmpPath) === path.join(workspaceRoot, TMP_FILE))
|
|
157
166
|
continue;
|
|
@@ -159,7 +168,7 @@ export function findEntries(workspaceRoot) {
|
|
|
159
168
|
const kind = entryType(meta, slot);
|
|
160
169
|
if (kind === GlobalTypeEnum.WORKSPACE)
|
|
161
170
|
continue;
|
|
162
|
-
if (
|
|
171
|
+
if (frontendOnly && kind !== GlobalTypeEnum.FRONTEND)
|
|
163
172
|
continue;
|
|
164
173
|
if (kind !== GlobalTypeEnum.API_SERVICE && kind !== GlobalTypeEnum.FRONTEND)
|
|
165
174
|
continue;
|
|
@@ -207,17 +216,10 @@ export function workspaceTmpTemplate(projectName) {
|
|
|
207
216
|
configs:
|
|
208
217
|
global:
|
|
209
218
|
type: workspace
|
|
210
|
-
runtime: bun
|
|
211
|
-
framework: bun
|
|
212
|
-
paths:
|
|
213
|
-
root: .
|
|
214
|
-
tmp: tmp.yml
|
|
215
|
-
options:
|
|
216
|
-
fileWatchIntervalMs: 500
|
|
217
219
|
folder-structure:
|
|
218
220
|
api: api
|
|
219
|
-
admin: admin
|
|
220
221
|
web: web
|
|
222
|
+
mobile: mobile
|
|
221
223
|
|
|
222
224
|
kubeconfig: ~/.kube/config
|
|
223
225
|
|