@xrystal/core 3.51.6 → 3.52.0
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 +35 -1
- package/package.json +1 -1
- package/x/bin/commands/create.mjs +44 -0
- package/x/bin/commands/projects.mjs +53 -0
- package/x/bin/commands/sync.mjs +49 -1
- package/x/bin/commands/tmp.mjs +1 -1
- package/x/bin/helpers/.generated/.generated-from +2 -0
- package/x/bin/helpers/.generated/seed-from-tmp.mjs +25 -31
- package/x/bin/helpers/.generated/tmp-schema.mjs +156 -96
- package/x/bin/helpers/.generated/workspace.mjs +402 -0
- package/x/bin/helpers/.generated/xrystal-home-registry.mjs +310 -0
- package/x/bin/helpers/build-config.mjs +3 -2
- package/x/bin/helpers/cli-help.mjs +3 -1
- package/x/bin/helpers/project-artifacts.mjs +9 -0
- package/x/bin/helpers/tmp-config.mjs +13 -12
- package/x/bin/helpers/tmp-layout.mjs +28 -52
- package/x/bin/helpers/tmp-schema.mjs +9 -3
- package/x/bin/helpers/workspace-resolve.mjs +11 -0
- package/x/bin/helpers/workspace-scaffold.mjs +23 -0
- package/x/bin/helpers/xrystal-registry.mjs +13 -0
- package/x/bin/main-cli.js +2 -0
- package/x/dist/index.js +5 -1
- package/x/dist/loader/clients/index.js +22 -1
- package/x/dist/loader/configs/index.js +97 -1
- package/x/dist/loader/controller/index.js +267 -1
- package/x/dist/loader/dto/index.js +92 -1
- package/x/dist/loader/events/index.js +39 -1
- package/x/dist/loader/index.js +13 -1
- package/x/dist/loader/kafka/index.js +142 -1
- package/x/dist/loader/kafka/resolve-ssl.js +23 -1
- package/x/dist/loader/localizations/index.js +46 -1
- package/x/dist/loader/logger/index.js +229 -2
- package/x/dist/loader/mongo/index.js +52 -1
- package/x/dist/loader/mongo/resolve-connect.js +16 -1
- package/x/dist/loader/redis/index.js +57 -1
- package/x/dist/loader/redis/resolve-socket.js +31 -1
- package/x/dist/loader/registry/index.js +1 -1
- package/x/dist/loader/service/index.js +7 -1
- package/x/dist/loader/system/index.js +26 -1
- package/x/dist/project/index.js +51 -1
- package/x/dist/utils/constants/defaults.json +3 -1
- package/x/dist/utils/constants/index.d.ts +1 -0
- package/x/dist/utils/constants/index.js +42 -1
- package/x/dist/utils/constants/package-root.js +6 -1
- package/x/dist/utils/helpers/configs/index.js +1 -1
- package/x/dist/utils/helpers/context/controller-store.js +12 -1
- package/x/dist/utils/helpers/context/index.js +24 -1
- package/x/dist/utils/helpers/core/handlebars-resolve.js +15 -1
- package/x/dist/utils/helpers/core/index.js +46 -1
- package/x/dist/utils/helpers/core/paths.js +78 -1
- package/x/dist/utils/helpers/core/tmp-layout.d.ts +4 -4
- package/x/dist/utils/helpers/core/tmp-layout.js +229 -1
- package/x/dist/utils/helpers/date/index.js +48 -1
- package/x/dist/utils/helpers/dispatch/index.js +53 -1
- package/x/dist/utils/helpers/dto/index.js +10 -1
- package/x/dist/utils/helpers/filters/index.js +44 -1
- package/x/dist/utils/helpers/framework/index.js +18 -1
- package/x/dist/utils/helpers/handlers/adapters.js +41 -1
- package/x/dist/utils/helpers/handlers/execute.js +82 -1
- package/x/dist/utils/helpers/handlers/index.js +31 -1
- package/x/dist/utils/helpers/hash/crypto.js +22 -1
- package/x/dist/utils/helpers/id/index.js +24 -1
- package/x/dist/utils/helpers/index.d.ts +1 -0
- package/x/dist/utils/helpers/index.js +28 -1
- package/x/dist/utils/helpers/ip/index.js +21 -1
- package/x/dist/utils/helpers/is/index.js +35 -1
- package/x/dist/utils/helpers/kafka-loader-options/index.js +14 -1
- package/x/dist/utils/helpers/locales/index.js +82 -1
- package/x/dist/utils/helpers/logger-layer/index.js +33 -1
- package/x/dist/utils/helpers/math/index.js +14 -1
- package/x/dist/utils/helpers/middleware/index.js +36 -1
- package/x/dist/utils/helpers/node-env/index.js +20 -1
- package/x/dist/utils/helpers/objects/index.js +55 -1
- package/x/dist/utils/helpers/path/index.js +5 -1
- package/x/dist/utils/helpers/path/resolve-alias-path.d.ts +1 -1
- package/x/dist/utils/helpers/path/resolve-alias-path.js +62 -1
- package/x/dist/utils/helpers/protocol/index.d.ts +1 -1
- package/x/dist/utils/helpers/protocol/index.js +100 -1
- package/x/dist/utils/helpers/protocol/options.js +13 -1
- package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +3 -1
- package/x/dist/utils/helpers/registry/index.js +103 -1
- package/x/dist/utils/helpers/runtime/dto-access.js +5 -1
- package/x/dist/utils/helpers/runtime/dto-types.js +1 -1
- package/x/dist/utils/helpers/runtime/index.js +2 -1
- package/x/dist/utils/helpers/runtime/shutdown.js +36 -1
- package/x/dist/utils/helpers/state/index.js +185 -1
- package/x/dist/utils/helpers/state/props-from-tmp.js +46 -1
- package/x/dist/utils/helpers/state/request-key-guard.js +43 -1
- package/x/dist/utils/helpers/state/scopes.js +69 -1
- package/x/dist/utils/helpers/string/index.js +9 -1
- package/x/dist/utils/helpers/timer/index.js +5 -1
- package/x/dist/utils/helpers/tmp/index.d.ts +2 -2
- package/x/dist/utils/helpers/tmp/index.js +8 -1
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +14 -1
- package/x/dist/utils/helpers/tmp/path-normalize.js +27 -1
- package/x/dist/utils/helpers/tmp/runtime-tmp.js +42 -1
- package/x/dist/utils/helpers/tmp/seed-from-tmp.d.ts +2 -2
- package/x/dist/utils/helpers/tmp/seed-from-tmp.js +62 -1
- package/x/dist/utils/helpers/tmp/tmp-interpolate.js +22 -1
- package/x/dist/utils/helpers/tmp/tmp-loader.js +56 -1
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +35 -23
- package/x/dist/utils/helpers/tmp/tmp-schema.js +211 -1
- package/x/dist/utils/helpers/tmp/tmp-watch.js +23 -1
- package/x/dist/utils/helpers/tmp/toolchain-heal.js +157 -2
- package/x/dist/utils/helpers/validates/index.js +20 -1
- package/x/dist/utils/helpers/workspace/index.d.ts +42 -0
- package/x/dist/utils/helpers/workspace/index.js +222 -0
- package/x/dist/utils/helpers/xrystal-home/registry.d.ts +32 -0
- package/x/dist/utils/helpers/xrystal-home/registry.js +92 -0
- package/x/dist/utils/index.js +3 -1
- package/x/dist/utils/models/classes/class.clients.js +142 -1
- package/x/dist/utils/models/classes/class.interfaces.js +10 -1
- package/x/dist/utils/models/classes/class.service-locator.js +16 -1
- package/x/dist/utils/models/classes/class.tmp-file-loader.js +61 -1
- package/x/dist/utils/models/classes/class.x.js +181 -1
- package/x/dist/utils/models/enums/index.d.ts +9 -1
- package/x/dist/utils/models/enums/index.js +169 -1
- package/x/dist/utils/models/index.js +9 -1
- package/x/dist/utils/models/types/index.js +2 -1
- package/x/tmp.yml +7 -50
|
@@ -8,7 +8,8 @@ import { getRuntimeTooling, RuntimeEnum, BundlerEnum, detectCliHostRuntime } fro
|
|
|
8
8
|
import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
|
|
9
9
|
import {
|
|
10
10
|
normalizeTmpDocument,
|
|
11
|
-
|
|
11
|
+
readTmpDependsBlock,
|
|
12
|
+
readTmpBuildBlock,
|
|
12
13
|
readTmpGlobalBlock,
|
|
13
14
|
normalizeBundler,
|
|
14
15
|
resolveEffectiveBundler,
|
|
@@ -56,7 +57,7 @@ export function readTmpBuildContext(root) {
|
|
|
56
57
|
const ensured = ensureTmpFile(root)
|
|
57
58
|
const tmp = normalizeTmpDocument(yaml.parse(fs.readFileSync(ensured.tmpFilePath, 'utf8')))
|
|
58
59
|
const configs = tmp.configs ?? {}
|
|
59
|
-
const build =
|
|
60
|
+
const build = readTmpBuildBlock(configs)
|
|
60
61
|
const global = readTmpGlobalBlock(configs)
|
|
61
62
|
const bundler = resolveEffectiveBundler(normalizeBundler(build.bundler), global.runtime)
|
|
62
63
|
return { layout: ensured.layout, configs, build, global, runtime: global.runtime, bundler }
|
|
@@ -31,7 +31,8 @@ const COMMAND_GROUPS = [
|
|
|
31
31
|
{ cmd: 'tmp', desc: 'Ensure tmp.yml exists (runtime config seed)' },
|
|
32
32
|
{ cmd: 'hooks install', desc: 'Install .git/hooks pre-commit version check' },
|
|
33
33
|
{ cmd: 'hooks status', desc: 'Show whether pre-commit hook is installed' },
|
|
34
|
-
{ cmd: 'sync', desc: '
|
|
34
|
+
{ cmd: 'sync', desc: 'Sync tsconfig for project or all workspace entries' },
|
|
35
|
+
{ cmd: 'projects', desc: 'List ~/.xrystal registry (workspaces + linked projects)' },
|
|
35
36
|
],
|
|
36
37
|
},
|
|
37
38
|
{
|
|
@@ -121,6 +122,7 @@ export function formatRootHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
121
122
|
|
|
122
123
|
export function formatCreateHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
123
124
|
const examples = [
|
|
125
|
+
{ cmd: `${cliName} create demo --workspace`, desc: '→ workspace with api/admin/panel/web' },
|
|
124
126
|
{ cmd: `${cliName} create my-api`, desc: '→ ./my-api (current folder)' },
|
|
125
127
|
{ cmd: `${cliName} create my-api ..`, desc: '→ ../my-api' },
|
|
126
128
|
{ cmd: `${cliName} create my-api ~/services`, desc: '→ ~/services/my-api' },
|
|
@@ -19,6 +19,14 @@ function cliGeneratedModules() {
|
|
|
19
19
|
source: `${main}/utils/helpers/tmp/tmp-schema.ts`,
|
|
20
20
|
outfile: path.join(CLI_GENERATED_DIR, 'tmp-schema.mjs'),
|
|
21
21
|
},
|
|
22
|
+
{
|
|
23
|
+
source: `${main}/utils/helpers/xrystal-home/registry.ts`,
|
|
24
|
+
outfile: path.join(CLI_GENERATED_DIR, 'xrystal-home-registry.mjs'),
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
source: `${main}/utils/helpers/workspace/index.ts`,
|
|
28
|
+
outfile: path.join(CLI_GENERATED_DIR, 'workspace.mjs'),
|
|
29
|
+
},
|
|
22
30
|
{
|
|
23
31
|
source: `${main}/utils/helpers/tmp/seed-from-tmp.ts`,
|
|
24
32
|
outfile: path.join(CLI_GENERATED_DIR, 'seed-from-tmp.mjs'),
|
|
@@ -78,6 +86,7 @@ export function buildCorePackageExports(distPrefix) {
|
|
|
78
86
|
function corePublishFilesStatic() {
|
|
79
87
|
const root = packageDefaults.packageRootFolder
|
|
80
88
|
const tmpName = `${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`
|
|
89
|
+
const apiTemplateDir = "x/templates"
|
|
81
90
|
return [
|
|
82
91
|
`${root}/bin`,
|
|
83
92
|
`${root}/${tmpName}`,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readTmpDependsBlock, readTmpGlobalBlock } from './tmp-schema.mjs'
|
|
2
2
|
import { packageDefaults } from './package-defaults.mjs'
|
|
3
3
|
const PROTOCOL_ALIASES = {
|
|
4
4
|
http: 'http',
|
|
@@ -24,20 +24,21 @@ export function resolveProtocolsFromConfig(configs = {}) {
|
|
|
24
24
|
|
|
25
25
|
export function summarizeLoaders(tmp = {}) {
|
|
26
26
|
const configs = tmp.configs ?? {}
|
|
27
|
-
const
|
|
27
|
+
const global = readTmpGlobalBlock(configs)
|
|
28
|
+
const depends = configs.depends ?? readTmpDependsBlock(configs)
|
|
28
29
|
|
|
29
30
|
return {
|
|
30
|
-
framework:
|
|
31
|
-
protocols: resolveProtocolsFromConfig(
|
|
32
|
-
|
|
31
|
+
framework: global.framework ?? packageDefaults.framework,
|
|
32
|
+
protocols: resolveProtocolsFromConfig(depends),
|
|
33
|
+
project: tmp.project?.name ?? '-',
|
|
33
34
|
items: [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
depends.loaders?.dto && { key: 'dto', detail: formatLoaderDetail(depends.loaders?.dto) },
|
|
36
|
+
depends.loaders?.loggers && { key: 'loggers', detail: formatLoaderDetail(depends.loaders?.loggers) },
|
|
37
|
+
depends.loaders?.localization && { key: 'localization', detail: formatLoaderDetail(depends.loaders?.localization) },
|
|
38
|
+
depends.loaders?.configs && { key: 'configs', detail: formatLoaderDetail(depends.loaders?.configs) },
|
|
39
|
+
depends.loaders?.controller && Object.keys(depends.loaders?.controller).length > 0 && {
|
|
39
40
|
key: 'controller',
|
|
40
|
-
detail: formatLoaderDetail(
|
|
41
|
+
detail: formatLoaderDetail(depends.loaders?.controller),
|
|
41
42
|
},
|
|
42
43
|
].filter(Boolean),
|
|
43
44
|
}
|
|
@@ -60,7 +61,7 @@ export function formatLoaderSummary(summary) {
|
|
|
60
61
|
`framework: ${summary.framework}`,
|
|
61
62
|
`protocols: ${summary.protocols.join(', ')}`,
|
|
62
63
|
]
|
|
63
|
-
if (summary.
|
|
64
|
+
if (summary.project) lines.push(`project: ${summary.project}`)
|
|
64
65
|
for (const item of summary.items) {
|
|
65
66
|
lines.push(`${item.key}: ${item.detail}`)
|
|
66
67
|
}
|
|
@@ -5,7 +5,7 @@ import yaml from 'yaml'
|
|
|
5
5
|
import { packageDefaults } from '../paths.mjs'
|
|
6
6
|
import { findAllFilesRecursively, findFileRecursively } from './index.mjs'
|
|
7
7
|
import { getBundledCoreTmpPath } from './project-root.mjs'
|
|
8
|
-
import { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder,
|
|
8
|
+
import { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, resolveMergedPaths, resolveTmpAbsPath } from './tmp-schema.mjs'
|
|
9
9
|
|
|
10
10
|
function formatTmpTarget(name, ext) {
|
|
11
11
|
return `${name}${ext.startsWith('.') ? ext : `.${ext}`}`
|
|
@@ -49,8 +49,13 @@ export function assertCoreTmpGuard(projectRoot, tmpFilePath) {
|
|
|
49
49
|
function findStrayCoreTmpFiles(projectRoot, canonicalPath) {
|
|
50
50
|
const resolvedRoot = path.resolve(projectRoot)
|
|
51
51
|
const canonical = path.resolve(canonicalPath)
|
|
52
|
+
const templatesPrefix = `${packageDefaults.packageRootFolder}/templates/`
|
|
52
53
|
return findAllFilesRecursively(resolvedRoot, packageDefaults.tmpBaseName, packageDefaults.tmpExtension)
|
|
53
|
-
.filter((filePath) =>
|
|
54
|
+
.filter((filePath) => {
|
|
55
|
+
if (path.resolve(filePath) === canonical) return false
|
|
56
|
+
const rel = path.relative(resolvedRoot, filePath).replace(/\\/g, '/')
|
|
57
|
+
return !rel.startsWith(templatesPrefix)
|
|
58
|
+
})
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
export function ensureCoreTmpEntry(projectRoot = process.cwd(), options = {}) {
|
|
@@ -91,39 +96,17 @@ function resolveTmpFilePath(projectRoot, tmpFileName, ext) {
|
|
|
91
96
|
return findFileRecursively(resolvedRoot, tmpFileName, ext)
|
|
92
97
|
}
|
|
93
98
|
|
|
94
|
-
export function resolveRootFolderPath(tmp,
|
|
99
|
+
export function resolveRootFolderPath(tmp, _tmpFilePath, _projectRoot) {
|
|
95
100
|
const configs = normalizeTmpDocument(tmp ?? {}).configs ?? {}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (service.paths?.root?.trim()) {
|
|
99
|
-
return normalizeRootFolder(service.paths.root)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (typeof tmp?.project?.name === 'string' && tmp.project.name.trim()) {
|
|
103
|
-
return tmp.project.name.trim()
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const relativeDir = path.relative(
|
|
107
|
-
path.resolve(projectRoot),
|
|
108
|
-
path.dirname(path.resolve(tmpFilePath)),
|
|
109
|
-
)
|
|
110
|
-
if (relativeDir && relativeDir !== '.') {
|
|
111
|
-
return relativeDir
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return packageDefaults.packageRootFolder
|
|
101
|
+
return normalizeRootFolder(resolveMergedPaths(configs).root)
|
|
115
102
|
}
|
|
116
103
|
|
|
117
104
|
export function resolveLayoutPaths(configs) {
|
|
118
|
-
return
|
|
105
|
+
return resolveMergedPaths(configs).special
|
|
119
106
|
}
|
|
120
107
|
|
|
121
108
|
export function resolveMainFolderPath(configs) {
|
|
122
|
-
|
|
123
|
-
if (typeof source === 'string' && source.trim()) {
|
|
124
|
-
return normalizeSourceFolder(source)
|
|
125
|
-
}
|
|
126
|
-
return packageDefaults.mainSourceFolder
|
|
109
|
+
return normalizeSourceFolder(resolveMergedPaths(configs).source)
|
|
127
110
|
}
|
|
128
111
|
|
|
129
112
|
export function buildTmpLayout(projectRoot, tmp, tmpFilePath) {
|
|
@@ -183,7 +166,10 @@ export function resolveTmpLayoutOrDefaults(projectRoot = process.cwd()) {
|
|
|
183
166
|
return buildTmpLayout(projectRoot, readTmpFile(tmpFilePath), tmpFilePath)
|
|
184
167
|
}
|
|
185
168
|
|
|
186
|
-
export function ownerTmpFilePath(projectRoot = process.cwd(), layout) {
|
|
169
|
+
export function ownerTmpFilePath(projectRoot = process.cwd(), layout, configs) {
|
|
170
|
+
if (configs) {
|
|
171
|
+
return resolveTmpAbsPath(projectRoot, configs)
|
|
172
|
+
}
|
|
187
173
|
const resolved = layout ?? resolveTmpLayoutOrDefaults(projectRoot)
|
|
188
174
|
return path.join(
|
|
189
175
|
resolved.rootFolderAbs,
|
|
@@ -196,7 +182,7 @@ export function relativeFromRoot(projectRoot, absolutePath) {
|
|
|
196
182
|
return rel.startsWith('.') ? rel : `./${rel}`
|
|
197
183
|
}
|
|
198
184
|
|
|
199
|
-
export function ensureTmpFile(projectRoot = process.cwd(), {
|
|
185
|
+
export function ensureTmpFile(projectRoot = process.cwd(), { patchProjectName = true, templatePath } = {}) {
|
|
200
186
|
const resolvedRoot = path.resolve(projectRoot)
|
|
201
187
|
|
|
202
188
|
if (isCorePackageRoot(resolvedRoot)) {
|
|
@@ -233,38 +219,28 @@ export function ensureTmpFile(projectRoot = process.cwd(), { patchServiceName =
|
|
|
233
219
|
}
|
|
234
220
|
}
|
|
235
221
|
|
|
236
|
-
const
|
|
237
|
-
if (!fs.existsSync(
|
|
222
|
+
const resolvedTemplate = templatePath ?? getBundledCoreTmpPath()
|
|
223
|
+
if (!fs.existsSync(resolvedTemplate)) {
|
|
238
224
|
throw new Error(`${packageDefaults.packageName} bundled ${packageDefaults.packageRootFolder}/tmp.yml not found in package`)
|
|
239
225
|
}
|
|
240
226
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const targetPath =
|
|
245
|
-
|
|
246
|
-
formatTmpTarget(packageDefaults.tmpBaseName, packageDefaults.tmpExtension),
|
|
247
|
-
)
|
|
227
|
+
let content = fs.readFileSync(resolvedTemplate, 'utf8')
|
|
228
|
+
const templateDoc = readTmpFile(resolvedTemplate)
|
|
229
|
+
const templateConfigs = templateDoc.configs ?? {}
|
|
230
|
+
const targetPath = ownerTmpFilePath(resolvedRoot, undefined, templateConfigs)
|
|
231
|
+
fs.mkdirSync(path.dirname(targetPath), { recursive: true })
|
|
248
232
|
|
|
249
|
-
|
|
250
|
-
if (patchServiceName) {
|
|
233
|
+
if (patchProjectName) {
|
|
251
234
|
try {
|
|
252
235
|
const pkgPath = path.join(resolvedRoot, 'package.json')
|
|
253
236
|
if (fs.existsSync(pkgPath)) {
|
|
254
237
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
255
|
-
const
|
|
256
|
-
? pkg.name.replace(/^@/, '').replace(/\//g, '-')
|
|
238
|
+
const projectName = typeof pkg.name === 'string'
|
|
239
|
+
? pkg.name.replace(/^@/, '').replace(/\//g, '-').replace(/-svc$/, '')
|
|
257
240
|
: null
|
|
258
|
-
if (
|
|
241
|
+
if (projectName) {
|
|
259
242
|
const tmp = yaml.parse(content)
|
|
260
|
-
|
|
261
|
-
const service = configs.service
|
|
262
|
-
if (typeof service === 'object' && service !== null && !Array.isArray(service)) {
|
|
263
|
-
service.name = serviceName
|
|
264
|
-
} else {
|
|
265
|
-
configs.service = { name: serviceName }
|
|
266
|
-
}
|
|
267
|
-
tmp.configs = configs
|
|
243
|
+
tmp.project = { name: projectName }
|
|
268
244
|
content = yaml.stringify(tmp)
|
|
269
245
|
}
|
|
270
246
|
}
|
|
@@ -4,11 +4,17 @@ export {
|
|
|
4
4
|
normalizeTmpDocument,
|
|
5
5
|
normalizeRuntime,
|
|
6
6
|
normalizeBundler,
|
|
7
|
+
normalizeGlobalType,
|
|
7
8
|
resolveEffectiveBundler,
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
readTmpDependsBlock,
|
|
10
|
+
readTmpBuildBlock,
|
|
10
11
|
readTmpGlobalBlock,
|
|
12
|
+
assertNoLegacyTmpKeys,
|
|
13
|
+
resolveTmpDeploymentName,
|
|
14
|
+
readTmpGlobalPathsBlock,
|
|
11
15
|
applyTmpGlobalVars,
|
|
12
|
-
|
|
16
|
+
resolveMergedPaths,
|
|
13
17
|
resolveTmpRuntimeConfigs,
|
|
18
|
+
resolveProjectRootFromTmpPath,
|
|
19
|
+
resolveTmpAbsPath,
|
|
14
20
|
} from './.generated/tmp-schema.mjs'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { DEFAULT_FOLDER_STRUCTURE, workspaceTmpTemplate } from './workspace-resolve.mjs'
|
|
5
|
+
|
|
6
|
+
export function scaffoldWorkspace(targetPath, projectName) {
|
|
7
|
+
const resolved = path.resolve(targetPath)
|
|
8
|
+
fs.mkdirSync(resolved, { recursive: true })
|
|
9
|
+
|
|
10
|
+
const tmpPath = path.join(resolved, 'tmp.yml')
|
|
11
|
+
if (fs.existsSync(tmpPath)) {
|
|
12
|
+
throw new Error(`workspace tmp.yml already exists: ${tmpPath}`)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
fs.writeFileSync(tmpPath, workspaceTmpTemplate(projectName))
|
|
16
|
+
fs.writeFileSync(path.join(resolved, '.gitignore'), '.env.telepresence\n.env.local\n.env.private\n')
|
|
17
|
+
|
|
18
|
+
for (const dir of Object.values(DEFAULT_FOLDER_STRUCTURE)) {
|
|
19
|
+
fs.mkdirSync(path.join(resolved, dir), { recursive: true })
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return { root: resolved, tmpPath }
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export {
|
|
2
|
+
ensureXrystalHome,
|
|
3
|
+
entryToRegistryProject,
|
|
4
|
+
listRegistryProjects,
|
|
5
|
+
readRegistry,
|
|
6
|
+
registryFilePath,
|
|
7
|
+
resolveXrystalHome,
|
|
8
|
+
scanWorkspace,
|
|
9
|
+
syncRegistryFromPath,
|
|
10
|
+
upsertWorkspace,
|
|
11
|
+
writeRegistry,
|
|
12
|
+
XRYSTAL_HOME_DIR,
|
|
13
|
+
} from './.generated/xrystal-home-registry.mjs'
|
package/x/bin/main-cli.js
CHANGED
|
@@ -8,6 +8,7 @@ import { registerDoctorCommand } from './commands/doctor.mjs'
|
|
|
8
8
|
import { registerProjectCommands } from './commands/project.mjs'
|
|
9
9
|
import { registerTmpCommand } from './commands/tmp.mjs'
|
|
10
10
|
import { registerSyncCommand } from './commands/sync.mjs'
|
|
11
|
+
import { registerProjectsCommand } from './commands/projects.mjs'
|
|
11
12
|
import { registerTagCommand, registerVersionCommand } from './commands/release.mjs'
|
|
12
13
|
import { registerHooksCommand } from './commands/hooks.mjs'
|
|
13
14
|
import { printBanner, shouldShowBanner } from './helpers/banner.mjs'
|
|
@@ -66,6 +67,7 @@ registerTagCommand(cli, cliContext)
|
|
|
66
67
|
registerDoctorCommand(cli, cliContext)
|
|
67
68
|
registerTmpCommand(cli, cliContext)
|
|
68
69
|
registerSyncCommand(cli, cliContext)
|
|
70
|
+
registerProjectsCommand(cli, cliContext)
|
|
69
71
|
registerHooksCommand(cli, cliContext)
|
|
70
72
|
registerProjectCommands(cli, cliContext)
|
|
71
73
|
|
package/x/dist/index.js
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
import{BaseApiClient
|
|
1
|
+
import { BaseApiClient, CoreClientsEnum } from "../../utils/index.js";
|
|
2
|
+
import { bindLoaderTmpSync } from '../../utils/index.js';
|
|
3
|
+
export default class Clients {
|
|
4
|
+
_instances = {};
|
|
5
|
+
#configs;
|
|
6
|
+
constructor({ configs }) {
|
|
7
|
+
this.#configs = configs;
|
|
8
|
+
}
|
|
9
|
+
async onInit() {
|
|
10
|
+
await this.syncFromTmp();
|
|
11
|
+
bindLoaderTmpSync(this);
|
|
12
|
+
}
|
|
13
|
+
syncFromTmp = async () => {
|
|
14
|
+
this._instances[CoreClientsEnum.BASE_API_CLIENT] = new BaseApiClient({
|
|
15
|
+
clientName: CoreClientsEnum.BASE_API_CLIENT,
|
|
16
|
+
baseURL: this.#configs.all.baseApiUri || '',
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
get instances() {
|
|
20
|
+
return this._instances;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1 +1,97 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { Constants } from '../../utils/constants/index.js';
|
|
5
|
+
import { resolveTmpLoadPath } from '../../utils/helpers/path/resolve-alias-path.js';
|
|
6
|
+
import { bindLoaderTmpSync } from '../../utils/helpers/tmp/loader-tmp-sync.js';
|
|
7
|
+
import { normalizeNodeEnv } from '../../utils/helpers/node-env/index.js';
|
|
8
|
+
import { readKafkaLoaderOptions } from '../../utils/helpers/kafka-loader-options/index.js';
|
|
9
|
+
export default class Configs {
|
|
10
|
+
publicFolderName = Constants.publicFolderName;
|
|
11
|
+
kafkaLogsTopic = Constants.kafkaLogsTopic;
|
|
12
|
+
#system;
|
|
13
|
+
#config;
|
|
14
|
+
constructor({ system }) {
|
|
15
|
+
this.#system = system;
|
|
16
|
+
const proxy = new Proxy(this, {
|
|
17
|
+
get: (target, prop) => {
|
|
18
|
+
return target[prop] || target.config?.[prop];
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return proxy;
|
|
22
|
+
}
|
|
23
|
+
onInit = async () => {
|
|
24
|
+
await this.syncFromTmp();
|
|
25
|
+
bindLoaderTmpSync(this);
|
|
26
|
+
};
|
|
27
|
+
syncFromTmp = async () => {
|
|
28
|
+
const cwd = process.cwd();
|
|
29
|
+
const tmp = this.#system.tmp;
|
|
30
|
+
const extendConfigs = tmp.configs.service.loaders.configs.loadPath;
|
|
31
|
+
const fullPath = resolveTmpLoadPath(extendConfigs, tmp, cwd);
|
|
32
|
+
const fileUrl = pathToFileURL(fullPath).href;
|
|
33
|
+
const modulePromise = import(fileUrl);
|
|
34
|
+
this.#config = {
|
|
35
|
+
worker: process.env.WORKER === 'true' ? true : false || false,
|
|
36
|
+
mode: process.env.MODE,
|
|
37
|
+
nodeEnv: normalizeNodeEnv(process.env.NODE_ENV),
|
|
38
|
+
debug: process.env.SYSTEM_LOGGER_LAYER ?? '',
|
|
39
|
+
https: process.env.HTTPS ?? 'false',
|
|
40
|
+
httpsfileEncoding: process.env.ENCODING || 'utf8',
|
|
41
|
+
httpsCertfile: process.env.HTTPS_CERT_FILE ?? '',
|
|
42
|
+
httpsKeyfile: process.env.HTTPS_KEY_FILE ?? '',
|
|
43
|
+
rootFolderPath: tmp.configs.rootFolderPath || 'x',
|
|
44
|
+
projectName: tmp.project.name,
|
|
45
|
+
serviceName: tmp.configs.service.name ?? "",
|
|
46
|
+
projectNamePrefixEnv: process.env.PROJECT_NAME_PREFIX || '',
|
|
47
|
+
projectNameEnv: process.env.PROJECT_NAME || '',
|
|
48
|
+
projectNameSuffixEnv: process.env.PROJECT_NAME_SUFFIX || '',
|
|
49
|
+
systemStaticFolderPath: path.resolve(tmp.configs.rootFolderPath, this.publicFolderName),
|
|
50
|
+
systemLoggerLayer: process.env.SYSTEM_LOGGER_LAYER ?? 'info',
|
|
51
|
+
isKafkaPassive: !readKafkaLoaderOptions(tmp.configs.service.loaders).enabled,
|
|
52
|
+
kafkaClientId: tmp.configs.service.name ?? "",
|
|
53
|
+
kafkaBrokers: process.env.KAFKA_BROKERS ?? '',
|
|
54
|
+
kafkaUsername: process.env.KAFKA_USERNAME ?? '',
|
|
55
|
+
kafkaPassword: process.env.KAFKA_PASSWORD ?? '',
|
|
56
|
+
kafkaTopics: [],
|
|
57
|
+
kafkaLogsTopic: this.kafkaLogsTopic,
|
|
58
|
+
isRedisPassive: process.env.IS_REDIS_PASSIVE === 'true' ? true : false,
|
|
59
|
+
redisUri: process.env.REDIS_URI ?? '',
|
|
60
|
+
isMongoPassive: process.env.IS_MONGODB_PASSIVE === 'true' ? true : false,
|
|
61
|
+
mongodbUri: process.env.MONGODB_URI ?? '',
|
|
62
|
+
isRegistryEnabled: process.env.IS_REGISTRY_ENABLED === 'true',
|
|
63
|
+
registryMongodbUri: process.env.REGISTRY_MONGODB_URI ?? '',
|
|
64
|
+
baseApiUri: process.env.HTTPS === 'true' ? (process.env.SYSTEM_HTTPS_BASE_API_URI ?? '') : (process.env.SYSTEM_BASE_API_URI ?? ''),
|
|
65
|
+
port: Number(process.env.PORT),
|
|
66
|
+
internalSecret: process.env.INTERNAL_SECRET ?? '',
|
|
67
|
+
secret: process.env.SECRET ?? '',
|
|
68
|
+
cwd,
|
|
69
|
+
env: normalizeNodeEnv(process.env.NODE_ENV),
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
const moduleData = await modulePromise;
|
|
73
|
+
const importedConfigs = moduleData?.default || moduleData?.configs || moduleData || {};
|
|
74
|
+
const merged = _.mergeWith({}, this.#config, importedConfigs, (objValue, srcValue) => {
|
|
75
|
+
if (_.isArray(objValue)) {
|
|
76
|
+
return objValue.concat(srcValue);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const nodeEnv = normalizeNodeEnv(merged.nodeEnv ?? merged.env ?? process.env.NODE_ENV);
|
|
80
|
+
this.#config = Object.freeze({ ...merged, nodeEnv, env: nodeEnv });
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
const nodeEnv = normalizeNodeEnv(this.#config.nodeEnv ?? this.#config.env ?? process.env.NODE_ENV);
|
|
84
|
+
this.#config = Object.freeze({ ...this.#config, nodeEnv, env: nodeEnv });
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
setConfig(newConfigs) {
|
|
88
|
+
const mergedDObj = Object.assign(this.#config, newConfigs);
|
|
89
|
+
this.#config = Object.freeze(mergedDObj);
|
|
90
|
+
}
|
|
91
|
+
_(key) {
|
|
92
|
+
return this.#config[key];
|
|
93
|
+
}
|
|
94
|
+
get all() {
|
|
95
|
+
return this.#config;
|
|
96
|
+
}
|
|
97
|
+
}
|