@xrystal/core 3.52.5 → 3.52.7
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 +2 -4
- package/x/bin/commands/project-info.mjs +94 -0
- package/x/bin/commands/projects.mjs +1 -1
- package/x/bin/commands/sync.mjs +67 -101
- package/x/bin/commands/tmp.mjs +12 -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 +43 -13
- package/x/bin/helpers/project-context.mjs +147 -0
- package/x/bin/helpers/scaffold-service.mjs +2 -3
- package/x/bin/helpers/sync-project.mjs +76 -0
- package/x/bin/helpers/sync-scope.mjs +71 -0
- package/x/bin/helpers/tmp-config.mjs +25 -0
- package/x/bin/helpers/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/loader/kafka/index.js +7 -2
- package/x/dist/loader/logger/index.js +8 -6
- package/x/dist/loader/mongo/index.js +9 -0
- package/x/dist/loader/redis/index.js +9 -0
- package/x/dist/project/index.d.ts +1 -0
- package/x/dist/project/index.js +21 -14
- package/x/dist/utils/constants/defaults.json +1 -0
- package/x/dist/utils/helpers/loader-options/index.d.ts +5 -0
- package/x/dist/utils/helpers/loader-options/index.js +16 -0
- package/x/dist/utils/helpers/tmp/index.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/index.js +1 -0
- package/x/dist/utils/helpers/tmp/loader-boot-plan.d.ts +10 -0
- package/x/dist/utils/helpers/tmp/loader-boot-plan.js +36 -0
- package/x/dist/utils/helpers/workspace/index.d.ts +1 -1
- package/x/dist/utils/helpers/workspace/index.js +2 -2
- package/x/templates/api-service/tmp.yml +7 -1
- package/x/templates/frontend/tmp.yml +61 -0
- package/x/tmp.yml +1 -1
- package/x/bin/helpers/tmp-end-version.mjs +0 -35
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
3
|
+
import chalk from 'chalk'
|
|
4
|
+
|
|
5
|
+
import { syncCliRuntime } from './project-artifacts.mjs'
|
|
6
|
+
import { syncCoreDependency } from './sync-core-dependency.mjs'
|
|
7
|
+
import { syncProjectToolchain } from './toolchain-config.mjs'
|
|
8
|
+
import { ensureTmpSchemaVersion } from './tmp-schema-version.mjs'
|
|
9
|
+
import { packageDefaults } from './package-defaults.mjs'
|
|
10
|
+
|
|
11
|
+
export function syncOneProject(entry, coreVersion, { dryRun = false, tmpPath = null } = {}) {
|
|
12
|
+
const label = entry.name ? `${entry.name} (${entry.type ?? 'project'})` : path.basename(entry.path)
|
|
13
|
+
const lines = []
|
|
14
|
+
|
|
15
|
+
if (dryRun) {
|
|
16
|
+
const preview = syncProjectToolchain(entry.path, { write: false })
|
|
17
|
+
lines.push({ level: 'gray', text: `would update ${preview.tsconfigRel ?? 'tsconfig.json'}` })
|
|
18
|
+
const core = syncCoreDependency(entry.path, coreVersion, { dryRun: true })
|
|
19
|
+
if (core.synced) {
|
|
20
|
+
lines.push({ level: 'gray', text: `would pin ${packageDefaults.packageName}@${coreVersion} (from ${core.current ?? core.declared})` })
|
|
21
|
+
} else if (core.reason === 'up-to-date') {
|
|
22
|
+
lines.push({ level: 'gray', text: `${packageDefaults.packageName}@${coreVersion} (ok)` })
|
|
23
|
+
} else if (core.reason === 'no core dependency') {
|
|
24
|
+
lines.push({ level: 'yellow', text: `skip core pin (${core.reason})` })
|
|
25
|
+
}
|
|
26
|
+
return { label, path: entry.path, lines, failed: false }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
syncCliRuntime(entry.path, { force: false })
|
|
31
|
+
const result = syncProjectToolchain(entry.path, { write: true })
|
|
32
|
+
lines.push({
|
|
33
|
+
level: 'green',
|
|
34
|
+
text: result.created
|
|
35
|
+
? `created ${result.tsconfigRel}`
|
|
36
|
+
: `updated ${result.tsconfigRel}`,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const core = syncCoreDependency(entry.path, coreVersion, { dryRun: false })
|
|
40
|
+
if (core.synced) {
|
|
41
|
+
lines.push({ level: 'green', text: `pinned ${packageDefaults.packageName}@${coreVersion}` })
|
|
42
|
+
} else if (core.reason === 'up-to-date') {
|
|
43
|
+
lines.push({ level: 'gray', text: `${packageDefaults.packageName}@${coreVersion} (ok)` })
|
|
44
|
+
} else if (core.reason === 'no core dependency') {
|
|
45
|
+
lines.push({ level: 'yellow', text: `skip core pin (${core.reason})` })
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (tmpPath) {
|
|
49
|
+
const schema = ensureTmpSchemaVersion(tmpPath)
|
|
50
|
+
if (schema.patched) {
|
|
51
|
+
lines.push({ level: 'green', text: `tmp end.version → ${schema.schemaVersion} (schema)` })
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { label, path: entry.path, lines, failed: false }
|
|
56
|
+
} catch (error) {
|
|
57
|
+
return {
|
|
58
|
+
label,
|
|
59
|
+
path: entry.path,
|
|
60
|
+
lines: [{ level: 'red', text: `failed: ${error.message}` }],
|
|
61
|
+
failed: true,
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function printSyncProjectResult(result) {
|
|
67
|
+
console.log(chalk.cyan(`\n→ ${result.label}`))
|
|
68
|
+
console.log(chalk.gray(` path: ${result.path}`))
|
|
69
|
+
for (const line of result.lines) {
|
|
70
|
+
const paint = line.level === 'green' ? chalk.green
|
|
71
|
+
: line.level === 'red' ? chalk.red
|
|
72
|
+
: line.level === 'yellow' ? chalk.yellow
|
|
73
|
+
: chalk.gray
|
|
74
|
+
console.log(` ${paint(line.text)}`)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { findEntries, findWorkspaceRoot } from './workspace-resolve.mjs'
|
|
4
|
+
import { resolveProjectRoot } from './project-root.mjs'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Resolve what `xry sync` should touch.
|
|
8
|
+
*
|
|
9
|
+
* | Context | default | --self | --all / --workspace |
|
|
10
|
+
* |--------------------|-----------|-------------|---------------------|
|
|
11
|
+
* | Standalone service | this repo | — | — |
|
|
12
|
+
* | Workspace root | all links | — | all links |
|
|
13
|
+
* | Inner service | this repo | this repo | all links + registry|
|
|
14
|
+
*/
|
|
15
|
+
export function resolveSyncScope(cwd = process.cwd(), options = {}) {
|
|
16
|
+
const resolvedCwd = path.resolve(cwd)
|
|
17
|
+
const workspaceRoot = findWorkspaceRoot(resolvedCwd)
|
|
18
|
+
const projectRoot = resolveProjectRoot(resolvedCwd)
|
|
19
|
+
const atWorkspaceRoot = workspaceRoot != null && path.resolve(workspaceRoot) === resolvedCwd
|
|
20
|
+
|
|
21
|
+
const wantAll = Boolean(options.all || options.workspace)
|
|
22
|
+
const wantSelf = Boolean(options.self)
|
|
23
|
+
|
|
24
|
+
if (wantAll && wantSelf) {
|
|
25
|
+
throw new Error('Use either --self or --all, not both')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!workspaceRoot) {
|
|
29
|
+
return {
|
|
30
|
+
mode: 'standalone',
|
|
31
|
+
label: 'standalone project',
|
|
32
|
+
targetRoot: projectRoot,
|
|
33
|
+
workspaceRoot: null,
|
|
34
|
+
entries: [{ path: projectRoot, name: path.basename(projectRoot), type: 'project' }],
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const entries = findEntries(workspaceRoot)
|
|
39
|
+
|
|
40
|
+
if (atWorkspaceRoot || wantAll) {
|
|
41
|
+
return {
|
|
42
|
+
mode: 'workspace-all',
|
|
43
|
+
label: wantAll && !atWorkspaceRoot ? 'workspace (all linked projects)' : 'workspace root',
|
|
44
|
+
targetRoot: workspaceRoot,
|
|
45
|
+
workspaceRoot,
|
|
46
|
+
entries,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (wantSelf) {
|
|
51
|
+
const self = entries.find((entry) => path.resolve(entry.path) === path.resolve(projectRoot))
|
|
52
|
+
return {
|
|
53
|
+
mode: 'self',
|
|
54
|
+
label: 'current linked project',
|
|
55
|
+
targetRoot: projectRoot,
|
|
56
|
+
workspaceRoot,
|
|
57
|
+
entries: self ? [self] : [{ path: projectRoot, name: path.basename(projectRoot), type: 'project' }],
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Inner service default: sync only this project (clear, predictable).
|
|
62
|
+
const self = entries.find((entry) => path.resolve(entry.path) === path.resolve(projectRoot))
|
|
63
|
+
return {
|
|
64
|
+
mode: 'self',
|
|
65
|
+
label: 'current linked project (default)',
|
|
66
|
+
targetRoot: projectRoot,
|
|
67
|
+
workspaceRoot,
|
|
68
|
+
entries: self ? [self] : [{ path: projectRoot, name: path.basename(projectRoot), type: 'project' }],
|
|
69
|
+
hintAll: `Run ${options.cliName ?? 'xry'} sync --all from here to sync every linked api/admin/web project`,
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -22,6 +22,22 @@ export function resolveProtocolsFromConfig(configs = {}) {
|
|
|
22
22
|
return (Array.isArray(raw) ? raw : [raw]).map(parseProtocolValue)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
function summarizeInfraLoaders(depends) {
|
|
26
|
+
const loaders = depends?.loaders ?? {}
|
|
27
|
+
const readEnabled = (key, fallback) => {
|
|
28
|
+
const opts = loaders?.[key]?.options
|
|
29
|
+
if (opts && typeof opts === 'object' && 'enabled' in opts) return opts.enabled !== false
|
|
30
|
+
return fallback
|
|
31
|
+
}
|
|
32
|
+
const type = depends?.globalType ?? null
|
|
33
|
+
const isFrontend = type === 'frontend'
|
|
34
|
+
return {
|
|
35
|
+
kafka: readEnabled('kafka', !isFrontend),
|
|
36
|
+
redis: readEnabled('redis', !isFrontend),
|
|
37
|
+
mongo: readEnabled('mongo', !isFrontend),
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
25
41
|
export function summarizeLoaders(tmp = {}) {
|
|
26
42
|
const configs = tmp.configs ?? {}
|
|
27
43
|
const global = readTmpGlobalBlock(configs)
|
|
@@ -29,8 +45,10 @@ export function summarizeLoaders(tmp = {}) {
|
|
|
29
45
|
|
|
30
46
|
return {
|
|
31
47
|
framework: global.framework ?? packageDefaults.framework,
|
|
48
|
+
globalType: global.type ?? '-',
|
|
32
49
|
protocols: resolveProtocolsFromConfig(depends),
|
|
33
50
|
project: tmp.project?.name ?? '-',
|
|
51
|
+
infra: summarizeInfraLoaders({ loaders: depends.loaders, globalType: global.type }),
|
|
34
52
|
items: [
|
|
35
53
|
depends.loaders?.dto && { key: 'dto', detail: formatLoaderDetail(depends.loaders?.dto) },
|
|
36
54
|
depends.loaders?.loggers && { key: 'loggers', detail: formatLoaderDetail(depends.loaders?.loggers) },
|
|
@@ -58,9 +76,16 @@ function formatLoaderDetail(obj) {
|
|
|
58
76
|
|
|
59
77
|
export function formatLoaderSummary(summary) {
|
|
60
78
|
const lines = [
|
|
79
|
+
`type: ${summary.globalType ?? '-'}`,
|
|
61
80
|
`framework: ${summary.framework}`,
|
|
62
81
|
`protocols: ${summary.protocols.join(', ')}`,
|
|
63
82
|
]
|
|
83
|
+
if (summary.infra) {
|
|
84
|
+
const flags = ['kafka', 'redis', 'mongo']
|
|
85
|
+
.map((key) => `${key}:${summary.infra[key] ? 'on' : 'off'}`)
|
|
86
|
+
.join(' · ')
|
|
87
|
+
lines.push(`infra: ${flags}`)
|
|
88
|
+
}
|
|
64
89
|
if (summary.project) lines.push(`project: ${summary.project}`)
|
|
65
90
|
for (const item of summary.items) {
|
|
66
91
|
lines.push(`${item.key}: ${item.detail}`)
|
|
@@ -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)
|
|
@@ -2,7 +2,7 @@ export { resolveKafkaJsSsl } from './resolve-ssl.js';
|
|
|
2
2
|
import { Kafka as KafkaClient, logLevel } from "kafkajs";
|
|
3
3
|
import { bindLoaderTmpSync } from '../../utils/helpers/tmp/loader-tmp-sync.js';
|
|
4
4
|
import { resolveKafkaJsSsl } from './resolve-ssl.js';
|
|
5
|
-
import { readKafkaLoaderOptions } from '../../utils/helpers/
|
|
5
|
+
import { readKafkaLoaderOptions } from '../../utils/helpers/loader-options/index.js';
|
|
6
6
|
export default class KafkaForCore {
|
|
7
7
|
_instance;
|
|
8
8
|
_producer;
|
|
@@ -23,13 +23,18 @@ export default class KafkaForCore {
|
|
|
23
23
|
await this.syncFromTmp();
|
|
24
24
|
bindLoaderTmpSync(this);
|
|
25
25
|
};
|
|
26
|
+
#resolveDependsLoaders = () => {
|
|
27
|
+
const configs = this.#system?.tmp?.configs;
|
|
28
|
+
return configs?.depends?.loaders ?? configs?.service?.loaders;
|
|
29
|
+
};
|
|
26
30
|
syncFromTmp = async () => {
|
|
27
31
|
await this.teardownKafka();
|
|
28
32
|
this.clientId = this.#configs.all?.kafkaClientId;
|
|
29
33
|
this.brokers = this.#configs.all?.kafkaBrokers;
|
|
30
34
|
this.username = this.#configs.all?.kafkaUsername;
|
|
31
35
|
this.password = this.#configs.all?.kafkaPassword;
|
|
32
|
-
const
|
|
36
|
+
const loaders = this.#resolveDependsLoaders();
|
|
37
|
+
const kafkaOpts = readKafkaLoaderOptions(loaders);
|
|
33
38
|
if (!kafkaOpts.enabled) {
|
|
34
39
|
return;
|
|
35
40
|
}
|
|
@@ -60,13 +60,15 @@ export default class Logger {
|
|
|
60
60
|
};
|
|
61
61
|
syncFromTmp = async () => {
|
|
62
62
|
await this.teardownLogger();
|
|
63
|
-
|
|
63
|
+
const configs = this.#system?.tmp?.configs;
|
|
64
|
+
const loaders = configs?.depends?.loaders ?? configs?.service?.loaders;
|
|
65
|
+
this.serviceName = configs?.deploymentName ?? configs?.service?.name ?? '';
|
|
64
66
|
this.kafkaLogsTopic = this.#configs?.all?.kafkaLogsTopic;
|
|
65
67
|
winston.addColors(customColors);
|
|
66
|
-
const loggersConfigs =
|
|
68
|
+
const loggersConfigs = (loaders?.loggers ?? {});
|
|
67
69
|
const { kafkaBrokers } = this.#configs.all;
|
|
68
70
|
const brokers = kafkaBrokers ? String(kafkaBrokers).split(',').map((b) => b.trim()) : [];
|
|
69
|
-
const kafkaOpts = readKafkaLoaderOptions(
|
|
71
|
+
const kafkaOpts = readKafkaLoaderOptions(loaders);
|
|
70
72
|
const isKafkaLogEnabled = kafkaOpts.enabled && kafkaOpts.queueLogEnabled && brokers.length > 0;
|
|
71
73
|
if (isKafkaLogEnabled && this.#kafka.instance) {
|
|
72
74
|
this.kafkaProducer = this.#kafka.instance.producer({
|
|
@@ -81,9 +83,9 @@ export default class Logger {
|
|
|
81
83
|
this.isKafkaReady = false;
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
|
-
const logPath = loggersConfigs
|
|
85
|
-
const loggerLevel = loggersConfigs
|
|
86
|
-
const queueLogLevel = normalizeLoggerLayer(loggersConfigs
|
|
86
|
+
const logPath = String(loggersConfigs.loadPath ?? 'logs');
|
|
87
|
+
const loggerLevel = String(loggersConfigs.logLevel ?? loggersConfigs.loggerLevel ?? 'info');
|
|
88
|
+
const queueLogLevel = normalizeLoggerLayer((loggersConfigs.queueLogLevel ?? loggersConfigs.kafkaLogLevel), LoggerLayerEnum.WARN);
|
|
87
89
|
this.queueLogLevel = queueLogLevel;
|
|
88
90
|
this.winstonLoader({
|
|
89
91
|
loadPath: path.join(this.#configs.all.rootFolderPath, logPath),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { resolveMongoConnectOptions } from './resolve-connect.js';
|
|
2
2
|
import { MongoClient } from 'mongodb';
|
|
3
3
|
import { bindLoaderTmpSync } from '../../utils/helpers/tmp/loader-tmp-sync.js';
|
|
4
|
+
import { readInfraLoaderEnabled } from '../../utils/helpers/loader-options/index.js';
|
|
4
5
|
import { resolveMongoConnectOptions } from './resolve-connect.js';
|
|
5
6
|
export default class MongoForCore {
|
|
6
7
|
#client = null;
|
|
@@ -18,8 +19,16 @@ export default class MongoForCore {
|
|
|
18
19
|
await this.syncFromTmp();
|
|
19
20
|
bindLoaderTmpSync(this);
|
|
20
21
|
};
|
|
22
|
+
#resolveDependsLoaders = () => {
|
|
23
|
+
const configs = this.#system?.tmp?.configs;
|
|
24
|
+
return configs?.depends?.loaders ?? configs?.service?.loaders;
|
|
25
|
+
};
|
|
21
26
|
syncFromTmp = async () => {
|
|
22
27
|
await this.teardown();
|
|
28
|
+
const loaders = this.#resolveDependsLoaders();
|
|
29
|
+
if (!readInfraLoaderEnabled(loaders, 'mongo', true)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
23
32
|
if (this.#configs.all.isMongoPassive) {
|
|
24
33
|
return;
|
|
25
34
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { resolveRedisSocketOptions } from './resolve-socket.js';
|
|
2
2
|
import { createClient } from 'redis';
|
|
3
3
|
import { bindLoaderTmpSync } from '../../utils/helpers/tmp/loader-tmp-sync.js';
|
|
4
|
+
import { readInfraLoaderEnabled } from '../../utils/helpers/loader-options/index.js';
|
|
4
5
|
import { resolveRedisSocketOptions } from './resolve-socket.js';
|
|
5
6
|
export default class RedisForCore {
|
|
6
7
|
#client = null;
|
|
@@ -17,8 +18,16 @@ export default class RedisForCore {
|
|
|
17
18
|
await this.syncFromTmp();
|
|
18
19
|
bindLoaderTmpSync(this);
|
|
19
20
|
};
|
|
21
|
+
#resolveDependsLoaders = () => {
|
|
22
|
+
const configs = this.#system?.tmp?.configs;
|
|
23
|
+
return configs?.depends?.loaders ?? configs?.service?.loaders;
|
|
24
|
+
};
|
|
20
25
|
syncFromTmp = async () => {
|
|
21
26
|
await this.teardown();
|
|
27
|
+
const loaders = this.#resolveDependsLoaders();
|
|
28
|
+
if (!readInfraLoaderEnabled(loaders, 'redis', true)) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
22
31
|
if (this.#configs.all.isRedisPassive) {
|
|
23
32
|
return;
|
|
24
33
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { ensureCoreTmpEntry, isCorePackageRoot } from '../utils/helpers/core/tmp-layout';
|
|
2
2
|
export { getTmpSnapshot } from '../utils/helpers/tmp/tmp-loader';
|
|
3
|
+
export { resolveLoaderBootPlan } from '../utils/helpers/tmp/loader-boot-plan';
|
|
3
4
|
export declare const core: {
|
|
4
5
|
_: Record<string, unknown>;
|
|
5
6
|
};
|
package/x/dist/project/index.js
CHANGED
|
@@ -4,8 +4,11 @@ import { System, Configs, Logger, Events, Localizations, DtoRuntime, Clients, Co
|
|
|
4
4
|
import { Constants, getCore, x } from '../utils/index.js';
|
|
5
5
|
import { ensureCoreTmpEntry, isCorePackageRoot } from '../utils/helpers/core/tmp-layout.js';
|
|
6
6
|
import { getTmpSnapshot } from '../utils/helpers/tmp/tmp-loader.js';
|
|
7
|
+
import { resolveLoaderBootPlan } from '../utils/helpers/tmp/loader-boot-plan.js';
|
|
8
|
+
import { resolveTmpRuntimeConfigs } from '../utils/helpers/tmp/tmp-schema.js';
|
|
7
9
|
export { ensureCoreTmpEntry, isCorePackageRoot } from '../utils/helpers/core/tmp-layout.js';
|
|
8
10
|
export { getTmpSnapshot } from '../utils/helpers/tmp/tmp-loader.js';
|
|
11
|
+
export { resolveLoaderBootPlan } from '../utils/helpers/tmp/loader-boot-plan.js';
|
|
9
12
|
export const core = getCore();
|
|
10
13
|
export const coreInit = async (params) => {
|
|
11
14
|
const { locales } = params;
|
|
@@ -16,29 +19,33 @@ let coreHasRun = false;
|
|
|
16
19
|
const projectModuleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
17
20
|
const loaderGlob = path.join(projectModuleDir, '..', 'loader', '**/*.{ts,js}');
|
|
18
21
|
const loaderExcludeGlob = path.join(projectModuleDir, '..', 'utils', '**/class.x.{ts,js}');
|
|
22
|
+
function buildLoaderInitList(plan, coreRef) {
|
|
23
|
+
const entries = [
|
|
24
|
+
{ service: System, props: { core: coreRef } },
|
|
25
|
+
{ service: Configs, props: {} },
|
|
26
|
+
];
|
|
27
|
+
if (plan.kafka)
|
|
28
|
+
entries.push({ service: KafkaForCore, props: {} });
|
|
29
|
+
if (plan.redis)
|
|
30
|
+
entries.push({ service: RedisForCore, props: {} });
|
|
31
|
+
if (plan.mongo)
|
|
32
|
+
entries.push({ service: MongoForCore, props: {} });
|
|
33
|
+
entries.push({ service: Logger, props: {} }, { service: Events, props: {} }, { service: Localizations, props: {} }, { service: DtoRuntime, props: {} }, { service: Controller, props: {} }, { service: Clients, props: {} });
|
|
34
|
+
return entries;
|
|
35
|
+
}
|
|
19
36
|
const coreLoader = async (_params = {}) => {
|
|
20
37
|
if (coreHasRun)
|
|
21
38
|
return core;
|
|
22
39
|
const root = process.cwd();
|
|
23
40
|
if (isCorePackageRoot(root))
|
|
24
41
|
ensureCoreTmpEntry(root);
|
|
25
|
-
getTmpSnapshot();
|
|
42
|
+
const snapshot = getTmpSnapshot();
|
|
43
|
+
const runtimeConfigs = resolveTmpRuntimeConfigs(snapshot);
|
|
44
|
+
const plan = resolveLoaderBootPlan(runtimeConfigs);
|
|
26
45
|
try {
|
|
27
46
|
await (await x.load([loaderGlob], {
|
|
28
47
|
exclude: [loaderExcludeGlob],
|
|
29
|
-
})).initialize(
|
|
30
|
-
{ service: System, props: { core } },
|
|
31
|
-
{ service: Configs, props: {} },
|
|
32
|
-
{ service: KafkaForCore, props: {} },
|
|
33
|
-
{ service: RedisForCore, props: {} },
|
|
34
|
-
{ service: MongoForCore, props: {} },
|
|
35
|
-
{ service: Logger, props: {} },
|
|
36
|
-
{ service: Events, props: {} },
|
|
37
|
-
{ service: Localizations, props: {} },
|
|
38
|
-
{ service: DtoRuntime, props: {} },
|
|
39
|
-
{ service: Controller, props: {} },
|
|
40
|
-
{ service: Clients, props: {} },
|
|
41
|
-
]);
|
|
48
|
+
})).initialize(buildLoaderInitList(plan, core));
|
|
42
49
|
coreHasRun = true;
|
|
43
50
|
return core;
|
|
44
51
|
}
|
|
@@ -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",
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type InfraLoaderOptions = {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
};
|
|
4
|
+
export declare function readInfraLoaderEnabled(loaders: Record<string, unknown> | undefined, key: string, defaultEnabled: boolean): boolean;
|
|
5
|
+
export { readKafkaLoaderOptions, type KafkaLoaderOptions } from '../../../utils/helpers/kafka-loader-options';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function readOptionsBlock(loaders, key) {
|
|
2
|
+
const block = loaders?.[key];
|
|
3
|
+
if (typeof block !== 'object' || block === null)
|
|
4
|
+
return {};
|
|
5
|
+
const options = block.options;
|
|
6
|
+
if (typeof options !== 'object' || options === null)
|
|
7
|
+
return {};
|
|
8
|
+
return options;
|
|
9
|
+
}
|
|
10
|
+
export function readInfraLoaderEnabled(loaders, key, defaultEnabled) {
|
|
11
|
+
const options = readOptionsBlock(loaders, key);
|
|
12
|
+
if ('enabled' in options)
|
|
13
|
+
return options.enabled !== false;
|
|
14
|
+
return defaultEnabled;
|
|
15
|
+
}
|
|
16
|
+
export { readKafkaLoaderOptions } from '../../../utils/helpers/kafka-loader-options/index.js';
|
|
@@ -2,6 +2,7 @@ export { setRuntimeTmpConfigs, getRuntimeTmpConfigs, onRuntimeTmpChange, notifyR
|
|
|
2
2
|
export { getTmpLoader, getTmpLoaderPath, getTmpSnapshot, onTmpReload, resetTmpLoaderForTests, stopTmpLoader, } from '../../../utils/helpers/tmp/tmp-loader';
|
|
3
3
|
export { bindLoaderTmpSync, type ITmpSyncLoader, } from '../../../utils/helpers/tmp/loader-tmp-sync';
|
|
4
4
|
export { resolveTmpWatchIntervalMs } from '../../../utils/helpers/tmp/tmp-watch';
|
|
5
|
+
export { resolveLoaderBootPlan, type LoaderBootPlan, type LoaderBootProfile, } from '../../../utils/helpers/tmp/loader-boot-plan';
|
|
5
6
|
export { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, normalizeRuntime, normalizeBundler, resolveEffectiveBundler, readTmpDependsBlock, readTmpBuildBlock, readTmpGlobalBlock, assertNoLegacyTmpKeys, resolveTmpDeploymentName, readTmpGlobalPathsBlock, applyTmpGlobalVars, resolveMergedPaths, resolveTmpRuntimeConfigs, resolveProjectRootFromTmpPath, resolveTmpAbsPath, normalizeGlobalType, } from '../../../utils/helpers/tmp/tmp-schema';
|
|
6
7
|
export { loadSeedFromBundledTmp, seedFromTmp, type SeedFromTmp, } from '../../../utils/helpers/tmp/seed-from-tmp';
|
|
7
8
|
export { normalizeLayoutPaths, type LayoutPaths, } from '../../../utils/helpers/tmp/path-normalize';
|
|
@@ -2,6 +2,7 @@ export { setRuntimeTmpConfigs, getRuntimeTmpConfigs, onRuntimeTmpChange, notifyR
|
|
|
2
2
|
export { getTmpLoader, getTmpLoaderPath, getTmpSnapshot, onTmpReload, resetTmpLoaderForTests, stopTmpLoader, } from '../../../utils/helpers/tmp/tmp-loader.js';
|
|
3
3
|
export { bindLoaderTmpSync, } from '../../../utils/helpers/tmp/loader-tmp-sync.js';
|
|
4
4
|
export { resolveTmpWatchIntervalMs } from '../../../utils/helpers/tmp/tmp-watch.js';
|
|
5
|
+
export { resolveLoaderBootPlan, } from '../../../utils/helpers/tmp/loader-boot-plan.js';
|
|
5
6
|
export { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, normalizeRuntime, normalizeBundler, resolveEffectiveBundler, readTmpDependsBlock, readTmpBuildBlock, readTmpGlobalBlock, assertNoLegacyTmpKeys, resolveTmpDeploymentName, readTmpGlobalPathsBlock, applyTmpGlobalVars, resolveMergedPaths, resolveTmpRuntimeConfigs, resolveProjectRootFromTmpPath, resolveTmpAbsPath, normalizeGlobalType, } from '../../../utils/helpers/tmp/tmp-schema.js';
|
|
6
7
|
export { loadSeedFromBundledTmp, seedFromTmp, } from '../../../utils/helpers/tmp/seed-from-tmp.js';
|
|
7
8
|
export { normalizeLayoutPaths, } from '../../../utils/helpers/tmp/path-normalize.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TmpRuntimeConfigs } from '../../../utils/helpers/tmp/tmp-schema';
|
|
2
|
+
export type LoaderBootProfile = 'api-service' | 'frontend' | 'workspace' | 'minimal';
|
|
3
|
+
export type LoaderBootPlan = {
|
|
4
|
+
profile: LoaderBootProfile;
|
|
5
|
+
projectType: string | undefined;
|
|
6
|
+
kafka: boolean;
|
|
7
|
+
redis: boolean;
|
|
8
|
+
mongo: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function resolveLoaderBootPlan(configs?: TmpRuntimeConfigs | null): LoaderBootPlan;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { GlobalTypeEnum } from '../../../utils/models/enums/index.js';
|
|
2
|
+
import { readInfraLoaderEnabled, readKafkaLoaderOptions } from '../../../utils/helpers/loader-options/index.js';
|
|
3
|
+
function loadersBlock(configs) {
|
|
4
|
+
const loaders = configs?.depends?.loaders;
|
|
5
|
+
return typeof loaders === 'object' && loaders !== null ? loaders : undefined;
|
|
6
|
+
}
|
|
7
|
+
export function resolveLoaderBootPlan(configs) {
|
|
8
|
+
const type = configs?.global?.type;
|
|
9
|
+
const loaders = loadersBlock(configs);
|
|
10
|
+
if (type === GlobalTypeEnum.FRONTEND) {
|
|
11
|
+
return {
|
|
12
|
+
profile: 'frontend',
|
|
13
|
+
projectType: type,
|
|
14
|
+
kafka: readInfraLoaderEnabled(loaders, 'kafka', false),
|
|
15
|
+
redis: readInfraLoaderEnabled(loaders, 'redis', false),
|
|
16
|
+
mongo: readInfraLoaderEnabled(loaders, 'mongo', false),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (type === GlobalTypeEnum.WORKSPACE) {
|
|
20
|
+
return {
|
|
21
|
+
profile: 'workspace',
|
|
22
|
+
projectType: type,
|
|
23
|
+
kafka: false,
|
|
24
|
+
redis: false,
|
|
25
|
+
mongo: false,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const kafkaOpts = readKafkaLoaderOptions(loaders);
|
|
29
|
+
return {
|
|
30
|
+
profile: type === GlobalTypeEnum.API_SERVICE ? 'api-service' : 'minimal',
|
|
31
|
+
projectType: type ?? GlobalTypeEnum.API_SERVICE,
|
|
32
|
+
kafka: kafkaOpts.enabled,
|
|
33
|
+
redis: readInfraLoaderEnabled(loaders, 'redis', true),
|
|
34
|
+
mongo: readInfraLoaderEnabled(loaders, 'mongo', true),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -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
|
}
|