@xrystal/core 3.52.5 → 3.52.6
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 +8 -2
- package/package.json +1 -1
- package/x/bin/commands/create.mjs +1 -3
- package/x/bin/commands/project-info.mjs +94 -0
- package/x/bin/commands/projects.mjs +1 -1
- package/x/bin/commands/sync.mjs +9 -9
- package/x/bin/commands/tmp.mjs +9 -9
- package/x/bin/helpers/.generated/seed-from-tmp.mjs +1 -0
- package/x/bin/helpers/.generated/tmp-schema.mjs +1 -0
- package/x/bin/helpers/.generated/workspace.mjs +3 -2
- package/x/bin/helpers/.generated/xrystal-home-registry.mjs +192 -44
- package/x/bin/helpers/cli-help.mjs +22 -13
- package/x/bin/helpers/project-context.mjs +144 -0
- package/x/bin/helpers/scaffold-service.mjs +2 -3
- package/x/bin/helpers/tmp-layout.mjs +2 -3
- package/x/bin/helpers/tmp-schema-version.mjs +46 -0
- package/x/bin/helpers/workspace-scaffold.mjs +4 -9
- package/x/bin/main-cli.js +10 -1
- package/x/dist/utils/constants/defaults.json +1 -0
- package/x/dist/utils/helpers/workspace/index.d.ts +1 -1
- package/x/dist/utils/helpers/workspace/index.js +2 -2
- package/x/templates/api-service/tmp.yml +1 -1
- package/x/tmp.yml +1 -1
- package/x/bin/helpers/tmp-end-version.mjs +0 -35
package/README.md
CHANGED
|
@@ -253,13 +253,19 @@ bun run dev
|
|
|
253
253
|
| Command / Komut | EN | TR |
|
|
254
254
|
|-----------------|----|----|
|
|
255
255
|
| `xry create [name] [path]` | Start project from template + `tmp.yml` | Template + `tmp.yml` ile proje başlat |
|
|
256
|
-
| `xry
|
|
257
|
-
| `xry
|
|
256
|
+
| `xry project` | **Context**: workspace root, inner service, standalone, or core library | **Bağlam**: workspace / servis / core |
|
|
257
|
+
| `xry workspaces` | **Global registry** `~/.xrystal` (not tmp.yml) | Global kayıt defteri |
|
|
258
|
+
| `xry create <name> --workspace` | Outer `./tmp.yml` + **api/general** + admin/web | Dış tmp + api/general |
|
|
259
|
+
| `xry tmp` | Inner `x/tmp.yml` or outer workspace tmp; **`end.version` = schema (1)** | tmp.yml · şema sürümü |
|
|
260
|
+
| `xry sync` | Inner tsconfig + pin `@xrystal/core` + registry (workspace mode) | tsconfig + core pin |
|
|
261
|
+
| `xry tp connect` / `xry tp dev <deploy>` | Telepresence cluster connect / local intercept | Telepresence bağlan / local intercept |
|
|
262
|
+
| `xry workspaces` | List `~/.xrystal` workspaces + linked projects | Kayıtlı workspace listesi |
|
|
258
263
|
| `xry dev` | Watch `source/index.ts` + dev env | `source/index.ts` watch + dev env |
|
|
259
264
|
| `xry build` | `tsc` full tree → dist (auto default) + alias/fix post-steps | `tsc` ile tüm `source/` → dist |
|
|
260
265
|
| `xry start` | Run `x/dist` + prod env | `x/dist` + prod env |
|
|
261
266
|
| `xry test` | Run `x/tests` | `x/tests` çalıştır |
|
|
262
267
|
| `xry doctor` | CLI, runtime, package health | CLI, runtime, paket uyumu |
|
|
268
|
+
| `xry tag` | Core release: tag + npm publish | Core release tag + npm |
|
|
263
269
|
|
|
264
270
|
---
|
|
265
271
|
|
package/package.json
CHANGED
|
@@ -61,14 +61,12 @@ export function registerCreateCommand(cli, { cliName = CLI_PRIMARY_NAME, runtime
|
|
|
61
61
|
const version = readCliPackageJson().version
|
|
62
62
|
printCommandHeader({ cliName, command: 'create (workspace)', version })
|
|
63
63
|
const result = scaffoldWorkspace(targetPath, name, {
|
|
64
|
-
coreVersion: version,
|
|
65
64
|
installCommand,
|
|
66
65
|
cliName,
|
|
67
66
|
})
|
|
68
67
|
console.log(chalk.green('\n✓ Workspace ready\n'))
|
|
69
68
|
console.log(chalk.gray(` tmp: ${path.relative(process.cwd(), result.tmpPath) || result.tmpPath}`))
|
|
70
|
-
console.log(chalk.gray(
|
|
71
|
-
console.log(chalk.gray(' folders: api/, admin/, web/'))
|
|
69
|
+
console.log(chalk.gray(' outer tmp: ./tmp.yml (workspace) · inner: each api|admin|web project'))
|
|
72
70
|
if (result.general) {
|
|
73
71
|
console.log(chalk.green(' api/general: monolith scaffold (gpt template)'))
|
|
74
72
|
console.log(chalk.gray(` tmp: ${path.relative(process.cwd(), result.general.tmpFilePath) || result.general.tmpFilePath}`))
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
|
|
3
|
+
import { printCommandFooter, printCommandHeader } from '../helpers/banner.mjs'
|
|
4
|
+
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
5
|
+
import { packageDefaults } from '../helpers/package-defaults.mjs'
|
|
6
|
+
import { resolveProjectContext } from '../helpers/project-context.mjs'
|
|
7
|
+
import { readCliPackageJson } from '../helpers/project-root.mjs'
|
|
8
|
+
import { ensureTmpSchemaVersion } from '../helpers/tmp-schema-version.mjs'
|
|
9
|
+
|
|
10
|
+
function line(label, value) {
|
|
11
|
+
console.log(` ${label.padEnd(20)}${value}`)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function printTmpLayer(title, meta, schemaExpected, { heal = false } = {}) {
|
|
15
|
+
if (!meta?.path) return
|
|
16
|
+
console.log(chalk.bold.cyan(`\n ${title}`))
|
|
17
|
+
line('path', chalk.gray(meta.path))
|
|
18
|
+
if (meta.projectName) line('project.name', chalk.bold(meta.projectName))
|
|
19
|
+
if (meta.globalType) line('global.type', meta.globalType)
|
|
20
|
+
if (meta.schemaVersion != null) {
|
|
21
|
+
const ok = String(meta.schemaVersion) === String(schemaExpected)
|
|
22
|
+
line('end.version', ok ? chalk.green(`${meta.schemaVersion} (schema)`) : chalk.yellow(`${meta.schemaVersion} (expected schema ${schemaExpected})`))
|
|
23
|
+
}
|
|
24
|
+
if (heal) ensureTmpSchemaVersion(meta.path)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function registerProjectInfoCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
28
|
+
cli
|
|
29
|
+
.command('project')
|
|
30
|
+
.description('Show workspace / service context for current directory')
|
|
31
|
+
.option('--heal-schema', 'Fix tmp.yml end.version if missing or mistaken core semver')
|
|
32
|
+
.action((options) => {
|
|
33
|
+
const version = readCliPackageJson().version
|
|
34
|
+
printCommandHeader({ cliName, command: 'project', version })
|
|
35
|
+
|
|
36
|
+
const ctx = resolveProjectContext()
|
|
37
|
+
console.log(chalk.bold.white(`\n ${ctx.label}`))
|
|
38
|
+
line('cwd', ctx.cwd)
|
|
39
|
+
line('scope', ctx.kind)
|
|
40
|
+
if (ctx.projectRoot !== ctx.cwd) line('project root', ctx.projectRoot)
|
|
41
|
+
if (ctx.workspaceRoot) line('workspace root', ctx.workspaceRoot)
|
|
42
|
+
|
|
43
|
+
if (ctx.package) {
|
|
44
|
+
console.log(chalk.bold.cyan('\n Package'))
|
|
45
|
+
line('name', chalk.bold(ctx.package.name))
|
|
46
|
+
line('version', ctx.package.version ?? '—')
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log(chalk.bold.cyan('\n @xrystal/core (global library)'))
|
|
50
|
+
line('CLI (this xry)', chalk.bold(`v${ctx.core.cli}`))
|
|
51
|
+
if (ctx.core.declared) line('declared', ctx.core.declared)
|
|
52
|
+
if (ctx.core.installed) {
|
|
53
|
+
const match = ctx.core.installed === ctx.core.cli
|
|
54
|
+
line('installed', `${ctx.core.installed} ${match ? chalk.green('(matches CLI)') : chalk.yellow('(drift)')}`)
|
|
55
|
+
} else if (!ctx.core.isGlobalLibrary) {
|
|
56
|
+
line('installed', chalk.yellow('not in node_modules'))
|
|
57
|
+
}
|
|
58
|
+
if (ctx.core.isGlobalLibrary) {
|
|
59
|
+
line('role', chalk.green('library source — npm package for all services/workspaces'))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (ctx.outerTmp) {
|
|
63
|
+
printTmpLayer('Outer tmp (workspace)', ctx.outerTmp, ctx.schemaVersionExpected, { heal: options.healSchema })
|
|
64
|
+
}
|
|
65
|
+
if (ctx.innerTmp) {
|
|
66
|
+
printTmpLayer('Inner tmp (project)', ctx.innerTmp, ctx.schemaVersionExpected, { heal: options.healSchema })
|
|
67
|
+
} else if (!ctx.outerTmp) {
|
|
68
|
+
console.log(chalk.yellow('\n No tmp.yml found — run xry tmp'))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (ctx.selfEntry) {
|
|
72
|
+
console.log(chalk.bold.cyan('\n Workspace link'))
|
|
73
|
+
line('name', `${ctx.selfEntry.name} [${ctx.selfEntry.type}]`)
|
|
74
|
+
line('slot', ctx.selfEntry.slot)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (ctx.workspaceEntries.length > 0 && ctx.kind === 'workspace-root') {
|
|
78
|
+
console.log(chalk.bold.cyan(`\n Linked projects (${ctx.workspaceEntries.length})`))
|
|
79
|
+
for (const entry of ctx.workspaceEntries) {
|
|
80
|
+
console.log(` • ${chalk.white(entry.name)} [${entry.type}] ${chalk.gray(entry.path)}`)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (ctx.hints?.length) {
|
|
85
|
+
console.log(chalk.bold.cyan('\n Next'))
|
|
86
|
+
for (const hint of ctx.hints) {
|
|
87
|
+
console.log(` ${chalk.gray('→')} ${hint}`)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.log(chalk.dim(`\n Registry (all workspaces): ${cliName} workspaces · inner tmp: ${cliName} tmp`))
|
|
92
|
+
printCommandFooter({ version })
|
|
93
|
+
})
|
|
94
|
+
}
|
|
@@ -81,7 +81,7 @@ export function registerWorkspacesCommand(cli, { cliName = CLI_PRIMARY_NAME } =
|
|
|
81
81
|
attachRegistryCommand(
|
|
82
82
|
cli
|
|
83
83
|
.command('workspaces [action]')
|
|
84
|
-
.description('
|
|
84
|
+
.description('Global ~/.xrystal registry — workspaces & linked projects (not repo tmp.yml)'),
|
|
85
85
|
{ cliName, label: 'workspaces' },
|
|
86
86
|
)
|
|
87
87
|
}
|
package/x/bin/commands/sync.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
|
6
6
|
import { getProjectRoot, readCliPackageJson } from '../helpers/project-root.mjs'
|
|
7
7
|
import { auditTsconfigAlignment, syncProjectToolchain } from '../helpers/toolchain-config.mjs'
|
|
8
8
|
import { ensureTmpFile } from '../helpers/tmp-layout.mjs'
|
|
9
|
-
import {
|
|
9
|
+
import { ensureTmpSchemaVersion } from '../helpers/tmp-schema-version.mjs'
|
|
10
10
|
import { findEntries, findWorkspaceRoot } from '../helpers/workspace-resolve.mjs'
|
|
11
11
|
import { syncCliRuntime } from '../helpers/project-artifacts.mjs'
|
|
12
12
|
import { syncCoreDependency } from '../helpers/sync-core-dependency.mjs'
|
|
@@ -28,8 +28,8 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
28
28
|
|
|
29
29
|
const wsTmp = path.join(workspaceRoot, 'tmp.yml')
|
|
30
30
|
if (!options.dryRun) {
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
31
|
+
const wsSchema = ensureTmpSchemaVersion(wsTmp)
|
|
32
|
+
if (wsSchema.patched) console.log(chalk.green(` outer tmp end.version → ${wsSchema.schemaVersion} (schema)`))
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
if (entries.length === 0) {
|
|
@@ -69,8 +69,8 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
69
69
|
console.log(chalk.gray(` ${packageDefaults.packageName}@${coreVersion} (ok)`))
|
|
70
70
|
}
|
|
71
71
|
if (!options.dryRun) {
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
72
|
+
const schema = ensureTmpSchemaVersion(entry.tmp)
|
|
73
|
+
if (schema.patched) console.log(chalk.green(` inner tmp end.version → ${schema.schemaVersion} (schema)`))
|
|
74
74
|
}
|
|
75
75
|
} catch (error) {
|
|
76
76
|
failed += 1
|
|
@@ -116,10 +116,10 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
116
116
|
return
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
const result = syncProjectToolchain(root, { write: true })
|
|
120
119
|
const layout = ensureTmpFile(root)
|
|
121
|
-
const
|
|
122
|
-
|
|
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
123
|
console.log(result.created
|
|
124
124
|
? chalk.green(` created ${result.tsconfigRel}`)
|
|
125
125
|
: chalk.green(` updated ${result.tsconfigRel}`))
|
|
@@ -132,7 +132,7 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
132
132
|
cli
|
|
133
133
|
.command('sync')
|
|
134
134
|
.alias('sync-toolchain')
|
|
135
|
-
.description('Sync
|
|
135
|
+
.description('Sync tsconfig + @xrystal/core pin (workspace: all inner tmp projects + ~/.xrystal registry)')
|
|
136
136
|
.option('--dry-run', 'Preview without writing')
|
|
137
137
|
.action(run)
|
|
138
138
|
}
|
package/x/bin/commands/tmp.mjs
CHANGED
|
@@ -14,12 +14,12 @@ import {
|
|
|
14
14
|
} from '../helpers/tmp-layout.mjs'
|
|
15
15
|
import { formatLoaderSummary, summarizeLoaders } from '../helpers/tmp-config.mjs'
|
|
16
16
|
import { packageDefaults } from '../helpers/package-defaults.mjs'
|
|
17
|
-
import {
|
|
17
|
+
import { ensureTmpSchemaVersion, readTmpSchemaVersion } from '../helpers/tmp-schema-version.mjs'
|
|
18
18
|
|
|
19
19
|
export function registerTmpCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
20
20
|
cli
|
|
21
21
|
.command('tmp')
|
|
22
|
-
.description(`Ensure tmp.yml exists (seed from ${packageDefaults.packageName})`)
|
|
22
|
+
.description(`Ensure inner/outer tmp.yml exists (seed from ${packageDefaults.packageName})`)
|
|
23
23
|
.option('--dry-run', 'Show target path without writing')
|
|
24
24
|
.action((options) => {
|
|
25
25
|
const root = getProjectRoot()
|
|
@@ -39,17 +39,17 @@ export function registerTmpCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
39
39
|
|
|
40
40
|
const result = ensureTmpFile(root)
|
|
41
41
|
const rel = relativeFromRoot(root, result.tmpFilePath)
|
|
42
|
-
const
|
|
42
|
+
const schema = ensureTmpSchemaVersion(result.tmpFilePath)
|
|
43
43
|
|
|
44
44
|
printCommandHeader({ cliName, command: 'tmp', version })
|
|
45
45
|
console.log(chalk.gray(` root: ${root}`))
|
|
46
46
|
console.log(result.created ? chalk.green(` created ${rel}`) : chalk.gray(` ok ${rel}`))
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
49
|
-
const
|
|
50
|
-
? chalk.green(` end.version → ${
|
|
51
|
-
: chalk.gray(` end.version: ${
|
|
52
|
-
console.log(
|
|
47
|
+
const schemaVersion = readTmpSchemaVersion(result.tmpFilePath)
|
|
48
|
+
if (schemaVersion) {
|
|
49
|
+
const schemaLabel = schema.patched
|
|
50
|
+
? chalk.green(` end.version → ${schemaVersion} (schema)`)
|
|
51
|
+
: chalk.gray(` end.version: ${schemaVersion} (schema)`)
|
|
52
|
+
console.log(schemaLabel)
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
try {
|
|
@@ -14,6 +14,7 @@ var defaults_default = {
|
|
|
14
14
|
cliBinFile: "main-cli.js",
|
|
15
15
|
tmpBaseName: "tmp",
|
|
16
16
|
tmpExtension: ".yml",
|
|
17
|
+
tmpSchemaVersion: 1,
|
|
17
18
|
apiServiceTemplateRel: "x/templates/api-service/tmp.yml",
|
|
18
19
|
templateRepoUri: "https://github.com/xdloper/api-gpt-svc",
|
|
19
20
|
publicFolderName: "public",
|
|
@@ -9,6 +9,7 @@ var defaults_default = {
|
|
|
9
9
|
cliBinFile: "main-cli.js",
|
|
10
10
|
tmpBaseName: "tmp",
|
|
11
11
|
tmpExtension: ".yml",
|
|
12
|
+
tmpSchemaVersion: 1,
|
|
12
13
|
apiServiceTemplateRel: "x/templates/api-service/tmp.yml",
|
|
13
14
|
templateRepoUri: "https://github.com/xdloper/api-gpt-svc",
|
|
14
15
|
publicFolderName: "public",
|
|
@@ -20,6 +20,7 @@ var defaults_default = {
|
|
|
20
20
|
cliBinFile: "main-cli.js",
|
|
21
21
|
tmpBaseName: "tmp",
|
|
22
22
|
tmpExtension: ".yml",
|
|
23
|
+
tmpSchemaVersion: 1,
|
|
23
24
|
apiServiceTemplateRel: "x/templates/api-service/tmp.yml",
|
|
24
25
|
templateRepoUri: "https://github.com/xdloper/api-gpt-svc",
|
|
25
26
|
publicFolderName: "public",
|
|
@@ -362,7 +363,7 @@ function readWorkspaceGlobalTmp(workspaceRoot) {
|
|
|
362
363
|
return match ? { fileWatchIntervalMs: Number(match[1]) } : {};
|
|
363
364
|
}
|
|
364
365
|
var readWorkspaceCoreTmp = readWorkspaceGlobalTmp;
|
|
365
|
-
function workspaceTmpTemplate(projectName
|
|
366
|
+
function workspaceTmpTemplate(projectName) {
|
|
366
367
|
return `project:
|
|
367
368
|
name: ${projectName}
|
|
368
369
|
|
|
@@ -384,7 +385,7 @@ configs:
|
|
|
384
385
|
kubeconfig: ~/.kube/config
|
|
385
386
|
|
|
386
387
|
end:
|
|
387
|
-
version:
|
|
388
|
+
version: 1
|
|
388
389
|
`;
|
|
389
390
|
}
|
|
390
391
|
export {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// source/utils/helpers/xrystal-home/registry.ts
|
|
2
|
-
import
|
|
2
|
+
import fs3 from "node:fs";
|
|
3
3
|
import os from "node:os";
|
|
4
|
-
import
|
|
4
|
+
import path3 from "node:path";
|
|
5
5
|
|
|
6
6
|
// source/utils/helpers/workspace/index.ts
|
|
7
|
-
import
|
|
8
|
-
import
|
|
7
|
+
import fs2 from "node:fs";
|
|
8
|
+
import path2 from "node:path";
|
|
9
9
|
|
|
10
10
|
// source/utils/models/enums/index.ts
|
|
11
11
|
var GlobalTypeEnum;
|
|
@@ -14,6 +14,167 @@ var GlobalTypeEnum;
|
|
|
14
14
|
GlobalTypeEnum2["API_SERVICE"] = "api-service";
|
|
15
15
|
GlobalTypeEnum2["FRONTEND"] = "frontend";
|
|
16
16
|
})(GlobalTypeEnum ||= {});
|
|
17
|
+
// source/utils/constants/defaults.json
|
|
18
|
+
var defaults_default = {
|
|
19
|
+
packageName: "@xrystal/core",
|
|
20
|
+
packageRootFolder: "x",
|
|
21
|
+
cliName: "xry",
|
|
22
|
+
cliBinNames: [
|
|
23
|
+
"xry"
|
|
24
|
+
],
|
|
25
|
+
cliBinFile: "main-cli.js",
|
|
26
|
+
tmpBaseName: "tmp",
|
|
27
|
+
tmpExtension: ".yml",
|
|
28
|
+
tmpSchemaVersion: 1,
|
|
29
|
+
apiServiceTemplateRel: "x/templates/api-service/tmp.yml",
|
|
30
|
+
templateRepoUri: "https://github.com/xdloper/api-gpt-svc",
|
|
31
|
+
publicFolderName: "public",
|
|
32
|
+
kafkaLogsTopic: "log",
|
|
33
|
+
pathAliasKey: "@/*",
|
|
34
|
+
eslintRestrictedImportDepth: 2,
|
|
35
|
+
brand: {
|
|
36
|
+
primary: "xrystal",
|
|
37
|
+
secondary: "core",
|
|
38
|
+
tagline: "microservice runtime library",
|
|
39
|
+
capabilities: "loaders · tmp.yml · dto · i18n · multi-protocol · scaffold"
|
|
40
|
+
},
|
|
41
|
+
runtimes: {
|
|
42
|
+
bun: {
|
|
43
|
+
label: "Bun",
|
|
44
|
+
packageManager: "bun",
|
|
45
|
+
installCommand: "bun install",
|
|
46
|
+
scriptRunner: "bun run",
|
|
47
|
+
binRunner: "bun",
|
|
48
|
+
testRunner: "bun test",
|
|
49
|
+
tscBin: "bunx tsc",
|
|
50
|
+
esbuildBin: "bunx esbuild",
|
|
51
|
+
devInvoker: null
|
|
52
|
+
},
|
|
53
|
+
node: {
|
|
54
|
+
label: "Node.js",
|
|
55
|
+
packageManager: "npm",
|
|
56
|
+
installCommand: "npm install",
|
|
57
|
+
scriptRunner: "npm run",
|
|
58
|
+
binRunner: "node",
|
|
59
|
+
testRunner: "node --test",
|
|
60
|
+
tscBin: "npx tsc",
|
|
61
|
+
esbuildBin: "npx esbuild",
|
|
62
|
+
devInvoker: "npx"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
bundlers: [
|
|
66
|
+
"auto",
|
|
67
|
+
"bun",
|
|
68
|
+
"tsc",
|
|
69
|
+
"esbuild"
|
|
70
|
+
],
|
|
71
|
+
tmpWatchDefaults: {
|
|
72
|
+
intervalMs: 500,
|
|
73
|
+
minIntervalMs: 100,
|
|
74
|
+
maxIntervalMs: 1e4
|
|
75
|
+
},
|
|
76
|
+
buildDefaults: {
|
|
77
|
+
bundler: "auto",
|
|
78
|
+
tsconfig: "tsconfig.json",
|
|
79
|
+
typecheck: false,
|
|
80
|
+
tscLenient: true,
|
|
81
|
+
declarations: false,
|
|
82
|
+
sourcemap: false,
|
|
83
|
+
minify: false
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// source/utils/helpers/tmp/seed-from-tmp.ts
|
|
88
|
+
import fs from "node:fs";
|
|
89
|
+
import path from "node:path";
|
|
90
|
+
import { fileURLToPath } from "node:url";
|
|
91
|
+
import yaml from "yaml";
|
|
92
|
+
|
|
93
|
+
// source/utils/helpers/tmp/path-normalize.ts
|
|
94
|
+
function normalizeRootFolder(value, fallback) {
|
|
95
|
+
if (typeof value !== "string" || !value.trim())
|
|
96
|
+
return fallback;
|
|
97
|
+
return value.trim().replace(/^\.\/+/, "");
|
|
98
|
+
}
|
|
99
|
+
function normalizeSourceFolder(value, fallback) {
|
|
100
|
+
if (typeof value !== "string" || !value.trim())
|
|
101
|
+
return fallback;
|
|
102
|
+
const trimmed = value.trim();
|
|
103
|
+
if (trimmed.startsWith("./") || trimmed.startsWith("../"))
|
|
104
|
+
return trimmed;
|
|
105
|
+
return `./${trimmed}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// source/utils/helpers/tmp/seed-from-tmp.ts
|
|
109
|
+
var here = path.dirname(fileURLToPath(import.meta.url));
|
|
110
|
+
var templateRel = defaults_default.apiServiceTemplateRel ?? "x/templates/api-service/tmp.yml";
|
|
111
|
+
function requireString(value, label) {
|
|
112
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
113
|
+
throw new Error(`${defaults_default.packageName}: bundled template missing ${label}`);
|
|
114
|
+
}
|
|
115
|
+
return value.trim();
|
|
116
|
+
}
|
|
117
|
+
function readLayoutFromSpecial(special) {
|
|
118
|
+
const block = special && typeof special === "object" && !Array.isArray(special) ? special : {};
|
|
119
|
+
return {
|
|
120
|
+
tests: requireString(block.tests, "configs.global.paths.special.tests"),
|
|
121
|
+
environments: requireString(block.environments, "configs.global.paths.special.environments"),
|
|
122
|
+
dist: requireString(block.dist, "configs.global.paths.special.dist")
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function findApiTemplate() {
|
|
126
|
+
const starts = [here, process.cwd()].map((value) => path.resolve(value));
|
|
127
|
+
for (const start of starts) {
|
|
128
|
+
let dir = start;
|
|
129
|
+
for (;; ) {
|
|
130
|
+
const candidate = path.join(dir, templateRel);
|
|
131
|
+
if (fs.existsSync(candidate))
|
|
132
|
+
return candidate;
|
|
133
|
+
const parent = path.dirname(dir);
|
|
134
|
+
if (parent === dir)
|
|
135
|
+
break;
|
|
136
|
+
dir = parent;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
throw new Error(`${defaults_default.packageName}: api-service template not found (${templateRel})`);
|
|
140
|
+
}
|
|
141
|
+
function loadSeedFromBundledTmp(tmpFilePath) {
|
|
142
|
+
const file = tmpFilePath ?? findApiTemplate();
|
|
143
|
+
const doc = yaml.parse(fs.readFileSync(file, "utf8"));
|
|
144
|
+
const configs = doc?.configs && typeof doc.configs === "object" ? doc.configs : {};
|
|
145
|
+
const global = configs.global && typeof configs.global === "object" ? configs.global : {};
|
|
146
|
+
const paths = global.paths && typeof global.paths === "object" ? global.paths : {};
|
|
147
|
+
const special = paths.special;
|
|
148
|
+
const root = requireString(paths.root, "configs.global.paths.root");
|
|
149
|
+
const rootNorm = normalizeRootFolder(root, defaults_default.packageRootFolder).replace(/^\.\//, "");
|
|
150
|
+
const tmpName = typeof paths.tmp === "string" && paths.tmp.trim() ? paths.tmp.trim().replace(/^\.\//, "") : "tmp.yml";
|
|
151
|
+
const sourceRaw = requireString(paths.source, "configs.global.paths.source");
|
|
152
|
+
return {
|
|
153
|
+
rootFolder: rootNorm,
|
|
154
|
+
sourceFolder: normalizeSourceFolder(sourceRaw, sourceRaw),
|
|
155
|
+
framework: requireString(global.framework, "configs.global.framework"),
|
|
156
|
+
layout: readLayoutFromSpecial(special),
|
|
157
|
+
tmpRelPath: `${rootNorm}/${tmpName}`.replace(/\/+/g, "/")
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
var seedFromTmp = loadSeedFromBundledTmp();
|
|
161
|
+
|
|
162
|
+
// source/utils/helpers/tmp/tmp-interpolate.ts
|
|
163
|
+
import Handlebars from "handlebars";
|
|
164
|
+
|
|
165
|
+
// source/utils/helpers/tmp/tmp-schema.ts
|
|
166
|
+
function normalizeGlobalType(value) {
|
|
167
|
+
if (value === undefined || value === null || value === "")
|
|
168
|
+
return;
|
|
169
|
+
const raw = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
170
|
+
if (raw === "workspace" /* WORKSPACE */)
|
|
171
|
+
return "workspace" /* WORKSPACE */;
|
|
172
|
+
if (raw === "api-service" /* API_SERVICE */)
|
|
173
|
+
return "api-service" /* API_SERVICE */;
|
|
174
|
+
if (raw === "frontend" /* FRONTEND */)
|
|
175
|
+
return "frontend" /* FRONTEND */;
|
|
176
|
+
throw new Error(`${defaults_default.packageName}: configs.global.type must be one of ${Object.values(GlobalTypeEnum).join("|")} (got "${String(value)}")`);
|
|
177
|
+
}
|
|
17
178
|
|
|
18
179
|
// source/utils/helpers/workspace/index.ts
|
|
19
180
|
var TMP_FILE = "tmp.yml";
|
|
@@ -31,7 +192,7 @@ function parseScalar(raw) {
|
|
|
31
192
|
return trimmed;
|
|
32
193
|
}
|
|
33
194
|
function readTmpFile(filePath) {
|
|
34
|
-
const text =
|
|
195
|
+
const text = fs2.readFileSync(filePath, "utf8");
|
|
35
196
|
const out = { path: filePath, folderStructure: { ...DEFAULT_FOLDER_STRUCTURE } };
|
|
36
197
|
const projectMatch = text.match(/^project:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+name:\s*(.+?)\s*(?:#.*)?$/m) ?? text.match(/^project:\s*\n[ \t]+name:\s*(.+?)\s*(?:#.*)?$/m);
|
|
37
198
|
if (projectMatch)
|
|
@@ -48,10 +209,7 @@ function readTmpFile(filePath) {
|
|
|
48
209
|
const tmpBlock = text.match(/paths:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+tmp:\s*(.+?)\s*(?:#.*)?$/m);
|
|
49
210
|
if (tmpBlock)
|
|
50
211
|
out.pathsTmp = parseScalar(tmpBlock[1]);
|
|
51
|
-
|
|
52
|
-
if (clusterBlock)
|
|
53
|
-
out.clusterDeployment = parseScalar(clusterBlock[1]);
|
|
54
|
-
else if (out.projectName)
|
|
212
|
+
if (out.projectName)
|
|
55
213
|
out.clusterDeployment = out.projectName;
|
|
56
214
|
out.folderStructure = parseFolderStructure(text);
|
|
57
215
|
return out;
|
|
@@ -70,16 +228,6 @@ function parseFolderStructure(text) {
|
|
|
70
228
|
web: readSlot("web")
|
|
71
229
|
};
|
|
72
230
|
}
|
|
73
|
-
function normalizeGlobalType(value) {
|
|
74
|
-
const raw = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
75
|
-
if (raw === "workspace" /* WORKSPACE */)
|
|
76
|
-
return "workspace" /* WORKSPACE */;
|
|
77
|
-
if (raw === "api-service" /* API_SERVICE */)
|
|
78
|
-
return "api-service" /* API_SERVICE */;
|
|
79
|
-
if (raw === "frontend" /* FRONTEND */)
|
|
80
|
-
return "frontend" /* FRONTEND */;
|
|
81
|
-
throw new Error(`@xrystal/core: configs.global.type must be one of ${Object.values(GlobalTypeEnum).join("|")} (got "${String(value)}")`);
|
|
82
|
-
}
|
|
83
231
|
function entryName(meta) {
|
|
84
232
|
const project = (meta.projectName ?? "").trim();
|
|
85
233
|
return project || null;
|
|
@@ -88,7 +236,7 @@ function entryType(meta, slot) {
|
|
|
88
236
|
const explicit = (meta.globalType ?? "").trim();
|
|
89
237
|
if (explicit) {
|
|
90
238
|
try {
|
|
91
|
-
return normalizeGlobalType(explicit);
|
|
239
|
+
return normalizeGlobalType(explicit) ?? null;
|
|
92
240
|
} catch {
|
|
93
241
|
return null;
|
|
94
242
|
}
|
|
@@ -98,15 +246,15 @@ function entryType(meta, slot) {
|
|
|
98
246
|
return null;
|
|
99
247
|
}
|
|
100
248
|
function findWorkspaceRoot(startDir = process.cwd()) {
|
|
101
|
-
let cur =
|
|
249
|
+
let cur = path2.resolve(startDir);
|
|
102
250
|
for (;; ) {
|
|
103
|
-
const candidate =
|
|
104
|
-
if (
|
|
251
|
+
const candidate = path2.join(cur, TMP_FILE);
|
|
252
|
+
if (fs2.existsSync(candidate)) {
|
|
105
253
|
const meta = readTmpFile(candidate);
|
|
106
254
|
if (meta.globalType === "workspace" /* WORKSPACE */)
|
|
107
255
|
return cur;
|
|
108
256
|
}
|
|
109
|
-
const parent =
|
|
257
|
+
const parent = path2.dirname(cur);
|
|
110
258
|
if (parent === cur)
|
|
111
259
|
break;
|
|
112
260
|
cur = parent;
|
|
@@ -118,7 +266,7 @@ function isTraversableDir(entry, fullPath) {
|
|
|
118
266
|
return true;
|
|
119
267
|
if (entry.isSymbolicLink()) {
|
|
120
268
|
try {
|
|
121
|
-
return
|
|
269
|
+
return fs2.statSync(fullPath).isDirectory();
|
|
122
270
|
} catch {
|
|
123
271
|
return false;
|
|
124
272
|
}
|
|
@@ -127,19 +275,19 @@ function isTraversableDir(entry, fullPath) {
|
|
|
127
275
|
}
|
|
128
276
|
function walkTmpUnder(rootDir) {
|
|
129
277
|
const found = [];
|
|
130
|
-
if (!
|
|
278
|
+
if (!fs2.existsSync(rootDir))
|
|
131
279
|
return found;
|
|
132
280
|
const stack = [rootDir];
|
|
133
281
|
while (stack.length) {
|
|
134
282
|
const dir = stack.pop();
|
|
135
283
|
let entries;
|
|
136
284
|
try {
|
|
137
|
-
entries =
|
|
285
|
+
entries = fs2.readdirSync(dir, { withFileTypes: true });
|
|
138
286
|
} catch {
|
|
139
287
|
continue;
|
|
140
288
|
}
|
|
141
289
|
for (const entry of entries) {
|
|
142
|
-
const full =
|
|
290
|
+
const full = path2.join(dir, entry.name);
|
|
143
291
|
if (isTraversableDir(entry, full)) {
|
|
144
292
|
if (SKIP_DIRS.has(entry.name) || entry.name.startsWith("."))
|
|
145
293
|
continue;
|
|
@@ -166,15 +314,15 @@ function repoRootFromTmp(tmpPath, meta) {
|
|
|
166
314
|
throw new Error(`tmp path mismatch: expected */${rel}, got ${abs}`);
|
|
167
315
|
}
|
|
168
316
|
function findEntries(workspaceRoot) {
|
|
169
|
-
const wsMeta = readTmpFile(
|
|
317
|
+
const wsMeta = readTmpFile(path2.join(workspaceRoot, TMP_FILE));
|
|
170
318
|
const fsMap = wsMeta.folderStructure;
|
|
171
319
|
const entries = [];
|
|
172
320
|
const seen = new Set;
|
|
173
321
|
const slots = ["api", "admin", "web"];
|
|
174
322
|
for (const slot of slots) {
|
|
175
|
-
const folder =
|
|
323
|
+
const folder = path2.join(workspaceRoot, fsMap[slot]);
|
|
176
324
|
for (const tmpPath of walkTmpUnder(folder)) {
|
|
177
|
-
if (
|
|
325
|
+
if (path2.resolve(tmpPath) === path2.join(workspaceRoot, TMP_FILE))
|
|
178
326
|
continue;
|
|
179
327
|
const meta = readTmpFile(tmpPath);
|
|
180
328
|
const kind = entryType(meta, slot);
|
|
@@ -207,14 +355,14 @@ function findEntries(workspaceRoot) {
|
|
|
207
355
|
// source/utils/helpers/xrystal-home/registry.ts
|
|
208
356
|
var XRYSTAL_HOME_DIR = ".xrystal";
|
|
209
357
|
function resolveXrystalHome() {
|
|
210
|
-
return
|
|
358
|
+
return path3.join(os.homedir(), XRYSTAL_HOME_DIR);
|
|
211
359
|
}
|
|
212
360
|
function registryFilePath() {
|
|
213
|
-
return
|
|
361
|
+
return path3.join(resolveXrystalHome(), "registry.json");
|
|
214
362
|
}
|
|
215
363
|
function ensureXrystalHome() {
|
|
216
364
|
const home = resolveXrystalHome();
|
|
217
|
-
|
|
365
|
+
fs3.mkdirSync(path3.join(home, "workspaces"), { recursive: true });
|
|
218
366
|
return home;
|
|
219
367
|
}
|
|
220
368
|
function entryToRegistryProject(entry) {
|
|
@@ -227,9 +375,9 @@ function entryToRegistryProject(entry) {
|
|
|
227
375
|
};
|
|
228
376
|
}
|
|
229
377
|
function normalizeRegistryPath(input) {
|
|
230
|
-
const resolved =
|
|
378
|
+
const resolved = path3.resolve(input);
|
|
231
379
|
try {
|
|
232
|
-
return
|
|
380
|
+
return fs3.realpathSync.native(resolved);
|
|
233
381
|
} catch {
|
|
234
382
|
return resolved;
|
|
235
383
|
}
|
|
@@ -237,7 +385,7 @@ function normalizeRegistryPath(input) {
|
|
|
237
385
|
function scanWorkspace(workspacePath, workspaceName) {
|
|
238
386
|
const root = normalizeRegistryPath(workspacePath);
|
|
239
387
|
const entries = findEntries(root);
|
|
240
|
-
const name = workspaceName ??
|
|
388
|
+
const name = workspaceName ?? path3.basename(root);
|
|
241
389
|
return {
|
|
242
390
|
name,
|
|
243
391
|
path: root,
|
|
@@ -248,23 +396,23 @@ function scanWorkspace(workspacePath, workspaceName) {
|
|
|
248
396
|
function readRegistry() {
|
|
249
397
|
ensureXrystalHome();
|
|
250
398
|
const file = registryFilePath();
|
|
251
|
-
if (!
|
|
399
|
+
if (!fs3.existsSync(file)) {
|
|
252
400
|
return { version: 1, updatedAt: new Date().toISOString(), workspaces: [] };
|
|
253
401
|
}
|
|
254
|
-
return JSON.parse(
|
|
402
|
+
return JSON.parse(fs3.readFileSync(file, "utf8"));
|
|
255
403
|
}
|
|
256
404
|
function writeRegistry(registry) {
|
|
257
405
|
ensureXrystalHome();
|
|
258
406
|
registry.updatedAt = new Date().toISOString();
|
|
259
|
-
|
|
407
|
+
fs3.writeFileSync(registryFilePath(), `${JSON.stringify(registry, null, 2)}
|
|
260
408
|
`);
|
|
261
409
|
for (const ws of registry.workspaces) {
|
|
262
|
-
const wsDir =
|
|
263
|
-
|
|
264
|
-
|
|
410
|
+
const wsDir = path3.join(resolveXrystalHome(), "workspaces", ws.name);
|
|
411
|
+
fs3.mkdirSync(wsDir, { recursive: true });
|
|
412
|
+
fs3.writeFileSync(path3.join(wsDir, "workspace.json"), `${JSON.stringify(ws, null, 2)}
|
|
265
413
|
`);
|
|
266
414
|
for (const project of ws.projects) {
|
|
267
|
-
|
|
415
|
+
fs3.writeFileSync(path3.join(wsDir, `${project.name}.json`), `${JSON.stringify(project, null, 2)}
|
|
268
416
|
`);
|
|
269
417
|
}
|
|
270
418
|
}
|
|
@@ -7,11 +7,13 @@ import { brandTitle } from './banner.mjs'
|
|
|
7
7
|
import { packageDefaults } from './package-defaults.mjs'
|
|
8
8
|
|
|
9
9
|
const QUICK_COMMANDS = [
|
|
10
|
-
{ cmd: '
|
|
11
|
-
{ cmd: '
|
|
12
|
-
{ cmd: '
|
|
13
|
-
{ cmd: '
|
|
14
|
-
{ cmd: '
|
|
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' },
|
|
16
|
+
{ cmd: 'dev / build / doctor', desc: 'Develop & diagnostics' },
|
|
15
17
|
]
|
|
16
18
|
|
|
17
19
|
const COMMAND_GROUPS = [
|
|
@@ -24,22 +26,27 @@ const COMMAND_GROUPS = [
|
|
|
24
26
|
{ cmd: 'test', desc: 'Run project tests (paths.tests)' },
|
|
25
27
|
],
|
|
26
28
|
},
|
|
29
|
+
{
|
|
30
|
+
title: 'Context',
|
|
31
|
+
items: [
|
|
32
|
+
{ cmd: 'project', desc: 'Current folder: workspace root, linked service, standalone, or core library' },
|
|
33
|
+
{ cmd: 'workspaces [list|sync]', desc: 'Global registry ~/.xrystal (external to repo tmp files)' },
|
|
34
|
+
],
|
|
35
|
+
},
|
|
27
36
|
{
|
|
28
37
|
title: 'Workspace',
|
|
29
38
|
items: [
|
|
30
|
-
{ cmd: 'create <name> --workspace', desc: '
|
|
31
|
-
{ cmd: 'sync', desc: '
|
|
32
|
-
{ cmd: 'telepresence dev <deploy>', aliases: 'tp dev', desc: 'Intercept cluster pod → local dev
|
|
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' },
|
|
41
|
+
{ cmd: 'telepresence dev <deploy>', aliases: 'tp dev', desc: 'Intercept cluster pod → local dev' },
|
|
33
42
|
{ cmd: 'telepresence connect', aliases: 'tp connect', desc: 'Connect Telepresence to dev/test namespace' },
|
|
34
|
-
{ cmd: 'workspaces [list|sync]', desc: 'List registered workspaces and linked projects' },
|
|
35
|
-
{ cmd: 'workspaces sync', aliases: 'projects sync', desc: 'Rescan cwd workspace into ~/.xrystal' },
|
|
36
43
|
],
|
|
37
44
|
},
|
|
38
45
|
{
|
|
39
46
|
title: 'Project',
|
|
40
47
|
items: [
|
|
41
|
-
{ cmd: 'create', hint: '<name> [path]', desc: '
|
|
42
|
-
{ cmd: 'tmp', desc: 'Ensure tmp.yml
|
|
48
|
+
{ 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)' },
|
|
43
50
|
{ cmd: 'hooks install', desc: 'Install .git/hooks pre-commit version check' },
|
|
44
51
|
{ cmd: 'hooks status', desc: 'Show whether pre-commit hook is installed' },
|
|
45
52
|
],
|
|
@@ -60,6 +67,7 @@ const COMMAND_GROUPS = [
|
|
|
60
67
|
]
|
|
61
68
|
|
|
62
69
|
const SECTION_COLORS = {
|
|
70
|
+
Context: chalk.bold.white,
|
|
63
71
|
Develop: chalk.bold.cyan,
|
|
64
72
|
Workspace: chalk.bold.blue,
|
|
65
73
|
Project: chalk.bold.green,
|
|
@@ -92,6 +100,7 @@ export function printQuickStartGuide({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
92
100
|
console.log('')
|
|
93
101
|
console.log(` ${chalk.dim('tip')} ${chalk.bold.white(`${cliName} -h`)} ${chalk.gray('· all commands & options')}`)
|
|
94
102
|
console.log(` ${chalk.dim('tip')} ${chalk.bold.white(`${cliName} doctor`)} ${chalk.gray('· verify install & versions')}`)
|
|
103
|
+
console.log(` ${chalk.dim('tip')} ${chalk.bold.white(`${cliName} tp dev general`)} ${chalk.gray('· telepresence local intercept')}`)
|
|
95
104
|
console.log('')
|
|
96
105
|
}
|
|
97
106
|
|
|
@@ -132,7 +141,7 @@ export function formatRootHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
132
141
|
|
|
133
142
|
export function formatCreateHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
134
143
|
const examples = [
|
|
135
|
-
{ cmd: `${cliName} create demo --workspace`, desc: '→ workspace
|
|
144
|
+
{ cmd: `${cliName} create demo --workspace`, desc: '→ workspace + api/general + admin/web' },
|
|
136
145
|
{ cmd: `${cliName} create my-api`, desc: '→ ./my-api (current folder)' },
|
|
137
146
|
{ cmd: `${cliName} create my-api ..`, desc: '→ ../my-api' },
|
|
138
147
|
{ cmd: `${cliName} create my-api ~/services`, desc: '→ ~/services/my-api' },
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import yaml from 'yaml'
|
|
4
|
+
|
|
5
|
+
import { packageDefaults } from './package-defaults.mjs'
|
|
6
|
+
import { isCorePackageRoot } from './tmp-layout.mjs'
|
|
7
|
+
import { findEntries, findWorkspaceRoot, workspaceProjectName } from './workspace-resolve.mjs'
|
|
8
|
+
import { getInstalledCoreVersion, readCliPackageJson, readProjectPackageJson, resolveProjectRoot } from './project-root.mjs'
|
|
9
|
+
import { readTmpSchemaVersion, TMP_SCHEMA_VERSION } from './tmp-schema-version.mjs'
|
|
10
|
+
|
|
11
|
+
const WORKSPACE_TYPE = 'workspace'
|
|
12
|
+
|
|
13
|
+
function readTmpMeta(tmpFilePath) {
|
|
14
|
+
if (!tmpFilePath || !fs.existsSync(tmpFilePath)) return null
|
|
15
|
+
try {
|
|
16
|
+
const doc = yaml.parse(fs.readFileSync(tmpFilePath, 'utf8'))
|
|
17
|
+
const globalType = doc?.configs?.global?.type ?? null
|
|
18
|
+
const projectName = doc?.project?.name ?? null
|
|
19
|
+
return {
|
|
20
|
+
path: tmpFilePath,
|
|
21
|
+
projectName,
|
|
22
|
+
globalType,
|
|
23
|
+
schemaVersion: readTmpSchemaVersion(tmpFilePath),
|
|
24
|
+
}
|
|
25
|
+
} catch {
|
|
26
|
+
return { path: tmpFilePath, projectName: null, globalType: null, schemaVersion: null }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function findOuterWorkspaceTmp(startDir) {
|
|
31
|
+
const wsRoot = findWorkspaceRoot(startDir)
|
|
32
|
+
if (!wsRoot) return null
|
|
33
|
+
const outer = path.join(wsRoot, 'tmp.yml')
|
|
34
|
+
return fs.existsSync(outer) ? outer : null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function resolveProjectContext(startDir = process.cwd()) {
|
|
38
|
+
const cwd = path.resolve(startDir)
|
|
39
|
+
const cliVersion = readCliPackageJson().version
|
|
40
|
+
const workspaceRoot = findWorkspaceRoot(cwd)
|
|
41
|
+
const projectRoot = resolveProjectRoot(cwd)
|
|
42
|
+
const atWorkspaceRoot = workspaceRoot != null && path.resolve(workspaceRoot) === cwd
|
|
43
|
+
|
|
44
|
+
if (isCorePackageRoot(projectRoot)) {
|
|
45
|
+
const coreRoot = projectRoot
|
|
46
|
+
const innerTmpPath = path.join(coreRoot, packageDefaults.packageRootFolder, `${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`)
|
|
47
|
+
const innerMeta = readTmpMeta(fs.existsSync(innerTmpPath) ? innerTmpPath : null)
|
|
48
|
+
return {
|
|
49
|
+
kind: 'core-library',
|
|
50
|
+
label: '@xrystal/core (library source)',
|
|
51
|
+
cwd,
|
|
52
|
+
projectRoot: coreRoot,
|
|
53
|
+
workspaceRoot: null,
|
|
54
|
+
outerTmp: null,
|
|
55
|
+
innerTmp: innerMeta,
|
|
56
|
+
tmp: innerMeta,
|
|
57
|
+
package: readProjectPackageJson(coreRoot),
|
|
58
|
+
core: { cli: cliVersion, declared: cliVersion, installed: cliVersion, isGlobalLibrary: true },
|
|
59
|
+
workspaceEntries: [],
|
|
60
|
+
hints: [
|
|
61
|
+
'Global runtime library — publish via xry tag',
|
|
62
|
+
'Consumers: bun add @xrystal/core && xry tmp in their repo',
|
|
63
|
+
],
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const outerTmpPath = findOuterWorkspaceTmp(cwd)
|
|
68
|
+
const outerMeta = outerTmpPath ? readTmpMeta(outerTmpPath) : null
|
|
69
|
+
|
|
70
|
+
const innerTmpPath = (() => {
|
|
71
|
+
if (atWorkspaceRoot) return null
|
|
72
|
+
const fromProject = path.join(projectRoot, packageDefaults.packageRootFolder, `${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`)
|
|
73
|
+
if (fs.existsSync(fromProject)) return fromProject
|
|
74
|
+
const atRoot = path.join(projectRoot, `${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`)
|
|
75
|
+
if (fs.existsSync(atRoot)) return atRoot
|
|
76
|
+
return null
|
|
77
|
+
})()
|
|
78
|
+
|
|
79
|
+
let pkg = null
|
|
80
|
+
const pkgPath = path.join(projectRoot, 'package.json')
|
|
81
|
+
if (fs.existsSync(pkgPath)) {
|
|
82
|
+
try {
|
|
83
|
+
pkg = readProjectPackageJson(projectRoot)
|
|
84
|
+
} catch {
|
|
85
|
+
pkg = null
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let core = { declared: null, installed: null, path: null, isWorkspace: false }
|
|
90
|
+
if (pkg) {
|
|
91
|
+
core = getInstalledCoreVersion(projectRoot)
|
|
92
|
+
}
|
|
93
|
+
const innerMeta = innerTmpPath ? readTmpMeta(innerTmpPath) : null
|
|
94
|
+
|
|
95
|
+
let kind = 'standalone-service'
|
|
96
|
+
let label = 'Standalone service'
|
|
97
|
+
if (atWorkspaceRoot && outerMeta?.globalType === WORKSPACE_TYPE) {
|
|
98
|
+
kind = 'workspace-root'
|
|
99
|
+
label = 'Workspace root (outer tmp.yml)'
|
|
100
|
+
} else if (workspaceRoot && outerMeta?.globalType === WORKSPACE_TYPE) {
|
|
101
|
+
kind = 'workspace-service'
|
|
102
|
+
label = 'Workspace linked service (inner x/tmp.yml)'
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const workspaceEntries = workspaceRoot ? findEntries(workspaceRoot) : []
|
|
106
|
+
const selfEntry = workspaceEntries.find((e) => path.resolve(e.path) === path.resolve(projectRoot))
|
|
107
|
+
|
|
108
|
+
const hints = []
|
|
109
|
+
if (kind === 'workspace-root') {
|
|
110
|
+
hints.push('Outer tmp: ./tmp.yml · inner tmp: each api|admin|web project')
|
|
111
|
+
hints.push('xry sync — all linked inner projects + ~/.xrystal registry')
|
|
112
|
+
hints.push('xry workspaces — global registry (~/.xrystal), not this folder alone')
|
|
113
|
+
} else if (kind === 'workspace-service') {
|
|
114
|
+
hints.push(`Outer workspace: ${workspaceRoot}`)
|
|
115
|
+
hints.push('xry tmp — inner x/tmp.yml · xry project — this view')
|
|
116
|
+
hints.push('Run xry sync from workspace root to pin @xrystal/core on all services')
|
|
117
|
+
} else {
|
|
118
|
+
hints.push('xry tmp — seed inner x/tmp.yml')
|
|
119
|
+
hints.push('@xrystal/core is the global library (npm) powering this service')
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
kind,
|
|
124
|
+
label,
|
|
125
|
+
cwd,
|
|
126
|
+
projectRoot,
|
|
127
|
+
workspaceRoot,
|
|
128
|
+
atWorkspaceRoot,
|
|
129
|
+
outerTmp: outerMeta,
|
|
130
|
+
innerTmp: innerMeta,
|
|
131
|
+
tmp: innerMeta ?? outerMeta,
|
|
132
|
+
selfEntry: selfEntry ?? null,
|
|
133
|
+
package: pkg,
|
|
134
|
+
core: {
|
|
135
|
+
cli: cliVersion,
|
|
136
|
+
declared: core.declared,
|
|
137
|
+
installed: core.installed,
|
|
138
|
+
isGlobalLibrary: false,
|
|
139
|
+
},
|
|
140
|
+
workspaceEntries,
|
|
141
|
+
schemaVersionExpected: TMP_SCHEMA_VERSION,
|
|
142
|
+
hints,
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -5,7 +5,7 @@ import yaml from 'yaml'
|
|
|
5
5
|
|
|
6
6
|
import { Constants } from '../constants/index.mjs'
|
|
7
7
|
import { ensureTmpFile } from './tmp-layout.mjs'
|
|
8
|
-
import {
|
|
8
|
+
import { ensureTmpSchemaVersion } from './tmp-schema-version.mjs'
|
|
9
9
|
import { setupProjectGitHooks } from '../scripts/install-git-hooks.mjs'
|
|
10
10
|
|
|
11
11
|
function patchTmpProjectName(tmpFilePath, projectName) {
|
|
@@ -19,7 +19,6 @@ export function scaffoldServiceFromTemplate(targetPath, {
|
|
|
19
19
|
templateRepoUri = Constants.templateRepoUri,
|
|
20
20
|
installCommand,
|
|
21
21
|
cliName,
|
|
22
|
-
coreVersion,
|
|
23
22
|
setupHooks = true,
|
|
24
23
|
} = {}) {
|
|
25
24
|
const resolved = path.resolve(targetPath)
|
|
@@ -44,7 +43,7 @@ export function scaffoldServiceFromTemplate(targetPath, {
|
|
|
44
43
|
|
|
45
44
|
const tmpResult = ensureTmpFile(resolved)
|
|
46
45
|
patchTmpProjectName(tmpResult.tmpFilePath, projectName)
|
|
47
|
-
|
|
46
|
+
ensureTmpSchemaVersion(tmpResult.tmpFilePath)
|
|
48
47
|
|
|
49
48
|
execSync(installCommand, { cwd: resolved, stdio: 'inherit' })
|
|
50
49
|
|
|
@@ -4,8 +4,7 @@ import yaml from 'yaml'
|
|
|
4
4
|
|
|
5
5
|
import { packageDefaults } from '../paths.mjs'
|
|
6
6
|
import { findAllFilesRecursively, findFileRecursively } from './index.mjs'
|
|
7
|
-
import {
|
|
8
|
-
import { readCliPackageJson } from './project-root.mjs'
|
|
7
|
+
import { ensureTmpSchemaVersion } from './tmp-schema-version.mjs'
|
|
9
8
|
import { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, resolveMergedPaths, resolveTmpAbsPath } from './tmp-schema.mjs'
|
|
10
9
|
|
|
11
10
|
function formatTmpTarget(name, ext) {
|
|
@@ -252,7 +251,7 @@ export function ensureTmpFile(projectRoot = process.cwd(), { patchProjectName =
|
|
|
252
251
|
fs.writeFileSync(targetPath, content)
|
|
253
252
|
|
|
254
253
|
try {
|
|
255
|
-
|
|
254
|
+
ensureTmpSchemaVersion(targetPath)
|
|
256
255
|
} catch {
|
|
257
256
|
}
|
|
258
257
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import yaml from 'yaml'
|
|
3
|
+
|
|
4
|
+
import { packageDefaults } from './package-defaults.mjs'
|
|
5
|
+
|
|
6
|
+
/** tmp.yml end.version — tmp **schema** revision (bump only when tmp shape changes). Starts at 1. */
|
|
7
|
+
export const TMP_SCHEMA_VERSION = packageDefaults.tmpSchemaVersion ?? 1
|
|
8
|
+
|
|
9
|
+
const SEMVER_LIKE = /^\d+\.\d+\.\d+(?:[-+].*)?$/
|
|
10
|
+
|
|
11
|
+
export function readTmpSchemaVersion(tmpFilePath) {
|
|
12
|
+
if (!fs.existsSync(tmpFilePath)) return null
|
|
13
|
+
const doc = yaml.parse(fs.readFileSync(tmpFilePath, 'utf8'))
|
|
14
|
+
const raw = doc?.end?.version
|
|
15
|
+
if (raw === undefined || raw === null || raw === '') return null
|
|
16
|
+
return String(raw).trim()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Ensure end.version exists; heal mistaken core semver stamps. Never writes CLI package version here. */
|
|
20
|
+
export function ensureTmpSchemaVersion(tmpFilePath, { write = true } = {}) {
|
|
21
|
+
if (!fs.existsSync(tmpFilePath)) {
|
|
22
|
+
return { ensured: false, reason: 'missing tmp.yml' }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const doc = yaml.parse(fs.readFileSync(tmpFilePath, 'utf8'))
|
|
26
|
+
const prev = doc?.end?.version != null ? String(doc.end.version).trim() : null
|
|
27
|
+
let next = prev
|
|
28
|
+
|
|
29
|
+
if (prev == null || prev === '') {
|
|
30
|
+
next = String(TMP_SCHEMA_VERSION)
|
|
31
|
+
} else if (SEMVER_LIKE.test(prev) && prev !== String(TMP_SCHEMA_VERSION)) {
|
|
32
|
+
// heal legacy bug: end.version had @xrystal/core semver instead of schema id
|
|
33
|
+
next = String(TMP_SCHEMA_VERSION)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (next === prev) {
|
|
37
|
+
return { ensured: true, patched: false, schemaVersion: next, previous: prev }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
doc.end = { ...(doc.end ?? {}), version: next }
|
|
41
|
+
if (write) {
|
|
42
|
+
fs.writeFileSync(tmpFilePath, yaml.stringify(doc))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return { ensured: true, patched: true, schemaVersion: next, previous: prev }
|
|
46
|
+
}
|
|
@@ -4,15 +4,15 @@ import path from 'node:path'
|
|
|
4
4
|
import { DEFAULT_FOLDER_STRUCTURE, workspaceTmpTemplate } from './workspace-resolve.mjs'
|
|
5
5
|
import { scaffoldServiceFromTemplate } from './scaffold-service.mjs'
|
|
6
6
|
import { ensureServiceTelepresenceEnv, writeWorkspaceTelepresenceFiles } from './telepresence-layout.mjs'
|
|
7
|
-
import {
|
|
7
|
+
import { ensureTmpSchemaVersion } from './tmp-schema-version.mjs'
|
|
8
8
|
import { syncRegistryFromPath } from './xrystal-registry.mjs'
|
|
9
9
|
|
|
10
10
|
export function scaffoldWorkspace(targetPath, projectName, {
|
|
11
|
-
coreVersion,
|
|
12
11
|
installCommand,
|
|
13
12
|
cliName,
|
|
14
13
|
scaffoldGeneral = true,
|
|
15
14
|
templateRepoUri,
|
|
15
|
+
coreVersion: _coreVersion,
|
|
16
16
|
} = {}) {
|
|
17
17
|
const resolved = path.resolve(targetPath)
|
|
18
18
|
fs.mkdirSync(resolved, { recursive: true })
|
|
@@ -22,7 +22,8 @@ export function scaffoldWorkspace(targetPath, projectName, {
|
|
|
22
22
|
throw new Error(`workspace tmp.yml already exists: ${tmpPath}`)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
fs.writeFileSync(tmpPath, workspaceTmpTemplate(projectName
|
|
25
|
+
fs.writeFileSync(tmpPath, workspaceTmpTemplate(projectName))
|
|
26
|
+
ensureTmpSchemaVersion(tmpPath)
|
|
26
27
|
fs.writeFileSync(path.join(resolved, '.gitignore'), '.env.telepresence\n.env.local\n.env.private\nnode_modules/\n')
|
|
27
28
|
|
|
28
29
|
writeWorkspaceTelepresenceFiles(resolved)
|
|
@@ -39,7 +40,6 @@ export function scaffoldWorkspace(targetPath, projectName, {
|
|
|
39
40
|
templateRepoUri,
|
|
40
41
|
installCommand,
|
|
41
42
|
cliName,
|
|
42
|
-
coreVersion,
|
|
43
43
|
})
|
|
44
44
|
ensureServiceTelepresenceEnv(generalPath)
|
|
45
45
|
}
|
|
@@ -51,8 +51,3 @@ export function scaffoldWorkspace(targetPath, projectName, {
|
|
|
51
51
|
|
|
52
52
|
return { root: resolved, tmpPath, general }
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
export function patchWorkspaceTmpEndVersion(workspaceRoot, coreVersion) {
|
|
56
|
-
const tmpPath = path.join(path.resolve(workspaceRoot), 'tmp.yml')
|
|
57
|
-
return patchTmpEndVersion(tmpPath, coreVersion)
|
|
58
|
-
}
|
package/x/bin/main-cli.js
CHANGED
|
@@ -5,6 +5,7 @@ import chalk from 'chalk'
|
|
|
5
5
|
|
|
6
6
|
import { registerCreateCommand } from './commands/create.mjs'
|
|
7
7
|
import { registerDoctorCommand } from './commands/doctor.mjs'
|
|
8
|
+
import { registerProjectInfoCommand } from './commands/project-info.mjs'
|
|
8
9
|
import { registerProjectCommands } from './commands/project.mjs'
|
|
9
10
|
import { registerTmpCommand } from './commands/tmp.mjs'
|
|
10
11
|
import { registerSyncCommand } from './commands/sync.mjs'
|
|
@@ -54,11 +55,18 @@ cli
|
|
|
54
55
|
.name(PACKAGE_NAME)
|
|
55
56
|
.description(packageCliDescription())
|
|
56
57
|
.version(pkg.version, '-V, --version', `Show ${PACKAGE_NAME} version`)
|
|
58
|
+
.allowExcessArguments(true)
|
|
57
59
|
.configureHelp({
|
|
58
60
|
helpWidth: () => Math.min(100, Math.max(56, process.stdout.columns || 80)),
|
|
59
61
|
sortSubcommands: true,
|
|
60
62
|
})
|
|
61
|
-
.action(() => {
|
|
63
|
+
.action((_options, cmd) => {
|
|
64
|
+
const unknown = cmd?.args ?? []
|
|
65
|
+
if (unknown.length > 0) {
|
|
66
|
+
console.error(chalk.red(`\n✗ Unknown command: ${unknown[0]}\n`))
|
|
67
|
+
console.error(chalk.gray(` Run ${cliName} -h for help.\n`))
|
|
68
|
+
process.exit(1)
|
|
69
|
+
}
|
|
62
70
|
printQuickStartGuide({ cliName })
|
|
63
71
|
})
|
|
64
72
|
|
|
@@ -67,6 +75,7 @@ registerVersionCommand(cli, cliContext)
|
|
|
67
75
|
registerTagCommand(cli, cliContext)
|
|
68
76
|
registerDoctorCommand(cli, cliContext)
|
|
69
77
|
registerTmpCommand(cli, cliContext)
|
|
78
|
+
registerProjectInfoCommand(cli, cliContext)
|
|
70
79
|
registerSyncCommand(cli, cliContext)
|
|
71
80
|
registerWorkspacesCommand(cli, cliContext)
|
|
72
81
|
registerProjectsCommand(cli, cliContext)
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"cliBinFile": "main-cli.js",
|
|
9
9
|
"tmpBaseName": "tmp",
|
|
10
10
|
"tmpExtension": ".yml",
|
|
11
|
+
"tmpSchemaVersion": 1,
|
|
11
12
|
"apiServiceTemplateRel": "x/templates/api-service/tmp.yml",
|
|
12
13
|
"templateRepoUri": "https://github.com/xdloper/api-gpt-svc",
|
|
13
14
|
"publicFolderName": "public",
|
|
@@ -39,4 +39,4 @@ export declare function readWorkspaceGlobalTmp(workspaceRoot: string): {
|
|
|
39
39
|
fileWatchIntervalMs?: number;
|
|
40
40
|
};
|
|
41
41
|
/** @deprecated */ export declare const readWorkspaceCoreTmp: typeof readWorkspaceGlobalTmp;
|
|
42
|
-
export declare function workspaceTmpTemplate(projectName: string
|
|
42
|
+
export declare function workspaceTmpTemplate(projectName: string): string;
|
|
@@ -200,7 +200,7 @@ export function readWorkspaceGlobalTmp(workspaceRoot) {
|
|
|
200
200
|
return match ? { fileWatchIntervalMs: Number(match[1]) } : {};
|
|
201
201
|
}
|
|
202
202
|
/** @deprecated */ export const readWorkspaceCoreTmp = readWorkspaceGlobalTmp;
|
|
203
|
-
export function workspaceTmpTemplate(projectName
|
|
203
|
+
export function workspaceTmpTemplate(projectName) {
|
|
204
204
|
return `project:
|
|
205
205
|
name: ${projectName}
|
|
206
206
|
|
|
@@ -222,6 +222,6 @@ configs:
|
|
|
222
222
|
kubeconfig: ~/.kube/config
|
|
223
223
|
|
|
224
224
|
end:
|
|
225
|
-
version:
|
|
225
|
+
version: 1
|
|
226
226
|
`;
|
|
227
227
|
}
|
package/x/tmp.yml
CHANGED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import yaml from 'yaml'
|
|
3
|
-
|
|
4
|
-
/** tmp.yml end.version tracks @xrystal/core CLI semver (not a schema id). */
|
|
5
|
-
export function readTmpEndVersion(tmpFilePath) {
|
|
6
|
-
if (!fs.existsSync(tmpFilePath)) return null
|
|
7
|
-
const doc = yaml.parse(fs.readFileSync(tmpFilePath, 'utf8'))
|
|
8
|
-
const raw = doc?.end?.version
|
|
9
|
-
if (raw === undefined || raw === null || raw === '') return null
|
|
10
|
-
return String(raw).trim()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function patchTmpEndVersion(tmpFilePath, coreVersion, { write = true } = {}) {
|
|
14
|
-
if (!fs.existsSync(tmpFilePath)) {
|
|
15
|
-
return { patched: false, reason: 'missing tmp.yml' }
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const version = String(coreVersion ?? '').trim()
|
|
19
|
-
if (!version) {
|
|
20
|
-
return { patched: false, reason: 'empty version' }
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const doc = yaml.parse(fs.readFileSync(tmpFilePath, 'utf8'))
|
|
24
|
-
const prev = doc?.end?.version != null ? String(doc.end.version).trim() : null
|
|
25
|
-
if (prev === version) {
|
|
26
|
-
return { patched: false, reason: 'up-to-date', version, previous: prev }
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
doc.end = { ...(doc.end ?? {}), version }
|
|
30
|
-
if (write) {
|
|
31
|
-
fs.writeFileSync(tmpFilePath, yaml.stringify(doc))
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return { patched: true, version, previous: prev }
|
|
35
|
-
}
|