@xrystal/core 3.39.0 → 3.41.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 +65 -34
- package/package.json +2 -4
- package/x/bin/commands/create.mjs +2 -1
- package/x/bin/commands/doctor.mjs +9 -7
- package/x/bin/commands/hooks.mjs +4 -2
- package/x/bin/commands/project.mjs +2 -1
- package/x/bin/commands/release.mjs +5 -3
- package/x/bin/commands/sync.mjs +51 -0
- package/x/bin/commands/tmp.mjs +4 -2
- package/x/bin/helpers/.generated/tmp-schema.mjs +110 -86
- package/x/bin/helpers/banner.mjs +4 -3
- package/x/bin/helpers/build-config.mjs +11 -2
- package/x/bin/helpers/cli-help.mjs +12 -11
- package/x/bin/helpers/cli-identity.mjs +7 -17
- package/x/bin/helpers/defaults.json +14 -30
- package/x/bin/helpers/package-defaults.mjs +43 -12
- package/x/bin/helpers/project-artifacts.mjs +9 -2
- package/x/bin/helpers/project-root.mjs +4 -4
- package/x/bin/helpers/seed-from-tmp.mjs +69 -0
- package/x/bin/helpers/tmp-config.mjs +2 -1
- package/x/bin/helpers/tmp-layout.mjs +5 -5
- package/x/bin/helpers/toolchain-config.mjs +7 -13
- package/x/bin/main-cli.js +3 -3
- package/x/bin/scripts/install-git-hooks.mjs +5 -3
- package/x/bin/scripts/release-prepare.mjs +2 -2
- package/x/bin/scripts/sync-cli-defaults.mjs +7 -2
- package/x/dist/utils/constants/defaults.json +14 -30
- package/x/dist/utils/constants/index.d.ts +19 -12
- package/x/dist/utils/constants/index.js +1 -1
- package/x/dist/utils/helpers/core/tmp-layout.js +1 -1
- package/x/dist/utils/helpers/tmp/index.d.ts +2 -0
- package/x/dist/utils/helpers/tmp/index.js +1 -1
- package/x/dist/utils/helpers/tmp/path-normalize.d.ts +8 -0
- package/x/dist/utils/helpers/tmp/path-normalize.js +1 -0
- package/x/dist/utils/helpers/tmp/seed-from-tmp.d.ts +10 -0
- package/x/dist/utils/helpers/tmp/seed-from-tmp.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -1
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +0 -3
- package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -1
- package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -1
- package/x/dist/utils/models/classes/class.x.js +1 -1
- package/x/bin/commands/sync-toolchain.mjs +0 -43
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import yaml from 'yaml'
|
|
5
|
+
|
|
6
|
+
const here = path.dirname(fileURLToPath(import.meta.url))
|
|
7
|
+
|
|
8
|
+
function requireString(value, label) {
|
|
9
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
10
|
+
throw new Error(label)
|
|
11
|
+
}
|
|
12
|
+
return value.trim()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function normalizeRootFolder(value, fallback) {
|
|
16
|
+
if (typeof value !== 'string' || !value.trim()) return fallback
|
|
17
|
+
return value.trim().replace(/^\.\/+/, '')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function normalizeSourceFolder(value, packageName) {
|
|
21
|
+
const trimmed = requireString(value, `${packageName}: bundled tmp.yml missing configs.service.paths.source`)
|
|
22
|
+
if (trimmed.startsWith('./') || trimmed.startsWith('../')) return trimmed
|
|
23
|
+
return `./${trimmed}`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function readLayout(special, packageName) {
|
|
27
|
+
const block = special && typeof special === 'object' && !Array.isArray(special) ? special : {}
|
|
28
|
+
const miss = (field) => `${packageName}: bundled tmp.yml missing configs.service.paths.special.${field}`
|
|
29
|
+
return Object.freeze({
|
|
30
|
+
tests: requireString(block.tests, miss('tests')),
|
|
31
|
+
environments: requireString(block.environments, miss('environments')),
|
|
32
|
+
dist: requireString(block.dist, miss('dist')),
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function findBundledTmpFile(packageRoot, raw) {
|
|
37
|
+
const packageName = requireString(raw.packageName, 'defaults.packageName required')
|
|
38
|
+
const rootFolder = requireString(raw.packageRootFolder, `${packageName}: defaults.packageRootFolder required`)
|
|
39
|
+
const tmpBase = requireString(raw.tmpBaseName, `${packageName}: defaults.tmpBaseName required`)
|
|
40
|
+
const tmpExt = requireString(raw.tmpExtension, `${packageName}: defaults.tmpExtension required`)
|
|
41
|
+
const tmpFileName = `${tmpBase}${tmpExt}`
|
|
42
|
+
const direct = path.join(packageRoot, rootFolder, tmpFileName)
|
|
43
|
+
if (fs.existsSync(direct)) return { file: direct, rootFolder, packageName }
|
|
44
|
+
|
|
45
|
+
let dir = path.resolve(here)
|
|
46
|
+
for (;;) {
|
|
47
|
+
const candidate = path.join(dir, rootFolder, tmpFileName)
|
|
48
|
+
if (fs.existsSync(candidate)) return { file: candidate, rootFolder, packageName }
|
|
49
|
+
const parent = path.dirname(dir)
|
|
50
|
+
if (parent === dir) break
|
|
51
|
+
dir = parent
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
throw new Error(`${packageName}: bundled ${rootFolder}/${tmpFileName} not found`)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function loadSeedLayoutFromBundledTmp(packageRoot, raw = {}) {
|
|
58
|
+
const { file, rootFolder, packageName } = findBundledTmpFile(packageRoot, raw)
|
|
59
|
+
const doc = yaml.parse(fs.readFileSync(file, 'utf8'))
|
|
60
|
+
const service = doc?.configs?.service ?? {}
|
|
61
|
+
const paths = service.paths ?? {}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
rootFolder: normalizeRootFolder(paths.root, rootFolder),
|
|
65
|
+
mainSourceFolder: normalizeSourceFolder(paths.source, packageName),
|
|
66
|
+
framework: requireString(service.framework, `${packageName}: bundled tmp.yml missing configs.service.framework`),
|
|
67
|
+
layoutPaths: readLayout(paths.special, packageName),
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readTmpServiceBlock } from './tmp-schema.mjs'
|
|
2
|
+
import { packageDefaults } from './package-defaults.mjs'
|
|
2
3
|
const PROTOCOL_ALIASES = {
|
|
3
4
|
http: 'http',
|
|
4
5
|
https: 'https',
|
|
@@ -26,7 +27,7 @@ export function summarizeLoaders(tmp = {}) {
|
|
|
26
27
|
const service = configs.service ?? readTmpServiceBlock(configs)
|
|
27
28
|
|
|
28
29
|
return {
|
|
29
|
-
framework: service.framework ??
|
|
30
|
+
framework: service.framework ?? packageDefaults.framework,
|
|
30
31
|
protocols: resolveProtocolsFromConfig(service),
|
|
31
32
|
service: service.name,
|
|
32
33
|
items: [
|
|
@@ -43,7 +43,7 @@ export function assertCoreTmpGuard(projectRoot, tmpFilePath) {
|
|
|
43
43
|
const canonical = coreCanonicalTmpPath(projectRoot)
|
|
44
44
|
if (path.resolve(tmpFilePath) !== path.resolve(canonical)) {
|
|
45
45
|
throw new Error(
|
|
46
|
-
|
|
46
|
+
`${packageDefaults.packageName}: tmp.yml must stay at ${packageDefaults.packageRootFolder}/tmp.yml (expected ${canonical}, got ${tmpFilePath})`,
|
|
47
47
|
)
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -58,7 +58,7 @@ function findStrayCoreTmpFiles(projectRoot, canonicalPath) {
|
|
|
58
58
|
export function ensureCoreTmpEntry(projectRoot = process.cwd(), options = {}) {
|
|
59
59
|
const resolvedRoot = path.resolve(projectRoot)
|
|
60
60
|
if (!isCorePackageRoot(resolvedRoot)) {
|
|
61
|
-
throw new Error(
|
|
61
|
+
throw new Error(`ensureCoreTmpEntry is only for ${packageDefaults.packageName} package root`)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
const canonical = coreCanonicalTmpPath(resolvedRoot)
|
|
@@ -66,7 +66,7 @@ export function ensureCoreTmpEntry(projectRoot = process.cwd(), options = {}) {
|
|
|
66
66
|
if (strays.length > 0) {
|
|
67
67
|
const rel = strays.map((p) => path.relative(resolvedRoot, p)).join(', ')
|
|
68
68
|
throw new Error(
|
|
69
|
-
|
|
69
|
+
`${packageDefaults.packageName}: tmp.yml must only exist under ${packageDefaults.packageRootFolder}/. Remove extra copies: ${rel}`,
|
|
70
70
|
)
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -207,7 +207,7 @@ export function ensureTmpFile(projectRoot = process.cwd(), { patchServiceName =
|
|
|
207
207
|
if (strays.length > 0) {
|
|
208
208
|
const rel = strays.map((p) => path.relative(resolvedRoot, p)).join(', ')
|
|
209
209
|
throw new Error(
|
|
210
|
-
|
|
210
|
+
`${packageDefaults.packageName}: tmp.yml must only exist under ${packageDefaults.packageRootFolder}/. Remove extra copies: ${rel}`,
|
|
211
211
|
)
|
|
212
212
|
}
|
|
213
213
|
|
|
@@ -237,7 +237,7 @@ export function ensureTmpFile(projectRoot = process.cwd(), { patchServiceName =
|
|
|
237
237
|
|
|
238
238
|
const templatePath = getBundledCoreTmpPath()
|
|
239
239
|
if (!fs.existsSync(templatePath)) {
|
|
240
|
-
throw new Error(
|
|
240
|
+
throw new Error(`${packageDefaults.packageName} bundled ${packageDefaults.packageRootFolder}/tmp.yml not found in package`)
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
const layout = buildTmpLayout(resolvedRoot, null, null)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CLI_PRIMARY_NAME } from './cli-identity.mjs'
|
|
1
2
|
import fs from 'node:fs'
|
|
2
3
|
import path from 'node:path'
|
|
3
4
|
|
|
@@ -32,7 +33,7 @@ export function resolveToolchainPaths(options = {}) {
|
|
|
32
33
|
outDir: `./${rootFolder}/${distSegment}`,
|
|
33
34
|
include: [mainFolder],
|
|
34
35
|
exclude: [`${rootFolder}/${testsSegment}`],
|
|
35
|
-
pathAliasKey: packageDefaults.
|
|
36
|
+
pathAliasKey: packageDefaults.pathAliasKey,
|
|
36
37
|
pathAliasTarget: [`${mainFolder}/*`],
|
|
37
38
|
eslintFiles: [`${mainFolder}/**/*.ts`, `${mainFolder}/**/*.tsx`],
|
|
38
39
|
eslintIgnores: [
|
|
@@ -51,23 +52,16 @@ export function resolveToolchainPathsFromProject(root = process.cwd()) {
|
|
|
51
52
|
|
|
52
53
|
export function resolveRecommendedTsconfig(options = {}) {
|
|
53
54
|
const paths = resolveToolchainPaths(options)
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
// compilerOptions language lives in tsconfig.base.json (extends);
|
|
56
|
+
// sync only overlays layout fields from tmp.yml
|
|
56
57
|
return {
|
|
57
58
|
include: [...paths.include],
|
|
58
59
|
exclude: [...paths.exclude],
|
|
59
60
|
compilerOptions: {
|
|
60
|
-
target: 'ESNext',
|
|
61
|
-
module: 'ESNext',
|
|
62
|
-
moduleResolution: 'Bundler',
|
|
63
61
|
baseUrl: '.',
|
|
64
62
|
paths: { [paths.pathAliasKey]: paths.pathAliasTarget },
|
|
65
63
|
rootDir: paths.mainSourceFolder,
|
|
66
64
|
outDir: paths.outDir,
|
|
67
|
-
esModuleInterop: true,
|
|
68
|
-
forceConsistentCasingInFileNames: true,
|
|
69
|
-
skipLibCheck: true,
|
|
70
|
-
...baseOptions,
|
|
71
65
|
},
|
|
72
66
|
}
|
|
73
67
|
}
|
|
@@ -80,7 +74,7 @@ export function resolveRecommendedTsconfigFromProject(root = process.cwd()) {
|
|
|
80
74
|
export function resolveTsconfigExtends(root) {
|
|
81
75
|
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
|
|
82
76
|
if (pkg.name === packageDefaults.packageName) return './tsconfig.base.json'
|
|
83
|
-
return
|
|
77
|
+
return `${packageDefaults.packageName}/tsconfig.base.json`
|
|
84
78
|
}
|
|
85
79
|
|
|
86
80
|
export function mergeTsconfigWithLayout(recommended, existing = {}, extendsPath) {
|
|
@@ -148,7 +142,7 @@ export function auditTsconfigAlignment(root, options = null) {
|
|
|
148
142
|
const recommended = resolveRecommendedTsconfig(resolvedOptions)
|
|
149
143
|
const onDisk = readProjectTsconfig(root)
|
|
150
144
|
if (!onDisk) {
|
|
151
|
-
return { ok: false, missing: true, notes: [
|
|
145
|
+
return { ok: false, missing: true, notes: [`tsconfig.json not found — run ${CLI_PRIMARY_NAME} sync`] }
|
|
152
146
|
}
|
|
153
147
|
|
|
154
148
|
const notes = []
|
|
@@ -175,7 +169,7 @@ export function auditTsconfigAlignment(root, options = null) {
|
|
|
175
169
|
|
|
176
170
|
export function createEslintConfigFromProject(root = process.cwd(), tseslint) {
|
|
177
171
|
const paths = resolveToolchainPathsFromProject(root)
|
|
178
|
-
const depth = packageDefaults.
|
|
172
|
+
const depth = packageDefaults.eslintRestrictedImportDepth ?? 2
|
|
179
173
|
const deepRelative = '../'.repeat(depth + 1)
|
|
180
174
|
|
|
181
175
|
return tseslint.config(
|
package/x/bin/main-cli.js
CHANGED
|
@@ -7,7 +7,7 @@ import { registerCreateCommand } from './commands/create.mjs'
|
|
|
7
7
|
import { registerDoctorCommand } from './commands/doctor.mjs'
|
|
8
8
|
import { registerProjectCommands } from './commands/project.mjs'
|
|
9
9
|
import { registerTmpCommand } from './commands/tmp.mjs'
|
|
10
|
-
import {
|
|
10
|
+
import { registerSyncCommand } from './commands/sync.mjs'
|
|
11
11
|
import { registerTagCommand, registerVersionCommand } from './commands/release.mjs'
|
|
12
12
|
import { registerHooksCommand } from './commands/hooks.mjs'
|
|
13
13
|
import { printBanner, shouldShowBanner } from './helpers/banner.mjs'
|
|
@@ -51,7 +51,7 @@ const cli = new Command()
|
|
|
51
51
|
cli
|
|
52
52
|
.name(cliName)
|
|
53
53
|
.description('xrystal core — microservice runtime library')
|
|
54
|
-
.version(pkg.version, '-V, --version',
|
|
54
|
+
.version(pkg.version, '-V, --version', `Show ${pkg.name} CLI version`)
|
|
55
55
|
.configureHelp({
|
|
56
56
|
helpWidth: () => Math.min(100, Math.max(56, process.stdout.columns || 80)),
|
|
57
57
|
sortSubcommands: true,
|
|
@@ -65,7 +65,7 @@ registerVersionCommand(cli, cliContext)
|
|
|
65
65
|
registerTagCommand(cli, cliContext)
|
|
66
66
|
registerDoctorCommand(cli, cliContext)
|
|
67
67
|
registerTmpCommand(cli, cliContext)
|
|
68
|
-
|
|
68
|
+
registerSyncCommand(cli, cliContext)
|
|
69
69
|
registerHooksCommand(cli, cliContext)
|
|
70
70
|
registerProjectCommands(cli, cliContext)
|
|
71
71
|
|
|
@@ -4,9 +4,11 @@ import path from 'node:path'
|
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
5
|
|
|
6
6
|
import { resolveProjectRoot } from '../helpers/project-root.mjs'
|
|
7
|
+
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
8
|
+
import { packageDefaults } from '../helpers/package-defaults.mjs'
|
|
7
9
|
|
|
8
10
|
const verifyScriptPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'verify-version-bump.mjs')
|
|
9
|
-
const HOOK_MARKER =
|
|
11
|
+
const HOOK_MARKER = `${packageDefaults.packageName} version-bump pre-commit`
|
|
10
12
|
|
|
11
13
|
export function resolveVerifyScriptPath() {
|
|
12
14
|
return verifyScriptPath
|
|
@@ -50,7 +52,7 @@ set -e
|
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
|
|
53
|
-
export function ensureHooksInstallScript(projectRoot, cliName =
|
|
55
|
+
export function ensureHooksInstallScript(projectRoot, cliName = CLI_PRIMARY_NAME) {
|
|
54
56
|
const packageJsonPath = path.join(projectRoot, 'package.json')
|
|
55
57
|
if (!fs.existsSync(packageJsonPath)) return false
|
|
56
58
|
|
|
@@ -66,7 +68,7 @@ export function ensureHooksInstallScript(projectRoot, cliName = 'xcore') {
|
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
/** Install pre-commit hook + package.json hooks:install script (create + manual). */
|
|
69
|
-
export function setupProjectGitHooks(projectRoot, { cliName =
|
|
71
|
+
export function setupProjectGitHooks(projectRoot, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
70
72
|
ensureHooksInstallScript(projectRoot, cliName)
|
|
71
73
|
const refreshed = isGitHookInstalled(projectRoot)
|
|
72
74
|
const result = installGitHooks(projectRoot)
|
|
@@ -34,12 +34,12 @@ export function isCorePackageProject(root) {
|
|
|
34
34
|
export function runReleasePrepare({ root = resolveProjectRoot(), dryRun = false, skipPrepare = false } = {}) {
|
|
35
35
|
if (skipPrepare || !isCorePackageProject(root)) {
|
|
36
36
|
if (!skipPrepare && !isCorePackageProject(root)) {
|
|
37
|
-
console.log(
|
|
37
|
+
console.log(`\nRelease prepare skipped (not ${packageDefaults.packageName}).\n`)
|
|
38
38
|
}
|
|
39
39
|
return { skipped: true }
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
console.log(
|
|
42
|
+
console.log(`\nRelease prepare (${packageDefaults.packageName}):\n`)
|
|
43
43
|
console.log(' (npm publish CI converts source → .js; git keeps TypeScript)\n')
|
|
44
44
|
|
|
45
45
|
for (const step of PREPARE_STEPS) {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Publish artifact only.
|
|
4
|
+
* Authoring source of truth: source/utils/constants/defaults.json
|
|
5
|
+
* Local CLI prefers the authored file; npm pack needs this copy under x/bin.
|
|
6
|
+
*/
|
|
2
7
|
import fs from 'node:fs'
|
|
3
8
|
import path from 'node:path'
|
|
4
9
|
|
|
@@ -7,10 +12,10 @@ const src = path.join(root, 'source/utils/constants/defaults.json')
|
|
|
7
12
|
const dest = path.join(root, 'x/bin/helpers/defaults.json')
|
|
8
13
|
|
|
9
14
|
if (!fs.existsSync(src)) {
|
|
10
|
-
console.error('sync-cli-defaults: source
|
|
15
|
+
console.error('sync-cli-defaults: source/utils/constants/defaults.json missing')
|
|
11
16
|
process.exit(1)
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
fs.mkdirSync(path.dirname(dest), { recursive: true })
|
|
15
20
|
fs.copyFileSync(src, dest)
|
|
16
|
-
console.log('sync-cli-defaults:
|
|
21
|
+
console.log('sync-cli-defaults: publish copy → x/bin/helpers/defaults.json')
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"packageName": "@xrystal/core",
|
|
3
3
|
"packageRootFolder": "x",
|
|
4
|
+
"cliName": "xry",
|
|
5
|
+
"cliBinNames": [
|
|
6
|
+
"xry"
|
|
7
|
+
],
|
|
4
8
|
"tmpBaseName": "tmp",
|
|
5
9
|
"tmpExtension": ".yml",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
"templateRepoUri": "https://github.com/xdloper/api-gpt-svc",
|
|
11
|
+
"publicFolderName": "public",
|
|
12
|
+
"kafkaLogsTopic": "log",
|
|
13
|
+
"pathAliasKey": "@/*",
|
|
14
|
+
"eslintRestrictedImportDepth": 2,
|
|
15
|
+
"tmpWatchDefaults": {
|
|
16
|
+
"intervalMs": 500,
|
|
17
|
+
"minIntervalMs": 100,
|
|
18
|
+
"maxIntervalMs": 10000
|
|
11
19
|
},
|
|
12
20
|
"buildDefaults": {
|
|
13
21
|
"tsconfig": "tsconfig.json",
|
|
@@ -16,29 +24,5 @@
|
|
|
16
24
|
"declarations": false,
|
|
17
25
|
"sourcemap": false,
|
|
18
26
|
"minify": false
|
|
19
|
-
}
|
|
20
|
-
"tsconfigDefaults": {
|
|
21
|
-
"pathAliasKey": "@/*",
|
|
22
|
-
"compilerOptions": {
|
|
23
|
-
"noEmit": false,
|
|
24
|
-
"noEmitOnError": false,
|
|
25
|
-
"declaration": true,
|
|
26
|
-
"emitDeclarationOnly": false,
|
|
27
|
-
"sourceMap": false,
|
|
28
|
-
"declarationMap": false,
|
|
29
|
-
"strict": true,
|
|
30
|
-
"noImplicitAny": true
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"eslintDefaults": {
|
|
34
|
-
"restrictedImportDepth": 2
|
|
35
|
-
},
|
|
36
|
-
"tmpWatchDefaults": {
|
|
37
|
-
"intervalMs": 500,
|
|
38
|
-
"minIntervalMs": 100,
|
|
39
|
-
"maxIntervalMs": 10000
|
|
40
|
-
},
|
|
41
|
-
"publicFolderName": "public",
|
|
42
|
-
"kafkaLogsTopic": "log",
|
|
43
|
-
"templateRepoUri": "https://github.com/xdloper/api-gpt-svc"
|
|
27
|
+
}
|
|
44
28
|
}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import defaults from './defaults.json';
|
|
2
|
-
export type PackageDefaults = typeof defaults
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export type PackageDefaults = typeof defaults & {
|
|
3
|
+
mainSourceFolder: string;
|
|
4
|
+
framework: string;
|
|
5
|
+
layoutPaths: {
|
|
6
|
+
tests: string;
|
|
7
|
+
environments: string;
|
|
8
|
+
dist: string;
|
|
9
|
+
};
|
|
10
|
+
cliBinNames: readonly string[];
|
|
11
|
+
};
|
|
12
|
+
export declare const packageDefaults: Readonly<PackageDefaults>;
|
|
6
13
|
export declare const coreVersionPattern: RegExp;
|
|
7
14
|
export declare const semverVersionPattern: RegExp;
|
|
8
15
|
export declare class Constants {
|
|
@@ -10,18 +17,18 @@ export declare class Constants {
|
|
|
10
17
|
static readonly packageRootFolder: string;
|
|
11
18
|
static readonly tmpBaseName: string;
|
|
12
19
|
static readonly tmpExtension: string;
|
|
20
|
+
static readonly publicFolderName: string;
|
|
21
|
+
static readonly kafkaLogsTopic: string;
|
|
22
|
+
static readonly templateRepoUri: string;
|
|
23
|
+
static readonly cliName: string;
|
|
24
|
+
static readonly cliBinNames: string[] & readonly string[];
|
|
25
|
+
static readonly pathAliasKey: string;
|
|
13
26
|
static readonly mainSourceFolder: string;
|
|
14
27
|
static readonly layoutPaths: {
|
|
15
28
|
tests: string;
|
|
16
29
|
environments: string;
|
|
17
30
|
dist: string;
|
|
18
|
-
}
|
|
19
|
-
tests: string;
|
|
20
|
-
environments: string;
|
|
21
|
-
dist: string;
|
|
22
|
-
}>;
|
|
23
|
-
static readonly publicFolderName: string;
|
|
24
|
-
static readonly kafkaLogsTopic: string;
|
|
25
|
-
static readonly templateRepoUri: string;
|
|
31
|
+
};
|
|
26
32
|
static readonly bundledCoreTmpPath: string;
|
|
27
33
|
}
|
|
34
|
+
export { seedFromTmp, loadSeedFromBundledTmp } from '../../utils/helpers/tmp/seed-from-tmp';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import n from"node:path";import{packageRootDir as q}from"../../utils/package-root";import b from"./defaults.json" with { type: 'json' };import{seedFromTmp as j}from"../../utils/helpers/tmp/seed-from-tmp";export const packageDefaults=Object.freeze({...b,mainSourceFolder:j.sourceFolder,framework:j.framework,layoutPaths:Object.freeze({...j.layout}),buildDefaults:Object.freeze({...b.buildDefaults}),tmpWatchDefaults:Object.freeze({...b.tmpWatchDefaults}),cliBinNames:Object.freeze([...b.cliBinNames??[b.cliName]])}),coreVersionPattern=/^\d{2}\.\d{2}\.\d{2}-v\d+$/,semverVersionPattern=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/;const v=`${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;export class Constants{static packageName=packageDefaults.packageName;static packageRootFolder=packageDefaults.packageRootFolder;static tmpBaseName=packageDefaults.tmpBaseName;static tmpExtension=packageDefaults.tmpExtension;static publicFolderName=packageDefaults.publicFolderName;static kafkaLogsTopic=packageDefaults.kafkaLogsTopic;static templateRepoUri=packageDefaults.templateRepoUri;static cliName=packageDefaults.cliName;static cliBinNames=packageDefaults.cliBinNames;static pathAliasKey=packageDefaults.pathAliasKey;static mainSourceFolder=packageDefaults.mainSourceFolder;static layoutPaths=packageDefaults.layoutPaths;static bundledCoreTmpPath=n.join(q,packageDefaults.packageRootFolder,v)}export{seedFromTmp,loadSeedFromBundledTmp}from"../../utils/helpers/tmp/seed-from-tmp";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import U from"node:fs";import
|
|
1
|
+
import U from"node:fs";import J from"node:path";import z from"yaml";import{Constants as I}from"../../../utils/constants";import{findAllFilesRecursively as L,findFileRecursively as A}from"../../../utils/helpers/core/paths";import{normalizeTmpDocument as D,readTmpServiceBlock as B,normalizeRootFolder as b,normalizeSourceFolder as x,resolveServiceLayoutPaths as k}from"../../../utils/helpers/tmp/tmp-schema";function M(E,q){return`${E}${q.startsWith(".")?q:`.${q}`}`}export function coreCanonicalTmpPath(E=process.cwd()){return J.join(J.resolve(E),I.packageRootFolder,M(I.tmpBaseName,I.tmpExtension))}export function assertCoreTmpGuard(E,q){if(!isCorePackageRoot(E))return;const H=coreCanonicalTmpPath(E);if(J.resolve(q)!==J.resolve(H))throw Error(`${I.packageName}: tmp.yml must stay at ${I.packageRootFolder}/tmp.yml (expected ${H}, got ${q})`)}function N(E,q){const H=J.resolve(E),K=J.resolve(q);return L(H,I.tmpBaseName,I.tmpExtension).filter((Q)=>J.resolve(Q)!==K)}export function ensureCoreTmpEntry(E=process.cwd(),q={}){const H=J.resolve(E);if(!isCorePackageRoot(H))throw Error(`ensureCoreTmpEntry is only for ${I.packageName} package root`);const K=coreCanonicalTmpPath(H),Q=N(H,K);if(Q.length>0){const X=Q.map((W)=>J.relative(H,W)).join(", ");throw Error(`${I.packageName}: tmp.yml must only exist under ${I.packageRootFolder}/. Remove extra copies: ${X}`)}if(U.existsSync(K)){assertCoreTmpGuard(H,K);return{tmpFilePath:K,created:!1,layout:buildTmpLayout(H,_(K),K)}}return ensureTmpFile(H,{...q,patchServiceName:!1})}function S(E,q,H){const K=J.resolve(E);if(isCorePackageRoot(K)){const Q=coreCanonicalTmpPath(K);return U.existsSync(Q)?Q:null}return A(K,q,H)}function _(E){return z.parse(U.readFileSync(E,"utf8"))}export function isCorePackageRoot(E){const q=J.join(J.resolve(E),"package.json");if(!U.existsSync(q))return!1;try{return JSON.parse(U.readFileSync(q,"utf8")).name===I.packageName}catch{return!1}}export function resolveRootFolderPath(E,q,H){const K=D(E).configs,Q=B(K);if(Q.paths?.root?.trim())return b(Q.paths.root);const X=E.project;if(typeof X?.name==="string"&&X.name.trim())return X.name.trim();const W=J.relative(J.resolve(H),J.dirname(J.resolve(q)));if(W&&W!==".")return W;return I.packageRootFolder}export function resolveLayoutPaths(E){const q=B(E);return k(q)}export function resolveMainFolderPath(E){const q=B(E);if(q.paths?.source?.trim())return x(q.paths.source);return I.mainSourceFolder}export function buildTmpLayout(E,q,H){const K=J.resolve(E),Q=q?D(q).configs:void 0,X=q&&H&&!isCorePackageRoot(K)?resolveRootFolderPath(q,H,K):I.packageRootFolder,W=J.join(K,X),Y=resolveLayoutPaths(Q),V=resolveMainFolderPath(Q),Z={tests:J.join(W,Y.tests),environments:J.join(W,Y.environments),dist:J.join(W,Y.dist)};return{projectRoot:K,rootFolderPath:X,rootFolderAbs:W,tmpFilePath:H,mainFolderPath:V,paths:Y,pathsAbs:Z}}export function resolveTmpLayout(E=process.cwd(),q={}){const H=q.tmpFileName??I.tmpBaseName,K=q.ext??I.tmpExtension,Q=S(E,H,K);if(!Q)throw Error(`${M(H,K)} not found under ${J.resolve(E)}`);if(isCorePackageRoot(J.resolve(E)))assertCoreTmpGuard(E,Q);return buildTmpLayout(E,_(Q),Q)}export function resolveTmpLayoutOrDefaults(E=process.cwd()){const q=S(E,I.tmpBaseName,I.tmpExtension);if(!q)return buildTmpLayout(E,null,null);return buildTmpLayout(E,_(q),q)}export function resolveBundledCoreTmpPath(E=process.cwd()){if(U.existsSync(I.bundledCoreTmpPath))return I.bundledCoreTmpPath;let q=J.resolve(E);while(q!==J.dirname(q)){const H=J.join(q,"node_modules","@xrystal","core",I.packageRootFolder,M(I.tmpBaseName,I.tmpExtension));if(U.existsSync(H))return H;const K=J.join(q,"package.json");if(U.existsSync(K)){if(JSON.parse(U.readFileSync(K,"utf8")).name===I.packageName){const X=J.join(q,I.packageRootFolder,M(I.tmpBaseName,I.tmpExtension));if(U.existsSync(X))return X}}q=J.dirname(q)}throw Error(`${I.packageName} bundled ${I.packageRootFolder}/tmp.yml not found`)}export function ownerTmpFilePath(E=process.cwd(),q){const H=q??resolveTmpLayoutOrDefaults(E);return J.join(H.rootFolderAbs,M(I.tmpBaseName,I.tmpExtension))}export function ensureTmpFile(E=process.cwd(),q={}){const H=J.resolve(E),K=q.patchServiceName??!0;if(isCorePackageRoot(H)){const V=coreCanonicalTmpPath(H),Z=N(H,V);if(Z.length>0){const $=Z.map((w)=>J.relative(H,w)).join(", ");throw Error(`${I.packageName}: tmp.yml must only exist under ${I.packageRootFolder}/. Remove extra copies: ${$}`)}if(U.existsSync(V)){assertCoreTmpGuard(H,V);return{tmpFilePath:V,created:!1,layout:buildTmpLayout(H,_(V),V)}}}else{const V=A(H,I.tmpBaseName,I.tmpExtension);if(V)return{tmpFilePath:V,created:!1,layout:buildTmpLayout(H,_(V),V)}}const Q=q.templatePath??resolveBundledCoreTmpPath(H);if(!U.existsSync(Q))throw Error(`${I.packageName} bundled ${I.packageRootFolder}/tmp.yml not found`);const X=buildTmpLayout(H,null,null);U.mkdirSync(X.rootFolderAbs,{recursive:!0});const W=ownerTmpFilePath(H,X);let Y=U.readFileSync(Q,"utf8");if(K)try{const V=J.join(H,"package.json");if(U.existsSync(V)){const Z=JSON.parse(U.readFileSync(V,"utf8")),$=typeof Z.name==="string"?Z.name.replace(/^@/,"").replace(/\//g,"-"):null;if($){const w=z.parse(Y),G=w.configs??{},O=G.service;if(typeof O==="object"&&O!==null&&!Array.isArray(O))O.name=$;else G.service={name:$};w.configs=G;Y=z.stringify(w)}}}catch{}U.writeFileSync(W,Y);return{tmpFilePath:W,created:!0,layout:buildTmpLayout(H,_(W),W)}}export function resolveTmpLayoutEnsured(E=process.cwd()){return ensureTmpFile(E).layout}
|
|
@@ -3,3 +3,5 @@ export { getTmpLoader, getTmpLoaderPath, getTmpSnapshot, onTmpReload, resetTmpLo
|
|
|
3
3
|
export { bindLoaderTmpSync, type ITmpSyncLoader, } from '../../../utils/helpers/tmp/loader-tmp-sync';
|
|
4
4
|
export { resolveTmpWatchIntervalMs } from '../../../utils/helpers/tmp/tmp-watch';
|
|
5
5
|
export { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, readTmpCoreBlock, readTmpServiceBlock, resolveServiceLayoutPaths, resolveTmpRuntimeConfigs, } from '../../../utils/helpers/tmp/tmp-schema';
|
|
6
|
+
export { loadSeedFromBundledTmp, seedFromTmp, type SeedFromTmp, type SeedLayoutPaths, } from '../../../utils/helpers/tmp/seed-from-tmp';
|
|
7
|
+
export { normalizeLayoutPaths, type LayoutPaths, } from '../../../utils/helpers/tmp/path-normalize';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{setRuntimeTmpConfigs,getRuntimeTmpConfigs,onRuntimeTmpChange,notifyRuntimeTmpChange,clearRuntimeTmpConfigs}from"../../../utils/helpers/tmp/runtime-tmp";export{getTmpLoader,getTmpLoaderPath,getTmpSnapshot,onTmpReload,resetTmpLoaderForTests,stopTmpLoader}from"../../../utils/helpers/tmp/tmp-loader";export{bindLoaderTmpSync}from"../../../utils/helpers/tmp/loader-tmp-sync";export{resolveTmpWatchIntervalMs}from"../../../utils/helpers/tmp/tmp-watch";export{normalizeTmpDocument,normalizeRootFolder,normalizeSourceFolder,readTmpCoreBlock,readTmpServiceBlock,resolveServiceLayoutPaths,resolveTmpRuntimeConfigs}from"../../../utils/helpers/tmp/tmp-schema";
|
|
1
|
+
export{setRuntimeTmpConfigs,getRuntimeTmpConfigs,onRuntimeTmpChange,notifyRuntimeTmpChange,clearRuntimeTmpConfigs}from"../../../utils/helpers/tmp/runtime-tmp";export{getTmpLoader,getTmpLoaderPath,getTmpSnapshot,onTmpReload,resetTmpLoaderForTests,stopTmpLoader}from"../../../utils/helpers/tmp/tmp-loader";export{bindLoaderTmpSync}from"../../../utils/helpers/tmp/loader-tmp-sync";export{resolveTmpWatchIntervalMs}from"../../../utils/helpers/tmp/tmp-watch";export{normalizeTmpDocument,normalizeRootFolder,normalizeSourceFolder,readTmpCoreBlock,readTmpServiceBlock,resolveServiceLayoutPaths,resolveTmpRuntimeConfigs}from"../../../utils/helpers/tmp/tmp-schema";export{loadSeedFromBundledTmp,seedFromTmp}from"../../../utils/helpers/tmp/seed-from-tmp";export{normalizeLayoutPaths}from"../../../utils/helpers/tmp/path-normalize";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type LayoutPaths = {
|
|
2
|
+
tests: string;
|
|
3
|
+
environments: string;
|
|
4
|
+
dist: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function normalizeRootFolder(value: unknown, fallback: string): string;
|
|
7
|
+
export declare function normalizeSourceFolder(value: unknown, fallback: string): string;
|
|
8
|
+
export declare function normalizeLayoutPaths(special: unknown, fallback: LayoutPaths): LayoutPaths;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function normalizeRootFolder(t,n){if(typeof t!=="string"||!t.trim())return n;return t.trim().replace(/^\.\/+/,"")}export function normalizeSourceFolder(t,n){if(typeof t!=="string"||!t.trim())return n;const r=t.trim();if(r.startsWith("./")||r.startsWith("../"))return r;return`./${r}`}export function normalizeLayoutPaths(t,n){const r=t&&typeof t==="object"&&!Array.isArray(t)?t:{},o=(e)=>{const i=r[e];return typeof i==="string"&&i.trim()?i.trim():n[e]};return{tests:o("tests"),environments:o("environments"),dist:o("dist")}}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type LayoutPaths } from '../../../utils/helpers/tmp/path-normalize';
|
|
2
|
+
export type SeedLayoutPaths = LayoutPaths;
|
|
3
|
+
export type SeedFromTmp = {
|
|
4
|
+
rootFolder: string;
|
|
5
|
+
sourceFolder: string;
|
|
6
|
+
framework: string;
|
|
7
|
+
layout: SeedLayoutPaths;
|
|
8
|
+
};
|
|
9
|
+
export declare function loadSeedFromBundledTmp(tmpFilePath?: string): SeedFromTmp;
|
|
10
|
+
export declare const seedFromTmp: SeedFromTmp;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import K from"node:fs";import J from"node:path";import{fileURLToPath as V}from"node:url";import W from"yaml";import D from"../../../utils/constants/defaults.json" with { type: 'json' };import{normalizeRootFolder as X,normalizeSourceFolder as Y}from"../../../utils/helpers/tmp/path-normalize";const O=J.dirname(V(import.meta.url)),Q=`${D.tmpBaseName}${D.tmpExtension}`;function I(j,A){if(typeof j!=="string"||!j.trim())throw Error(`${D.packageName}: bundled tmp.yml missing ${A}`);return j.trim()}function Z(j){const A=j&&typeof j==="object"&&!Array.isArray(j)?j:{};return{tests:I(A.tests,"configs.service.paths.special.tests"),environments:I(A.environments,"configs.service.paths.special.environments"),dist:I(A.dist,"configs.service.paths.special.dist")}}function _(j){if(j){if(!K.existsSync(j))throw Error(`${D.packageName}: bundled tmp.yml missing at ${j}`);return j}const A=[O,process.cwd()];for(const H of A){let C=J.resolve(H);for(;;){const E=J.join(C,D.packageRootFolder,Q);if(K.existsSync(E))return E;const G=J.dirname(C);if(G===C)break;C=G}}throw Error(`${D.packageName}: bundled ${D.packageRootFolder}/${Q} not found from ${O}`)}export function loadSeedFromBundledTmp(j){const A=_(j),H=W.parse(K.readFileSync(A,"utf8")),C=H?.configs&&typeof H.configs==="object"?H.configs:{},E=C.service&&typeof C.service==="object"?C.service:{},G=E.paths&&typeof E.paths==="object"?E.paths:{},M=I(G.source,"configs.service.paths.source");return{rootFolder:X(G.root,D.packageRootFolder),sourceFolder:Y(M,M),framework:I(E.framework,"configs.service.framework"),layout:Z(G.special)}}export const seedFromTmp=loadSeedFromBundledTmp();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import J from"node:fs";import K from"node:path";import{Constants as
|
|
1
|
+
import J from"node:fs";import K from"node:path";import{Constants as z}from"../../../utils/constants";import{assertCoreTmpGuard as M,coreCanonicalTmpPath as O,isCorePackageRoot as Q}from"../../../utils/helpers/core/tmp-layout";import{findFileRecursively as U}from"../../../utils/helpers/core/paths";import{TmpFileLoader as V}from"../../../utils/models/classes/class.tmp-file-loader";import{registerGracefulShutdown as W}from"../../../utils/helpers/runtime/shutdown";let q=null,B=null;function X(D=process.cwd(),j=z.tmpBaseName,b=z.tmpExtension){const A=K.resolve(D);if(Q(A)){const E=O(A);if(!J.existsSync(E))throw Error(`${z.packageRootFolder}/tmp.yml not found. Run ${z.cliName} tmp or ensureCoreTmpEntry() before starting ${z.packageName}`);M(A,E);return E}const H=U(A,j,b);if(!H)throw Error(`${j}${b.startsWith(".")?b:`.${b}`} file not found`);return H}export function getTmpLoaderPath(){if(!B)B=X();return B}export function getTmpLoader(){if(!q){q=new V({filePath:getTmpLoaderPath()});W()}return q}export function getTmpSnapshot(){return getTmpLoader().getResolvedTmpFile()}export function onTmpReload(D){const j=getTmpLoader(),b=()=>D(j.getResolvedTmpFile());j.on("reload",b);return()=>j.off("reload",b)}export function stopTmpLoader(){if(q){q.stop();q=null;B=null}}export function resetTmpLoaderForTests(){stopTmpLoader()}
|
|
@@ -35,13 +35,10 @@ export type TmpRuntimeConfigs = {
|
|
|
35
35
|
core: TmpCoreBlock;
|
|
36
36
|
rootFolderPath: string;
|
|
37
37
|
};
|
|
38
|
-
/** `paths.root` → folder name under project root (`x`, `infra`). */
|
|
39
38
|
export declare function normalizeRootFolder(value?: string): string;
|
|
40
|
-
/** `paths.source` → dev/build source folder (`./source`, `./src`). */
|
|
41
39
|
export declare function normalizeSourceFolder(value?: string): string;
|
|
42
40
|
export declare function readTmpCoreBlock(configs?: Record<string, unknown>): TmpCoreBlock;
|
|
43
41
|
export declare function readTmpServiceBlock(configs?: Record<string, unknown>): TmpServiceBlock;
|
|
44
42
|
export declare function resolveServiceLayoutPaths(service: TmpServiceBlock): TmpLayoutPathsFlat;
|
|
45
|
-
/** Canonical tmp.yml shape — `service` + `core` + derived `rootFolderPath`. */
|
|
46
43
|
export declare function resolveTmpRuntimeConfigs(tmp?: Record<string, unknown> | null): TmpRuntimeConfigs;
|
|
47
44
|
export declare function normalizeTmpDocument(tmp: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import K from"../../../utils/constants/defaults.json" with { type: 'json' };import{seedFromTmp as G}from"../../../utils/helpers/tmp/seed-from-tmp";import{normalizeLayoutPaths as O,normalizeRootFolder as Q,normalizeSourceFolder as U}from"../../../utils/helpers/tmp/path-normalize";function A(j){return typeof j==="object"&&j!==null&&!Array.isArray(j)}function X(j){if(typeof j==="number"||typeof j==="string")return j;return}export function normalizeRootFolder(j){return Q(j,K.packageRootFolder)}export function normalizeSourceFolder(j){return U(j,G.sourceFolder)}export function readTmpCoreBlock(j){const q=A(j?.core)?j.core:{},x=A(q.tmp)?q.tmp:{};return{tmp:{fileWatchIntervalMs:X(x.fileWatchIntervalMs)}}}export function readTmpServiceBlock(j){const q=A(j?.service)?j.service:{},x=A(q.paths)?q.paths:{},D=A(x.special)?x.special:{};let E=A(q.loaders)?{...q.loaders}:void 0,H=A(q.build)?q.build:void 0;if(E&&A(E.build)){const{build:J,...M}=E;E=M;if(!H&&A(J))H=J}return{name:typeof q.name==="string"?q.name:void 0,framework:typeof q.framework==="string"?q.framework:void 0,paths:{root:typeof x.root==="string"?x.root:void 0,source:typeof x.source==="string"?x.source:void 0,special:{tests:typeof D.tests==="string"?D.tests:void 0,environments:typeof D.environments==="string"?D.environments:void 0,dist:typeof D.dist==="string"?D.dist:void 0}},protocols:q.protocols,loaders:E,build:H}}export function resolveServiceLayoutPaths(j){return O(j.paths?.special,G.layout)}function Y(j){const q=resolveServiceLayoutPaths(j);return{name:j.name,framework:j.framework??G.framework,paths:{root:j.paths?.root??K.packageRootFolder,source:j.paths?.source??G.sourceFolder,special:q},protocols:j.protocols,loaders:j.loaders,build:j.build}}function Z(j){return{tmp:{fileWatchIntervalMs:j.tmp?.fileWatchIntervalMs}}}export function resolveTmpRuntimeConfigs(j){const q=A(j?.configs)?j.configs:{},x=readTmpServiceBlock(q),D=readTmpCoreBlock(q),E=Y(x);return{service:E,core:Z(D),rootFolderPath:normalizeRootFolder(E.paths.root)}}export function normalizeTmpDocument(j){return{...j,configs:resolveTmpRuntimeConfigs(j)}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import I
|
|
1
|
+
import{packageDefaults as I}from"../../../utils/constants";import{readTmpCoreBlock as J}from"../../../utils/helpers/tmp/tmp-schema";const b=I.tmpWatchDefaults;export function resolveTmpWatchIntervalMs(q){const v=q?.configs,y=J(v).tmp?.fileWatchIntervalMs??b.intervalMs,j=Number(y);if(!Number.isFinite(j))return b.intervalMs;const z=b.minIntervalMs??100,G=b.maxIntervalMs??1e4;return Math.min(G,Math.max(z,Math.round(j)))}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var __filename="/home/runner/work/-xrystal-core/-xrystal-core/x/dist/utils/models/classes/class.x.js";import{createContainer as
|
|
1
|
+
var __filename="/home/runner/work/-xrystal-core/-xrystal-core/x/dist/utils/models/classes/class.x.js";import{createContainer as V,asClass as K,asValue as j,InjectionMode as N,listModules as X,Lifetime as Z}from"awilix";import R from"node:path";import{pathToFileURL as x}from"node:url";import C from"../../../utils/constants/defaults.json" with { type: 'json' };export const xSymbol=Symbol.for(`${C.packageName}/di-container`);class T{checkRegistration(q,A){return!!q.registrations[A]}}class U extends T{container;initializedNames=new Set;loadedPaths=new Set;registeredClasses=new Set;isInitializing=!1;constructor(){super();this.container=V({injectionMode:N.PROXY,strict:!0})}getName(q){if(typeof q==="string")return q.charAt(0).toLowerCase()+q.slice(1);if(typeof q==="function"&&q.name)return q.name.charAt(0).toLowerCase()+q.name.slice(1);return""}async load(q,A={}){const{verbose:H=!1,exclude:$=[],lifetime:E=Z.SINGLETON}=A,B=process.cwd(),G=(Array.isArray(q)?q:[q]).map((Q)=>{return(R.isAbsolute(Q)?Q:R.resolve(B,Q)).replace(/\\/g,"/").toLowerCase()});let O=[];try{O=X(G)}catch(Q){return this}for(const Q of O){const Y=Q.path.replace(/\\/g,"/").toLowerCase();if(this.loadedPaths.has(Y))continue;if(Y===__filename.replace(/\\/g,"/").toLowerCase()||Y.endsWith(".d.ts"))continue;try{const F=await import(x(Q.path).href);let J=F.default;if(!J)J=Object.values(F).find((W)=>typeof W==="function"&&!!W.prototype&&!!W.name);if(typeof J==="function"&&!!J.prototype&&!!J.name){if(this.registeredClasses.has(J))continue;const W=this.getName(J);if(W&&!this.checkRegistration(this.container,W)){this.container.register({[W]:K(J).setLifetime(E)});this.loadedPaths.add(Y);this.registeredClasses.add(J)}}}catch(w){if(H)console.error("[DI] Load Error:",w.message)}}return this}register(q,A=Z.SINGLETON){const H=this.getName(q);if(!H||this.registeredClasses.has(q))return this;if(this.checkRegistration(this.container,H))return this;this.container.register({[H]:K(q).setLifetime(A)});this.registeredClasses.add(q);return this}registerInstance(q,A){if(!q)return this;const H=this.getName(q);this.container.register({[H]:j(A)});return this}async initialize(q,A=!1){if(this.isInitializing)return this;this.isInitializing=!0;try{const H=q?Array.isArray(q)?q:[q]:[];for(const E of H){const B=this.getName(E.service);if(!B||this.initializedNames.has(B))continue;const G=this.container.registrations[B];if(!G||G.lifetime!==Z.SINGLETON)continue;try{const O=this.container.cradle[B];if(O&&typeof O.onInit==="function")await O.onInit(E.props||{});this.initializedNames.add(B)}catch(O){if(A)console.error(`[DI] Priority onInit Failed (${B}):`,O.message)}}const $=Object.keys(this.container.registrations);for(const E of $){if(this.initializedNames.has(E))continue;if(this.container.registrations[E].lifetime!==Z.SINGLETON)continue;try{const G=this.container.cradle[E];if(G&&typeof G.onInit==="function")await G.onInit({});this.initializedNames.add(E)}catch(G){if(A)console.error(`[DI] Auto onInit Failed (${E}):`,G.message)}}for(const E of this.initializedNames)try{const B=this.container.cradle[E];if(B&&typeof B.onAfterInit==="function")await B.onAfterInit()}catch(B){if(A)console.error(`[DI] onAfterInit Failed (${E}):`,B.message)}}finally{this.isInitializing=!1}return this}get(q){const A=this.getName(q);return this.container.resolve(A)}async shutdown(){for(const q of this.initializedNames)try{const A=this.container.cradle[q];if(A&&typeof A.onDispose==="function")await A.onDispose()}catch(A){console.error(`[DI] onDispose Failed (${q})`)}await this.container.dispose()}get cradle(){return this.container.cradle}}const _=globalThis;if(!_[xSymbol])_[xSymbol]=new U;export default _[xSymbol];
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk'
|
|
2
|
-
import { printCommandHeader } from '../helpers/banner.mjs'
|
|
3
|
-
import { readCliPackageJson } from '../helpers/project-root.mjs'
|
|
4
|
-
|
|
5
|
-
import { syncProjectToolchain, auditTsconfigAlignment } from '../helpers/toolchain-config.mjs'
|
|
6
|
-
import { getProjectRoot } from '../helpers/project-root.mjs'
|
|
7
|
-
|
|
8
|
-
export function registerSyncToolchainCommand(cli, { cliName = 'xcore' } = {}) {
|
|
9
|
-
cli
|
|
10
|
-
.command('sync-toolchain')
|
|
11
|
-
.description('Sync tsconfig paths from tmp.yml layout')
|
|
12
|
-
.option('--dry-run', 'Show changes without writing tsconfig.json')
|
|
13
|
-
.action((options) => {
|
|
14
|
-
const root = getProjectRoot()
|
|
15
|
-
const auditBefore = auditTsconfigAlignment(root)
|
|
16
|
-
|
|
17
|
-
printCommandHeader({ cliName, command: 'sync-toolchain', version: readCliPackageJson().version })
|
|
18
|
-
console.log(chalk.gray(` root: ${root}`))
|
|
19
|
-
|
|
20
|
-
const lo = auditBefore.layoutOptions ?? {}
|
|
21
|
-
console.log(chalk.gray(' tmp.yml layout:'))
|
|
22
|
-
console.log(chalk.gray(` paths.root: ${lo.rootFolderPath ?? 'x'}`))
|
|
23
|
-
console.log(chalk.gray(` paths.source: ${lo.mainFolderPath ?? './source'}`))
|
|
24
|
-
console.log(chalk.gray(` paths.dist: ${lo.pathsDist ?? 'dist'}`))
|
|
25
|
-
|
|
26
|
-
if (options.dryRun) {
|
|
27
|
-
const preview = syncProjectToolchain(root, { write: false })
|
|
28
|
-
console.log(chalk.gray('\n would write tsconfig.json:'))
|
|
29
|
-
console.log(chalk.gray(` include: ${JSON.stringify(preview.merged.include)}`))
|
|
30
|
-
console.log(chalk.gray(` outDir: ${preview.merged.compilerOptions.outDir}`))
|
|
31
|
-
console.log(chalk.gray(` paths: ${JSON.stringify(preview.merged.compilerOptions.paths)}`))
|
|
32
|
-
console.log(chalk.gray(`\n bunfig.toml → ${preview.paths.bunfigAliasLine}\n`))
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const result = syncProjectToolchain(root, { write: true })
|
|
37
|
-
console.log(result.created ? chalk.green(` created ${result.tsconfigRel}`) : chalk.green(` updated ${result.tsconfigRel}`))
|
|
38
|
-
console.log(chalk.gray(` include → ${JSON.stringify(result.merged.include)}`))
|
|
39
|
-
console.log(chalk.gray(` outDir → ${result.merged.compilerOptions.outDir}`))
|
|
40
|
-
console.log(chalk.gray(` eslint → ${result.paths.eslintFiles.join(', ')}`))
|
|
41
|
-
console.log(chalk.yellow(`\n bunfig.toml [resolve.alias]: ${result.paths.bunfigAliasLine}\n`))
|
|
42
|
-
})
|
|
43
|
-
}
|