@xrystal/core 3.55.4 → 3.55.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -6,11 +6,14 @@ import { getCliLang, setCliLang, t } from '../helpers/cli-i18n.mjs'
|
|
|
6
6
|
import { CliLangEnum } from '../helpers/cli-lang.mjs'
|
|
7
7
|
import { readCliPackageJson } from '../helpers/project-root.mjs'
|
|
8
8
|
import {
|
|
9
|
+
clearCliConfigInfraDir,
|
|
9
10
|
clearCliConfigLang,
|
|
10
11
|
configFilePath,
|
|
12
|
+
getCliConfigInfraDir,
|
|
11
13
|
getCliConfigLang,
|
|
12
14
|
listSupportedCliLangs,
|
|
13
15
|
readXrystalConfig,
|
|
16
|
+
setCliConfigInfraDir,
|
|
14
17
|
setCliConfigLang,
|
|
15
18
|
} from '../helpers/xrystal-config.mjs'
|
|
16
19
|
|
|
@@ -18,7 +21,9 @@ function printConfigDoc(doc) {
|
|
|
18
21
|
console.log(chalk.gray(` file: ${configFilePath()}`))
|
|
19
22
|
console.log(chalk.bold.white('\n cli'))
|
|
20
23
|
const lang = doc.cli?.lang ?? chalk.dim('(not set — default en)')
|
|
24
|
+
const infraDir = doc.cli?.infraDir ?? chalk.dim('(auto-detect from cwd)')
|
|
21
25
|
console.log(` lang: ${lang}`)
|
|
26
|
+
console.log(` infraDir: ${infraDir}`)
|
|
22
27
|
if (doc.updatedAt) {
|
|
23
28
|
console.log(chalk.gray(`\n updated: ${doc.updatedAt}`))
|
|
24
29
|
}
|
|
@@ -74,4 +79,37 @@ export function registerConfigCommand(cli, { cliName = CLI_PRIMARY_NAME } = {})
|
|
|
74
79
|
}
|
|
75
80
|
printCommandFooter({ version })
|
|
76
81
|
})
|
|
82
|
+
|
|
83
|
+
config
|
|
84
|
+
.command('infra [path]')
|
|
85
|
+
.description('Get or set -infrastructure- repo path — saved to ~/.xrystal/config.json')
|
|
86
|
+
.action((infraPath) => {
|
|
87
|
+
const version = readCliPackageJson().version
|
|
88
|
+
printCommandHeader({ cliName, command: 'config infra', version })
|
|
89
|
+
|
|
90
|
+
if (!infraPath) {
|
|
91
|
+
const saved = getCliConfigInfraDir()
|
|
92
|
+
console.log(chalk.gray(` saved: ${saved ?? '(auto-detect from cwd)'}`))
|
|
93
|
+
console.log(chalk.dim(`\n set: ${cliName} config infra /path/to/-infrastructure-`))
|
|
94
|
+
printCommandFooter({ version })
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (infraPath === 'reset' || infraPath === 'clear') {
|
|
99
|
+
clearCliConfigInfraDir()
|
|
100
|
+
console.log(chalk.green(' infraDir reset → auto-detect from cwd'))
|
|
101
|
+
printCommandFooter({ version })
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const resolved = setCliConfigInfraDir(infraPath)
|
|
107
|
+
console.log(chalk.green(` infraDir → ${resolved}`))
|
|
108
|
+
console.log(chalk.gray(` saved: ${configFilePath()}`))
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error(chalk.red(`\n✗ ${error.message}\n`))
|
|
111
|
+
process.exit(1)
|
|
112
|
+
}
|
|
113
|
+
printCommandFooter({ version })
|
|
114
|
+
})
|
|
77
115
|
}
|
|
@@ -5,7 +5,7 @@ import chalk from 'chalk'
|
|
|
5
5
|
import { printCommandFooter, printCommandHeader } from '../helpers/banner.mjs'
|
|
6
6
|
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
7
7
|
import { readCliPackageJson } from '../helpers/project-root.mjs'
|
|
8
|
-
import { resolveInfraHelperScript } from '../helpers/resolve-infra-helper.mjs'
|
|
8
|
+
import { formatInfraResolveHint, resolveInfraHelperScript } from '../helpers/resolve-infra-helper.mjs'
|
|
9
9
|
import {
|
|
10
10
|
ensureServiceTelepresenceEnv,
|
|
11
11
|
resolveTelepresenceServiceDir,
|
|
@@ -21,10 +21,11 @@ function runHelper(scriptPath, args, { cwd } = {}) {
|
|
|
21
21
|
})
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function requireInfraScript(name) {
|
|
25
|
-
const script = resolveInfraHelperScript(name)
|
|
24
|
+
function requireInfraScript(name, { cliName } = {}) {
|
|
25
|
+
const script = resolveInfraHelperScript(name, { cwd: process.cwd() })
|
|
26
26
|
if (!script) {
|
|
27
|
-
console.error(chalk.red(`\n✗ ${name} not found
|
|
27
|
+
console.error(chalk.red(`\n✗ ${name} not found\n`))
|
|
28
|
+
console.error(chalk.gray(` ${formatInfraResolveHint({ cliName, cwd: process.cwd() })}\n`))
|
|
28
29
|
process.exit(1)
|
|
29
30
|
}
|
|
30
31
|
return script
|
|
@@ -63,7 +64,7 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
|
|
|
63
64
|
.action((options) => {
|
|
64
65
|
const version = readCliPackageJson().version
|
|
65
66
|
printCommandHeader({ cliName, command: 'telepresence connect', version })
|
|
66
|
-
const script = requireInfraScript('telepresence-connect.sh')
|
|
67
|
+
const script = requireInfraScript('telepresence-connect.sh', { cliName })
|
|
67
68
|
process.env.NS = options.ns
|
|
68
69
|
runHelper(script, [`NS=${options.ns}`])
|
|
69
70
|
printCommandFooter({ version })
|
|
@@ -75,7 +76,7 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
|
|
|
75
76
|
.action(() => {
|
|
76
77
|
const version = readCliPackageJson().version
|
|
77
78
|
printCommandHeader({ cliName, command: 'telepresence quit', version })
|
|
78
|
-
const script = requireInfraScript('telepresence-quit.sh')
|
|
79
|
+
const script = requireInfraScript('telepresence-quit.sh', { cliName })
|
|
79
80
|
runHelper(script, [])
|
|
80
81
|
printCommandFooter({ version })
|
|
81
82
|
})
|
|
@@ -86,7 +87,7 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
|
|
|
86
87
|
.action(() => {
|
|
87
88
|
const version = readCliPackageJson().version
|
|
88
89
|
printCommandHeader({ cliName, command: 'telepresence install', version })
|
|
89
|
-
const script = requireInfraScript('telepresence-client-install.sh')
|
|
90
|
+
const script = requireInfraScript('telepresence-client-install.sh', { cliName })
|
|
90
91
|
runHelper(script, [])
|
|
91
92
|
printCommandFooter({ version })
|
|
92
93
|
})
|
|
@@ -132,7 +133,7 @@ export function registerTelepresenceCommand(cli, { cliName = CLI_PRIMARY_NAME }
|
|
|
132
133
|
console.log(chalk.gray(` service: ${svcDir}`))
|
|
133
134
|
console.log(chalk.gray(` env: ${env.envRel}${env.created ? chalk.green(' (created)') : ''}\n`))
|
|
134
135
|
|
|
135
|
-
const interceptScript = requireInfraScript('telepresence-intercept.sh')
|
|
136
|
+
const interceptScript = requireInfraScript('telepresence-intercept.sh', { cliName })
|
|
136
137
|
|
|
137
138
|
const portArg = parsePort(port)
|
|
138
139
|
const rest = command.args.slice(/^\d+$/.test(String(port ?? '')) ? 2 : 1)
|
|
@@ -2,21 +2,70 @@ import fs from 'node:fs'
|
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import { fileURLToPath } from 'node:url'
|
|
4
4
|
|
|
5
|
+
import { getCliConfigInfraDir } from './xrystal-config.mjs'
|
|
6
|
+
|
|
5
7
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
8
|
+
const HELPERS_DIR = 'scripts/helpers'
|
|
9
|
+
|
|
10
|
+
function infraRootHasHelpers(root) {
|
|
11
|
+
if (!root) return false
|
|
12
|
+
return fs.existsSync(path.join(root, HELPERS_DIR))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Walk cwd → parents; sibling `-infrastructure-` next to each ancestor folder. */
|
|
16
|
+
export function walkUpForInfraRoot(start = process.cwd(), { maxDepth = 12 } = {}) {
|
|
17
|
+
let dir = path.resolve(start)
|
|
18
|
+
for (let depth = 0; depth < maxDepth; depth += 1) {
|
|
19
|
+
const sibling = path.join(path.dirname(dir), '-infrastructure-')
|
|
20
|
+
if (infraRootHasHelpers(sibling)) return sibling
|
|
21
|
+
|
|
22
|
+
const parent = path.dirname(dir)
|
|
23
|
+
if (parent === dir) break
|
|
24
|
+
dir = parent
|
|
25
|
+
}
|
|
26
|
+
return null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function listInfraRootCandidates(start = process.cwd()) {
|
|
30
|
+
const seen = new Set()
|
|
31
|
+
const out = []
|
|
6
32
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
33
|
+
const push = (value) => {
|
|
34
|
+
const resolved = value ? path.resolve(String(value)) : null
|
|
35
|
+
if (!resolved || seen.has(resolved)) return
|
|
36
|
+
seen.add(resolved)
|
|
37
|
+
out.push(resolved)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
push(process.env.XRYSTAL_INFRA_DIR)
|
|
41
|
+
push(process.env.XRYSTAL_INFRA_ROOT)
|
|
42
|
+
push(getCliConfigInfraDir())
|
|
43
|
+
push(walkUpForInfraRoot(start))
|
|
44
|
+
push(path.resolve(start, '../-infrastructure-'))
|
|
45
|
+
push(path.resolve(start, '../../-infrastructure-'))
|
|
46
|
+
push(path.resolve(__dirname, '../../../..', '-infrastructure-'))
|
|
47
|
+
|
|
48
|
+
return out
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Resolve a script under -infrastructure-/scripts/helpers. */
|
|
52
|
+
export function resolveInfraHelperScript(name, { cwd = process.cwd() } = {}) {
|
|
53
|
+
for (const root of listInfraRootCandidates(cwd)) {
|
|
54
|
+
const script = path.join(root, HELPERS_DIR, name)
|
|
19
55
|
if (fs.existsSync(script)) return script
|
|
20
56
|
}
|
|
21
57
|
return null
|
|
22
58
|
}
|
|
59
|
+
|
|
60
|
+
export function formatInfraResolveHint({ cliName = 'xry', cwd = process.cwd() } = {}) {
|
|
61
|
+
const walked = walkUpForInfraRoot(cwd)
|
|
62
|
+
const lines = [
|
|
63
|
+
'Set infra repo path (one of):',
|
|
64
|
+
` ${cliName} config infra /path/to/-infrastructure-`,
|
|
65
|
+
' export XRYSTAL_INFRA_DIR=/path/to/-infrastructure-',
|
|
66
|
+
]
|
|
67
|
+
if (walked) {
|
|
68
|
+
lines.push(` detected near cwd: ${walked}`)
|
|
69
|
+
}
|
|
70
|
+
return lines.join('\n')
|
|
71
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
2
3
|
|
|
3
4
|
import { CliLangEnum, normalizeCliLang } from './cli-lang.mjs'
|
|
4
5
|
import { ensureXrystalHome, resolveXrystalHome } from './xrystal-registry.mjs'
|
|
@@ -51,6 +52,31 @@ export function setCliConfigLang(lang) {
|
|
|
51
52
|
return normalized
|
|
52
53
|
}
|
|
53
54
|
|
|
55
|
+
export function getCliConfigInfraDir() {
|
|
56
|
+
const infraDir = readXrystalConfig().cli?.infraDir
|
|
57
|
+
if (!infraDir || typeof infraDir !== 'string') return null
|
|
58
|
+
const trimmed = infraDir.trim()
|
|
59
|
+
return trimmed || null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function setCliConfigInfraDir(infraDir) {
|
|
63
|
+
const resolved = path.resolve(String(infraDir ?? '').trim())
|
|
64
|
+
if (!fs.existsSync(resolved)) {
|
|
65
|
+
throw new Error(`Infra directory not found: ${resolved}`)
|
|
66
|
+
}
|
|
67
|
+
if (!fs.existsSync(path.join(resolved, 'scripts', 'helpers'))) {
|
|
68
|
+
throw new Error(`Not an -infrastructure- repo (missing scripts/helpers): ${resolved}`)
|
|
69
|
+
}
|
|
70
|
+
writeXrystalConfig({ cli: { infraDir: resolved } })
|
|
71
|
+
return resolved
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function clearCliConfigInfraDir() {
|
|
75
|
+
const current = readXrystalConfig()
|
|
76
|
+
const { infraDir: _removed, ...rest } = current.cli ?? {}
|
|
77
|
+
writeXrystalConfig({ cli: rest })
|
|
78
|
+
}
|
|
79
|
+
|
|
54
80
|
export function clearCliConfigLang() {
|
|
55
81
|
const current = readXrystalConfig()
|
|
56
82
|
const { lang: _removed, ...rest } = current.cli ?? {}
|