@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 +1 -1
- package/x/bin/commands/create.mjs +35 -5
- package/x/bin/commands/sync.mjs +65 -99
- package/x/bin/commands/tmp.mjs +3 -0
- 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 +35 -13
- package/x/bin/helpers/create-target.mjs +49 -5
- package/x/bin/helpers/project-context.mjs +10 -7
- package/x/bin/helpers/sync-project.mjs +76 -0
- package/x/bin/helpers/sync-scope.mjs +71 -0
- package/x/bin/helpers/tmp-config.mjs +25 -0
- package/x/bin/helpers/workspace-resolve.mjs +2 -0
- package/x/dist/loader/kafka/index.js +7 -2
- package/x/dist/loader/logger/index.js +8 -6
- package/x/dist/loader/mongo/index.js +9 -0
- package/x/dist/loader/redis/index.js +9 -0
- package/x/dist/project/index.d.ts +1 -0
- package/x/dist/project/index.js +21 -14
- package/x/dist/utils/helpers/loader-options/index.d.ts +5 -0
- package/x/dist/utils/helpers/loader-options/index.js +16 -0
- package/x/dist/utils/helpers/tmp/index.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/index.js +1 -0
- package/x/dist/utils/helpers/tmp/loader-boot-plan.d.ts +10 -0
- package/x/dist/utils/helpers/tmp/loader-boot-plan.js +36 -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/x/templates/api-service/tmp.yml +6 -0
- package/x/templates/frontend/tmp.yml +61 -0
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,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|
|
|
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 {
|
|
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
|
-
;({
|
|
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
|
@@ -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 {
|
|
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
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
console.
|
|
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
|
-
|
|
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)
|
|
38
|
+
if (wsSchema.patched) {
|
|
39
|
+
console.log(chalk.green(` outer tmp end.version → ${wsSchema.schemaVersion} (schema)`))
|
|
40
|
+
}
|
|
33
41
|
}
|
|
42
|
+
}
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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(
|
|
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
|
-
|
|
97
|
-
|
|
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 (
|
|
109
|
-
|
|
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
|
-
|
|
87
|
+
process.exit(1)
|
|
117
88
|
}
|
|
118
89
|
|
|
119
|
-
|
|
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
|
|
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
|
|
package/x/bin/commands/tmp.mjs
CHANGED
|
@@ -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
|
|
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,
|
|
@@ -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
|
|
11
|
-
{ cmd: '
|
|
12
|
-
{ cmd: '
|
|
13
|
-
{ cmd: '
|
|
14
|
-
{ cmd: '
|
|
15
|
-
{ cmd: '
|
|
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
|
|
40
|
-
{ cmd: 'sync', desc: '
|
|
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: '
|
|
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 +
|
|
145
|
-
{ cmd: `${cliName} create my-api`, desc: '→ ./my-api (
|
|
146
|
-
{ cmd: `${cliName} create my-api ..`, desc: '→ ../my-api' },
|
|
147
|
-
{ 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' },
|
|
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
|
-
|
|
34
|
-
return { targetPath, isCurrentDir, label: isCurrentDir ? targetPath : targetPath }
|
|
77
|
+
export function formatCreateTargetPreview(projectName, targetDir, options = {}) {
|
|
78
|
+
return resolveCreateTarget(projectName, targetDir, options)
|
|
35
79
|
}
|