@xrystal/core 3.55.4 → 3.55.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/package.json +1 -1
- package/x/bin/commands/config.mjs +38 -0
- package/x/bin/commands/project.mjs +24 -9
- package/x/bin/commands/telepresence.mjs +10 -9
- package/x/bin/helpers/build-config.mjs +30 -0
- package/x/bin/helpers/resolve-infra-helper.mjs +61 -12
- package/x/bin/helpers/xrystal-config.mjs +26 -0
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
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execSync } from 'node:child_process'
|
|
1
|
+
import { execSync, spawnSync } from 'node:child_process'
|
|
2
2
|
import fs from 'node:fs'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import chalk from 'chalk'
|
|
@@ -8,7 +8,10 @@ import {
|
|
|
8
8
|
isCorePackageName,
|
|
9
9
|
readTmpBuildContext,
|
|
10
10
|
resolveCoreBuildSteps,
|
|
11
|
+
buildRuntimeStartArgv,
|
|
12
|
+
buildRuntimeWatchArgv,
|
|
11
13
|
resolveDevEntry,
|
|
14
|
+
resolveDevEnvFileNames,
|
|
12
15
|
resolveDistEntryAbs,
|
|
13
16
|
resolveEnvFiles,
|
|
14
17
|
resolvePackageScriptRunner,
|
|
@@ -28,6 +31,12 @@ function runInProject(root, command) {
|
|
|
28
31
|
execSync(command, { cwd: root, stdio: 'inherit', env: process.env })
|
|
29
32
|
}
|
|
30
33
|
|
|
34
|
+
function runRunner(root, runner, argv) {
|
|
35
|
+
const result = spawnSync(runner, argv, { cwd: root, stdio: 'inherit', env: process.env })
|
|
36
|
+
if (result.error) throw result.error
|
|
37
|
+
if (result.status !== 0) process.exit(result.status ?? 1)
|
|
38
|
+
}
|
|
39
|
+
|
|
31
40
|
function resolveTestTarget(root) {
|
|
32
41
|
const layout = ensureTmpFile(root).layout
|
|
33
42
|
if (fs.existsSync(layout.pathsAbs.tests)) {
|
|
@@ -46,15 +55,22 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
|
|
|
46
55
|
runWithServiceRoot((root) => {
|
|
47
56
|
const { layout, runtime } = readTmpBuildContext(root)
|
|
48
57
|
const entry = resolveDevEntry(root, layout)
|
|
49
|
-
const envFiles = resolveEnvFiles(
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
const envFiles = resolveEnvFiles(
|
|
59
|
+
layout.pathsAbs.environments,
|
|
60
|
+
resolveDevEnvFileNames(layout.pathsAbs.environments),
|
|
61
|
+
)
|
|
62
|
+
const { runner, argv } = buildRuntimeWatchArgv(runtime, entry, envFiles)
|
|
52
63
|
|
|
53
64
|
printCommandHeader({ cliName, command: 'dev', version: readCliPackageJson().version })
|
|
54
65
|
console.log(chalk.gray(` root: ${root}`))
|
|
55
66
|
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
56
|
-
console.log(chalk.gray(` entry: ${entry} (.ts)
|
|
57
|
-
|
|
67
|
+
console.log(chalk.gray(` entry: ${entry} (.ts)`))
|
|
68
|
+
if (envFiles.length) {
|
|
69
|
+
console.log(chalk.gray(` env: ${envFiles.map((f) => path.relative(root, f)).join(' · ')}\n`))
|
|
70
|
+
} else {
|
|
71
|
+
console.log('')
|
|
72
|
+
}
|
|
73
|
+
runRunner(root, runner, argv)
|
|
58
74
|
}, { cliName, command: 'dev' })
|
|
59
75
|
})
|
|
60
76
|
|
|
@@ -116,14 +132,13 @@ export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}
|
|
|
116
132
|
|
|
117
133
|
const entry = relativeFromRoot(root, entryAbs)
|
|
118
134
|
const envFiles = resolveEnvFiles(layout.pathsAbs.environments, ['.global.env', '.prod.env'])
|
|
119
|
-
const
|
|
120
|
-
const runner = resolveRuntimeRunner(runtime)
|
|
135
|
+
const { runner, argv } = buildRuntimeStartArgv(runtime, entry, envFiles)
|
|
121
136
|
|
|
122
137
|
printCommandHeader({ cliName, command: 'start', version: readCliPackageJson().version })
|
|
123
138
|
console.log(chalk.gray(` root: ${root}`))
|
|
124
139
|
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
125
140
|
console.log(chalk.gray(` entry: ${entry} (.js)\n`))
|
|
126
|
-
|
|
141
|
+
runRunner(root, runner, argv)
|
|
127
142
|
}, { cliName, command: 'start' })
|
|
128
143
|
})
|
|
129
144
|
|
|
@@ -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,11 +133,11 @@ 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)
|
|
139
|
-
const localCmd = rest.length ? rest : ['
|
|
140
|
+
const localCmd = rest.length ? rest : ['xry', 'dev']
|
|
140
141
|
const args = [`NS=${ns}`, deployName, portArg, '--', ...localCmd]
|
|
141
142
|
|
|
142
143
|
runHelper(interceptScript, args, { cwd: svcDir })
|
|
@@ -463,6 +463,36 @@ export function resolveEnvFiles(envDir, names) {
|
|
|
463
463
|
.filter((file) => fs.existsSync(file))
|
|
464
464
|
}
|
|
465
465
|
|
|
466
|
+
/** Dev env load order — telepresence cluster env last when present. */
|
|
467
|
+
export function resolveDevEnvFileNames(envDir) {
|
|
468
|
+
const names = ['.global.env', '.dev.env']
|
|
469
|
+
if (fs.existsSync(path.join(envDir, '.env.telepresence'))) {
|
|
470
|
+
names.push('.env.telepresence')
|
|
471
|
+
}
|
|
472
|
+
return names
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function appendEnvFileArgs(argv, envFiles) {
|
|
476
|
+
for (const file of envFiles) {
|
|
477
|
+
argv.push('--env-file', file)
|
|
478
|
+
}
|
|
479
|
+
return argv
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export function buildRuntimeWatchArgv(runtime, entry, envFiles) {
|
|
483
|
+
const runner = resolveRuntimeRunner(runtime)
|
|
484
|
+
const argv = appendEnvFileArgs(['--watch'], envFiles)
|
|
485
|
+
argv.push(entry)
|
|
486
|
+
return { runner, argv }
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
export function buildRuntimeStartArgv(runtime, entry, envFiles) {
|
|
490
|
+
const runner = resolveRuntimeRunner(runtime)
|
|
491
|
+
const argv = appendEnvFileArgs([], envFiles)
|
|
492
|
+
argv.push(entry)
|
|
493
|
+
return { runner, argv }
|
|
494
|
+
}
|
|
495
|
+
|
|
466
496
|
|
|
467
497
|
export function resolveRuntimeRunner(runtime = detectCliHostRuntime()) {
|
|
468
498
|
return getRuntimeTooling(runtime).binRunner
|
|
@@ -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 ?? {}
|