@xrystal/core 3.52.4 → 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 +19 -13
- package/package.json +1 -1
- package/x/bin/commands/create.mjs +12 -3
- package/x/bin/commands/project-info.mjs +94 -0
- package/x/bin/commands/projects.mjs +1 -1
- package/x/bin/commands/sync.mjs +18 -2
- package/x/bin/commands/telepresence.mjs +134 -0
- package/x/bin/commands/tmp.mjs +10 -1
- 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 +6 -0
- package/x/bin/helpers/.generated/xrystal-home-registry.mjs +192 -44
- package/x/bin/helpers/cli-help.mjs +23 -12
- package/x/bin/helpers/project-context.mjs +144 -0
- package/x/bin/helpers/scaffold-service.mjs +60 -0
- package/x/bin/helpers/sync-core-dependency.mjs +10 -4
- package/x/bin/helpers/telepresence-layout.mjs +61 -0
- package/x/bin/helpers/tmp-layout.mjs +7 -1
- package/x/bin/helpers/tmp-schema-version.mjs +46 -0
- package/x/bin/helpers/workspace-scaffold.mjs +33 -3
- package/x/bin/main-cli.js +12 -1
- package/x/dist/utils/constants/defaults.json +1 -0
- package/x/dist/utils/helpers/workspace/index.js +5 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
const TELEPRESENCE_ENV_EXAMPLE = `# Telepresence intercept env — copied to x/environments/.env.telepresence per service
|
|
5
|
+
# Used by: telepresence intercept --env-file .env.telepresence
|
|
6
|
+
NS=dev
|
|
7
|
+
TELEPRESENCE_INTERCEPT_HEADER=x-intercept-who
|
|
8
|
+
# TELEPRESENCE_DEV_ID=your-id
|
|
9
|
+
`
|
|
10
|
+
|
|
11
|
+
const SERVICE_TELEPRESENCE_ENV = `# Auto-scaffolded for local intercept (xry telepresence dev)
|
|
12
|
+
NS=dev
|
|
13
|
+
NODE_ENV=dev
|
|
14
|
+
TELEPRESENCE_INTERCEPT_HEADER=x-intercept-who
|
|
15
|
+
`
|
|
16
|
+
|
|
17
|
+
export function writeWorkspaceTelepresenceFiles(workspaceRoot) {
|
|
18
|
+
const root = path.resolve(workspaceRoot)
|
|
19
|
+
const examplePath = path.join(root, '.env.telepresence.example')
|
|
20
|
+
if (!fs.existsSync(examplePath)) {
|
|
21
|
+
fs.writeFileSync(examplePath, TELEPRESENCE_ENV_EXAMPLE)
|
|
22
|
+
}
|
|
23
|
+
return { examplePath }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function ensureServiceTelepresenceEnv(serviceRoot) {
|
|
27
|
+
const root = path.resolve(serviceRoot)
|
|
28
|
+
const envDir = path.join(root, 'x', 'environments')
|
|
29
|
+
const envPath = path.join(envDir, '.env.telepresence')
|
|
30
|
+
fs.mkdirSync(envDir, { recursive: true })
|
|
31
|
+
if (!fs.existsSync(envPath)) {
|
|
32
|
+
fs.writeFileSync(envPath, SERVICE_TELEPRESENCE_ENV)
|
|
33
|
+
}
|
|
34
|
+
return envPath
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Deploy name (tmp project.name) → workspace api folder name */
|
|
38
|
+
export const TELEPRESENCE_DEPLOYMENTS = Object.freeze([
|
|
39
|
+
'general',
|
|
40
|
+
'gateway',
|
|
41
|
+
'iam',
|
|
42
|
+
'core',
|
|
43
|
+
'websocket',
|
|
44
|
+
'crons',
|
|
45
|
+
'log',
|
|
46
|
+
'gpt',
|
|
47
|
+
])
|
|
48
|
+
|
|
49
|
+
export function resolveTelepresenceServiceDir(workspaceRoot, deployName) {
|
|
50
|
+
const apiRoot = path.join(path.resolve(workspaceRoot), 'api')
|
|
51
|
+
const slug = String(deployName ?? '').trim()
|
|
52
|
+
if (!slug) return null
|
|
53
|
+
|
|
54
|
+
const direct = path.join(apiRoot, slug)
|
|
55
|
+
if (fs.existsSync(path.join(direct, 'x', 'tmp.yml'))) return direct
|
|
56
|
+
|
|
57
|
+
const suffixed = path.join(apiRoot, `api-${slug}-svc`)
|
|
58
|
+
if (fs.existsSync(path.join(suffixed, 'x', 'tmp.yml'))) return suffixed
|
|
59
|
+
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
@@ -4,7 +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 {
|
|
7
|
+
import { ensureTmpSchemaVersion } from './tmp-schema-version.mjs'
|
|
8
8
|
import { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, resolveMergedPaths, resolveTmpAbsPath } from './tmp-schema.mjs'
|
|
9
9
|
|
|
10
10
|
function formatTmpTarget(name, ext) {
|
|
@@ -249,6 +249,12 @@ export function ensureTmpFile(projectRoot = process.cwd(), { patchProjectName =
|
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
fs.writeFileSync(targetPath, content)
|
|
252
|
+
|
|
253
|
+
try {
|
|
254
|
+
ensureTmpSchemaVersion(targetPath)
|
|
255
|
+
} catch {
|
|
256
|
+
}
|
|
257
|
+
|
|
252
258
|
return {
|
|
253
259
|
tmpFilePath: targetPath,
|
|
254
260
|
created: true,
|
|
@@ -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
|
+
}
|
|
@@ -2,8 +2,18 @@ import fs from 'node:fs'
|
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
|
|
4
4
|
import { DEFAULT_FOLDER_STRUCTURE, workspaceTmpTemplate } from './workspace-resolve.mjs'
|
|
5
|
+
import { scaffoldServiceFromTemplate } from './scaffold-service.mjs'
|
|
6
|
+
import { ensureServiceTelepresenceEnv, writeWorkspaceTelepresenceFiles } from './telepresence-layout.mjs'
|
|
7
|
+
import { ensureTmpSchemaVersion } from './tmp-schema-version.mjs'
|
|
8
|
+
import { syncRegistryFromPath } from './xrystal-registry.mjs'
|
|
5
9
|
|
|
6
|
-
export function scaffoldWorkspace(targetPath, projectName
|
|
10
|
+
export function scaffoldWorkspace(targetPath, projectName, {
|
|
11
|
+
installCommand,
|
|
12
|
+
cliName,
|
|
13
|
+
scaffoldGeneral = true,
|
|
14
|
+
templateRepoUri,
|
|
15
|
+
coreVersion: _coreVersion,
|
|
16
|
+
} = {}) {
|
|
7
17
|
const resolved = path.resolve(targetPath)
|
|
8
18
|
fs.mkdirSync(resolved, { recursive: true })
|
|
9
19
|
|
|
@@ -13,11 +23,31 @@ export function scaffoldWorkspace(targetPath, projectName) {
|
|
|
13
23
|
}
|
|
14
24
|
|
|
15
25
|
fs.writeFileSync(tmpPath, workspaceTmpTemplate(projectName))
|
|
16
|
-
|
|
26
|
+
ensureTmpSchemaVersion(tmpPath)
|
|
27
|
+
fs.writeFileSync(path.join(resolved, '.gitignore'), '.env.telepresence\n.env.local\n.env.private\nnode_modules/\n')
|
|
28
|
+
|
|
29
|
+
writeWorkspaceTelepresenceFiles(resolved)
|
|
17
30
|
|
|
18
31
|
for (const dir of Object.values(DEFAULT_FOLDER_STRUCTURE)) {
|
|
19
32
|
fs.mkdirSync(path.join(resolved, dir), { recursive: true })
|
|
20
33
|
}
|
|
21
34
|
|
|
22
|
-
|
|
35
|
+
let general = null
|
|
36
|
+
if (scaffoldGeneral) {
|
|
37
|
+
const generalPath = path.join(resolved, DEFAULT_FOLDER_STRUCTURE.api, 'general')
|
|
38
|
+
general = scaffoldServiceFromTemplate(generalPath, {
|
|
39
|
+
projectName: 'general',
|
|
40
|
+
templateRepoUri,
|
|
41
|
+
installCommand,
|
|
42
|
+
cliName,
|
|
43
|
+
})
|
|
44
|
+
ensureServiceTelepresenceEnv(generalPath)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
syncRegistryFromPath(resolved)
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return { root: resolved, tmpPath, general }
|
|
23
53
|
}
|
package/x/bin/main-cli.js
CHANGED
|
@@ -5,11 +5,13 @@ 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'
|
|
11
12
|
import { registerProjectsCommand, registerWorkspacesCommand } from './commands/projects.mjs'
|
|
12
13
|
import { registerTagCommand, registerVersionCommand } from './commands/release.mjs'
|
|
14
|
+
import { registerTelepresenceCommand } from './commands/telepresence.mjs'
|
|
13
15
|
import { registerHooksCommand } from './commands/hooks.mjs'
|
|
14
16
|
import { printBanner, shouldShowBanner } from './helpers/banner.mjs'
|
|
15
17
|
import { formatRootHelp, formatCreateCommandHelp, isCreateHelpRequest, isRootHelpRequest, printQuickStartGuide } from './helpers/cli-help.mjs'
|
|
@@ -53,11 +55,18 @@ cli
|
|
|
53
55
|
.name(PACKAGE_NAME)
|
|
54
56
|
.description(packageCliDescription())
|
|
55
57
|
.version(pkg.version, '-V, --version', `Show ${PACKAGE_NAME} version`)
|
|
58
|
+
.allowExcessArguments(true)
|
|
56
59
|
.configureHelp({
|
|
57
60
|
helpWidth: () => Math.min(100, Math.max(56, process.stdout.columns || 80)),
|
|
58
61
|
sortSubcommands: true,
|
|
59
62
|
})
|
|
60
|
-
.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
|
+
}
|
|
61
70
|
printQuickStartGuide({ cliName })
|
|
62
71
|
})
|
|
63
72
|
|
|
@@ -66,10 +75,12 @@ registerVersionCommand(cli, cliContext)
|
|
|
66
75
|
registerTagCommand(cli, cliContext)
|
|
67
76
|
registerDoctorCommand(cli, cliContext)
|
|
68
77
|
registerTmpCommand(cli, cliContext)
|
|
78
|
+
registerProjectInfoCommand(cli, cliContext)
|
|
69
79
|
registerSyncCommand(cli, cliContext)
|
|
70
80
|
registerWorkspacesCommand(cli, cliContext)
|
|
71
81
|
registerProjectsCommand(cli, cliContext)
|
|
72
82
|
registerHooksCommand(cli, cliContext)
|
|
83
|
+
registerTelepresenceCommand(cli, cliContext)
|
|
73
84
|
registerProjectCommands(cli, cliContext)
|
|
74
85
|
|
|
75
86
|
cli.parseAsync(process.argv).catch((error) => {
|
|
@@ -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",
|