@xrystal/core 3.28.3 → 3.37.3
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 +2331 -21
- package/package.json +66 -24
- package/tsconfig.base.json +15 -0
- package/x/bin/commands/create.mjs +136 -0
- package/x/bin/commands/doctor.mjs +149 -0
- package/x/bin/commands/hooks.mjs +55 -0
- package/x/bin/commands/project.mjs +126 -0
- package/x/bin/commands/release.mjs +66 -0
- package/x/bin/commands/sync-toolchain.mjs +43 -0
- package/x/bin/commands/tmp.mjs +57 -0
- package/x/bin/constants/index.mjs +6 -0
- package/x/bin/helpers/.generated/.generated-from +1 -0
- package/x/bin/helpers/.generated/tmp-schema.mjs +192 -0
- package/x/bin/helpers/banner.mjs +80 -0
- package/x/bin/helpers/build-config.mjs +342 -0
- package/x/bin/helpers/cli-help.mjs +164 -0
- package/x/bin/helpers/cli-identity.mjs +17 -0
- package/x/bin/helpers/create-target.mjs +35 -0
- package/{bin → x/bin}/helpers/index.mjs +44 -1
- package/x/bin/helpers/project-artifacts.mjs +140 -0
- package/x/bin/helpers/project-root.mjs +70 -0
- package/x/bin/helpers/runtime-info.mjs +172 -0
- package/x/bin/helpers/tmp-config.mjs +67 -0
- package/x/bin/helpers/tmp-layout.mjs +281 -0
- package/x/bin/helpers/tmp-schema.mjs +9 -0
- package/x/bin/helpers/toolchain-config.mjs +233 -0
- package/x/bin/main-cli.js +80 -0
- package/x/bin/paths.mjs +14 -0
- package/x/bin/scripts/clean-source-types.mjs +19 -0
- package/x/bin/scripts/fix-dist-imports.mjs +80 -0
- package/x/bin/scripts/install-git-hooks.mjs +86 -0
- package/x/bin/scripts/minify-dist.mjs +50 -0
- package/x/bin/scripts/prepare-npm-publish.mjs +49 -0
- package/x/bin/scripts/release-prepare.mjs +56 -0
- package/x/bin/scripts/tag.mjs +17 -0
- package/x/bin/scripts/unpublish-leaked-versions.mjs +62 -0
- package/x/bin/scripts/verify-npm-pack.mjs +45 -0
- package/x/bin/scripts/verify-version-bump.mjs +27 -0
- package/x/bin/scripts/version-check.mjs +370 -0
- package/x/dist/index.d.ts +3 -0
- package/x/dist/index.js +1 -0
- package/{source → x/dist}/loader/clients/index.d.ts +2 -1
- package/x/dist/loader/clients/index.js +1 -0
- package/{source → x/dist}/loader/configs/index.d.ts +3 -2
- package/x/dist/loader/configs/index.js +1 -0
- package/x/dist/loader/controller/index.d.ts +69 -0
- package/x/dist/loader/controller/index.js +1 -0
- package/x/dist/loader/dto/index.d.ts +39 -0
- package/x/dist/loader/dto/index.js +1 -0
- package/{source → x/dist}/loader/events/index.d.ts +1 -1
- package/x/dist/loader/events/index.js +1 -0
- package/{source → x/dist}/loader/index.d.ts +2 -1
- package/x/dist/loader/index.js +1 -0
- package/{source → x/dist}/loader/kafka/index.d.ts +6 -3
- package/x/dist/loader/kafka/index.js +1 -0
- package/{source → x/dist}/loader/localizations/index.d.ts +4 -3
- package/x/dist/loader/localizations/index.js +1 -0
- package/{source → x/dist}/loader/logger/index.d.ts +10 -7
- package/x/dist/loader/logger/index.js +2 -0
- package/x/dist/loader/service/index.js +1 -0
- package/{source → x/dist}/loader/system/index.d.ts +4 -3
- package/x/dist/loader/system/index.js +1 -0
- package/{source → x/dist}/project/index.d.ts +2 -2
- package/x/dist/project/index.js +1 -0
- package/x/dist/utils/constants/defaults.json +44 -0
- package/x/dist/utils/constants/index.d.ts +27 -0
- package/x/dist/utils/constants/index.js +1 -0
- package/x/dist/utils/helpers/configs/index.js +1 -0
- package/x/dist/utils/helpers/context/controller-store.d.ts +51 -0
- package/x/dist/utils/helpers/context/controller-store.js +1 -0
- package/x/dist/utils/helpers/context/index.d.ts +18 -0
- package/x/dist/utils/helpers/context/index.js +1 -0
- package/{source → x/dist}/utils/helpers/core/index.d.ts +8 -6
- package/x/dist/utils/helpers/core/index.js +1 -0
- package/x/dist/utils/helpers/core/paths.d.ts +2 -0
- package/x/dist/utils/helpers/core/paths.js +1 -0
- package/x/dist/utils/helpers/core/tmp-layout.d.ts +45 -0
- package/x/dist/utils/helpers/core/tmp-layout.js +1 -0
- package/{source → x/dist}/utils/helpers/date/index.d.ts +1 -1
- package/x/dist/utils/helpers/date/index.js +1 -0
- package/x/dist/utils/helpers/dispatch/index.d.ts +9 -0
- package/x/dist/utils/helpers/dispatch/index.js +1 -0
- package/x/dist/utils/helpers/dto/index.d.ts +10 -0
- package/x/dist/utils/helpers/dto/index.js +1 -0
- package/x/dist/utils/helpers/filters/index.js +1 -0
- package/x/dist/utils/helpers/framework/index.d.ts +3 -0
- package/x/dist/utils/helpers/framework/index.js +1 -0
- package/x/dist/utils/helpers/handlers/adapters.d.ts +10 -0
- package/x/dist/utils/helpers/handlers/adapters.js +1 -0
- package/x/dist/utils/helpers/handlers/execute.d.ts +5 -0
- package/x/dist/utils/helpers/handlers/execute.js +1 -0
- package/x/dist/utils/helpers/handlers/index.d.ts +18 -0
- package/x/dist/utils/helpers/handlers/index.js +1 -0
- package/x/dist/utils/helpers/hash/crypto.js +1 -0
- package/x/dist/utils/helpers/id/index.js +1 -0
- package/x/dist/utils/helpers/index.d.ts +26 -0
- package/x/dist/utils/helpers/index.js +1 -0
- package/x/dist/utils/helpers/ip/index.js +1 -0
- package/x/dist/utils/helpers/is/index.js +1 -0
- package/{source → x/dist}/utils/helpers/locales/index.d.ts +1 -0
- package/x/dist/utils/helpers/locales/index.js +1 -0
- package/x/dist/utils/helpers/math/index.js +1 -0
- package/x/dist/utils/helpers/middleware/index.d.ts +19 -0
- package/x/dist/utils/helpers/middleware/index.js +1 -0
- package/x/dist/utils/helpers/objects/index.js +1 -0
- package/x/dist/utils/helpers/path/index.js +1 -0
- package/x/dist/utils/helpers/protocol/index.d.ts +20 -0
- package/x/dist/utils/helpers/protocol/index.js +1 -0
- package/x/dist/utils/helpers/protocol/options.d.ts +6 -0
- package/x/dist/utils/helpers/protocol/options.js +1 -0
- package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-access.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/dto-access.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-types.d.ts +19 -0
- package/x/dist/utils/helpers/runtime/dto-types.js +1 -0
- package/x/dist/utils/helpers/runtime/index.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/index.js +1 -0
- package/x/dist/utils/helpers/runtime/shutdown.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/shutdown.js +1 -0
- package/x/dist/utils/helpers/state/index.d.ts +59 -0
- package/x/dist/utils/helpers/state/index.js +1 -0
- package/x/dist/utils/helpers/state/props-from-tmp.d.ts +9 -0
- package/x/dist/utils/helpers/state/props-from-tmp.js +1 -0
- package/x/dist/utils/helpers/state/request-key-guard.d.ts +3 -0
- package/x/dist/utils/helpers/state/request-key-guard.js +1 -0
- package/x/dist/utils/helpers/state/scopes.d.ts +21 -0
- package/x/dist/utils/helpers/state/scopes.js +1 -0
- package/x/dist/utils/helpers/string/index.js +1 -0
- package/x/dist/utils/helpers/tests/tmp-schema.test.js +1 -0
- package/{source/utils/models/types/index.js → x/dist/utils/helpers/tests/tmp-watch.test.d.ts} +0 -1
- package/x/dist/utils/helpers/tests/tmp-watch.test.js +1 -0
- package/x/dist/utils/helpers/timer/index.js +1 -0
- package/x/dist/utils/helpers/tmp/index.d.ts +5 -0
- package/x/dist/utils/helpers/tmp/index.js +1 -0
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.d.ts +4 -0
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +1 -0
- package/x/dist/utils/helpers/tmp/runtime-tmp.d.ts +9 -0
- package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-loader.d.ts +7 -0
- package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +47 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-watch.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -0
- package/x/dist/utils/helpers/validates/index.js +1 -0
- package/x/dist/utils/index.d.ts +3 -0
- package/x/dist/utils/index.js +1 -0
- package/x/dist/utils/models/classes/class.clients.js +1 -0
- package/x/dist/utils/models/classes/class.interfaces.js +1 -0
- package/x/dist/utils/models/classes/class.service-locator.js +1 -0
- package/{source → x/dist}/utils/models/classes/class.tmp-file-loader.d.ts +3 -2
- package/x/dist/utils/models/classes/class.tmp-file-loader.js +1 -0
- package/x/dist/utils/models/classes/class.x.js +1 -0
- package/{source → x/dist}/utils/models/enums/index.d.ts +14 -1
- package/x/dist/utils/models/enums/index.js +1 -0
- package/x/dist/utils/models/index.d.ts +9 -0
- package/x/dist/utils/models/index.js +1 -0
- package/x/dist/utils/models/types/index.d.ts +5 -0
- package/x/dist/utils/models/types/index.js +1 -0
- package/x/dist/utils/package-root.d.ts +2 -0
- package/x/dist/utils/package-root.js +1 -0
- package/x/tmp.yml +48 -17
- package/bin/constants/index.mjs +0 -17
- package/bin/main-cli.js +0 -131
- package/source/index.js +0 -6
- package/source/loader/clients/index.js +0 -18
- package/source/loader/configs/index.js +0 -81
- package/source/loader/controller/index.d.ts +0 -129
- package/source/loader/controller/index.js +0 -327
- package/source/loader/events/index.js +0 -44
- package/source/loader/index.js +0 -10
- package/source/loader/kafka/index.js +0 -122
- package/source/loader/localizations/index.js +0 -40
- package/source/loader/logger/index.js +0 -183
- package/source/loader/service/index.js +0 -7
- package/source/loader/system/index.js +0 -19
- package/source/project/index.js +0 -66
- package/source/utils/constants/index.d.ts +0 -10
- package/source/utils/constants/index.js +0 -11
- package/source/utils/helpers/configs/index.js +0 -1
- package/source/utils/helpers/core/index.js +0 -105
- package/source/utils/helpers/date/index.js +0 -48
- package/source/utils/helpers/filters/index.js +0 -44
- package/source/utils/helpers/hash/crypto.js +0 -22
- package/source/utils/helpers/id/index.js +0 -24
- package/source/utils/helpers/index.d.ts +0 -17
- package/source/utils/helpers/index.js +0 -17
- package/source/utils/helpers/ip/index.js +0 -21
- package/source/utils/helpers/is/index.js +0 -35
- package/source/utils/helpers/locales/index.js +0 -63
- package/source/utils/helpers/math/index.js +0 -14
- package/source/utils/helpers/middlewares/index.d.ts +0 -1
- package/source/utils/helpers/middlewares/index.js +0 -26
- package/source/utils/helpers/objects/index.js +0 -55
- package/source/utils/helpers/path/index.js +0 -4
- package/source/utils/helpers/regex/checkSpecialRegexControl.js +0 -3
- package/source/utils/helpers/string/index.js +0 -9
- package/source/utils/helpers/timer/index.js +0 -5
- package/source/utils/helpers/validates/index.js +0 -20
- package/source/utils/index.d.ts +0 -3
- package/source/utils/index.js +0 -3
- package/source/utils/models/classes/class.clients.js +0 -142
- package/source/utils/models/classes/class.dtos.d.ts +0 -47
- package/source/utils/models/classes/class.dtos.js +0 -36
- package/source/utils/models/classes/class.interfaces.js +0 -10
- package/source/utils/models/classes/class.response.d.ts +0 -17
- package/source/utils/models/classes/class.response.js +0 -35
- package/source/utils/models/classes/class.service-locator.js +0 -16
- package/source/utils/models/classes/class.tmp-file-loader.js +0 -38
- package/source/utils/models/classes/class.x.js +0 -179
- package/source/utils/models/enums/index.js +0 -133
- package/source/utils/models/index.d.ts +0 -11
- package/source/utils/models/index.js +0 -11
- package/source/utils/models/types/index.d.ts +0 -3
- /package/{source → x/dist}/loader/service/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/configs/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/filters/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/hash/crypto.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/id/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/ip/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/is/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/math/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/objects/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/path/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/regex/checkSpecialRegexControl.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/string/index.d.ts +0 -0
- /package/{source/index.d.ts → x/dist/utils/helpers/tests/tmp-schema.test.d.ts} +0 -0
- /package/{source → x/dist}/utils/helpers/timer/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/validates/index.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.clients.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.interfaces.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.service-locator.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.x.d.ts +0 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import yaml from 'yaml'
|
|
4
|
+
|
|
5
|
+
import { packageDefaults } from '../paths.mjs'
|
|
6
|
+
import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
|
|
7
|
+
import { normalizeTmpDocument, readTmpServiceBlock } from './tmp-schema.mjs'
|
|
8
|
+
|
|
9
|
+
export const CLI_BUILD_SCRIPT_RE = /^(xcore|xrystal|tmp)\s+build\b/
|
|
10
|
+
|
|
11
|
+
const BUILD_DEFAULTS = packageDefaults.buildDefaults ?? {}
|
|
12
|
+
|
|
13
|
+
export function isCorePackageName(name) {
|
|
14
|
+
return name === packageDefaults.packageName
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function shouldDelegatePackageBuild(pkg) {
|
|
18
|
+
const buildScript = pkg.scripts?.build?.trim() ?? ''
|
|
19
|
+
if (!buildScript) return false
|
|
20
|
+
if (isCorePackageName(pkg.name)) return false
|
|
21
|
+
if (CLI_BUILD_SCRIPT_RE.test(buildScript)) return false
|
|
22
|
+
return true
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function readTmpBuildContext(root) {
|
|
26
|
+
const ensured = ensureTmpFile(root)
|
|
27
|
+
const tmp = normalizeTmpDocument(yaml.parse(fs.readFileSync(ensured.tmpFilePath, 'utf8')))
|
|
28
|
+
const configs = tmp.configs ?? {}
|
|
29
|
+
const build = readTmpServiceBlock(configs).build ?? {}
|
|
30
|
+
return { layout: ensured.layout, configs, build }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function normalizeMainFolder(mainFolderPath = packageDefaults.mainSourceFolder) {
|
|
34
|
+
const trimmed = String(mainFolderPath).trim() || packageDefaults.mainSourceFolder
|
|
35
|
+
if (trimmed.startsWith('./') || trimmed.startsWith('../')) return trimmed
|
|
36
|
+
return `./${trimmed}`
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function resolveTsconfigRel(root, buildConfig = {}) {
|
|
40
|
+
const configured =
|
|
41
|
+
typeof buildConfig.tsconfig === 'string' && buildConfig.tsconfig.trim()
|
|
42
|
+
? buildConfig.tsconfig.trim()
|
|
43
|
+
: BUILD_DEFAULTS.tsconfig ?? 'tsconfig.json'
|
|
44
|
+
|
|
45
|
+
const abs = path.isAbsolute(configured) ? configured : path.join(root, configured)
|
|
46
|
+
if (!fs.existsSync(abs)) return null
|
|
47
|
+
return relativeFromRoot(root, abs)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function readTsconfigJson(root, buildConfig = {}) {
|
|
51
|
+
const rel = resolveTsconfigRel(root, buildConfig)
|
|
52
|
+
if (!rel) return null
|
|
53
|
+
|
|
54
|
+
const abs = path.join(root, rel)
|
|
55
|
+
let raw
|
|
56
|
+
try {
|
|
57
|
+
raw = JSON.parse(fs.readFileSync(abs, 'utf8'))
|
|
58
|
+
} catch (error) {
|
|
59
|
+
throw new Error(`Failed to parse ${rel}: ${error instanceof Error ? error.message : error}`)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
rel,
|
|
64
|
+
raw,
|
|
65
|
+
compilerOptions: raw.compilerOptions ?? {},
|
|
66
|
+
include: Array.isArray(raw.include) ? raw.include : null,
|
|
67
|
+
exclude: Array.isArray(raw.exclude) ? raw.exclude : null,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function includeToEntryGlobs(include) {
|
|
72
|
+
const items = Array.isArray(include) && include.length > 0 ? include : null
|
|
73
|
+
if (!items) return null
|
|
74
|
+
|
|
75
|
+
const globs = []
|
|
76
|
+
for (const item of items.map(String)) {
|
|
77
|
+
const trimmed = item.trim()
|
|
78
|
+
if (!trimmed) continue
|
|
79
|
+
|
|
80
|
+
const normalized = trimmed.startsWith('./') || trimmed.startsWith('../') ? trimmed : `./${trimmed}`
|
|
81
|
+
|
|
82
|
+
if (normalized.includes('*')) {
|
|
83
|
+
if (normalized.endsWith('.ts')) {
|
|
84
|
+
globs.push(normalized)
|
|
85
|
+
continue
|
|
86
|
+
}
|
|
87
|
+
const base = normalized.replace(/\/+$/, '')
|
|
88
|
+
globs.push(`${base}/*.ts`, `${base}/**/*.ts`)
|
|
89
|
+
continue
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
globs.push(`${normalized}/*.ts`, `${normalized}/**/*.ts`)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return globs.length > 0 ? [...new Set(globs)] : null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function sourcemapFromTsconfig(compilerOptions = {}) {
|
|
99
|
+
if (compilerOptions.inlineSourceMap === true) return 'inline'
|
|
100
|
+
if (compilerOptions.sourceMap === true) return 'linked'
|
|
101
|
+
if (compilerOptions.sourceMap === false) return false
|
|
102
|
+
return undefined
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function declarationsFromTsconfig(compilerOptions = {}) {
|
|
106
|
+
if (compilerOptions.emitDeclarationOnly === true) return true
|
|
107
|
+
if (compilerOptions.declaration === false) return false
|
|
108
|
+
return undefined
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function resolveBuildEntryGlobs(mainFolderPath, buildConfig = {}, tsconfig = null) {
|
|
112
|
+
if (Array.isArray(buildConfig.entries) && buildConfig.entries.length > 0) {
|
|
113
|
+
return buildConfig.entries.map(String)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (typeof buildConfig.glob === 'string' && buildConfig.glob.trim()) {
|
|
117
|
+
const glob = buildConfig.glob.trim()
|
|
118
|
+
if (glob.includes('*')) {
|
|
119
|
+
const flat = glob.replace(/\/\*\*\/\*\.ts$/, '/*.ts')
|
|
120
|
+
return flat === glob ? [glob] : [flat, glob]
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const fromInclude = includeToEntryGlobs(tsconfig?.include)
|
|
125
|
+
if (fromInclude) return fromInclude
|
|
126
|
+
|
|
127
|
+
const rootDir = tsconfig?.compilerOptions?.rootDir
|
|
128
|
+
if (typeof rootDir === 'string' && rootDir.trim()) {
|
|
129
|
+
const fromRootDir = includeToEntryGlobs([rootDir])
|
|
130
|
+
if (fromRootDir) return fromRootDir
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const main = normalizeMainFolder(mainFolderPath)
|
|
134
|
+
return [`${main}/*.ts`, `${main}/**/*.ts`]
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function resolveDistRel(root, layout) {
|
|
138
|
+
return relativeFromRoot(root, layout.pathsAbs.dist)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function resolveDistRelWithTsconfig(root, layout, buildConfig = {}, tsconfig = null) {
|
|
142
|
+
if (typeof buildConfig.outDir === 'string' && buildConfig.outDir.trim()) {
|
|
143
|
+
const abs = path.isAbsolute(buildConfig.outDir)
|
|
144
|
+
? buildConfig.outDir
|
|
145
|
+
: path.join(root, buildConfig.outDir.trim())
|
|
146
|
+
return relativeFromRoot(root, abs)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const outDir = tsconfig?.compilerOptions?.outDir
|
|
150
|
+
if (typeof outDir === 'string' && outDir.trim()) {
|
|
151
|
+
const abs = path.isAbsolute(outDir) ? outDir : path.join(root, outDir.trim())
|
|
152
|
+
return relativeFromRoot(root, abs)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return resolveDistRel(root, layout)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function resolveDistEntryAbs(root, layout, buildConfig = {}) {
|
|
159
|
+
const tsconfig = readTsconfigJson(root, buildConfig)
|
|
160
|
+
const distRel = resolveDistRelWithTsconfig(root, layout, buildConfig, tsconfig)
|
|
161
|
+
const distAbs = path.join(root, distRel)
|
|
162
|
+
return path.join(distAbs, 'index.js')
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function resolveTypecheckEnabled(buildConfig = {}) {
|
|
166
|
+
if (typeof buildConfig.typecheck === 'boolean') return buildConfig.typecheck
|
|
167
|
+
return BUILD_DEFAULTS.typecheck ?? false
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function resolveDeclarationsEnabled(buildConfig = {}, tsconfig = null) {
|
|
171
|
+
if (typeof buildConfig.declarations === 'boolean') return buildConfig.declarations
|
|
172
|
+
const fromTsconfig = declarationsFromTsconfig(tsconfig?.compilerOptions ?? {})
|
|
173
|
+
if (typeof fromTsconfig === 'boolean') return fromTsconfig
|
|
174
|
+
return BUILD_DEFAULTS.declarations ?? false
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function resolveMinifyEnabled(buildConfig = {}) {
|
|
178
|
+
const raw = buildConfig.minify ?? buildConfig.protect ?? buildConfig.compress ?? BUILD_DEFAULTS.minify ?? false
|
|
179
|
+
if (raw === false || raw === 'off' || raw === 'none' || raw === 0 || raw === null) return false
|
|
180
|
+
return true
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** tmp.yml build.minify / build.protect — strip comments/whitespace, mangle identifiers. */
|
|
184
|
+
export function resolveMinifyFlags(buildConfig = {}) {
|
|
185
|
+
const raw = buildConfig.minify ?? buildConfig.protect ?? buildConfig.compress ?? BUILD_DEFAULTS.minify ?? false
|
|
186
|
+
|
|
187
|
+
if (raw === false || raw === 'off' || raw === 'none' || raw === 0 || raw === null) return []
|
|
188
|
+
|
|
189
|
+
if (raw === true || raw === 'on' || raw === 'all') return ['--minify']
|
|
190
|
+
if (raw === 'production' || raw === 'prod') return ['--production']
|
|
191
|
+
|
|
192
|
+
if (typeof raw === 'object') {
|
|
193
|
+
if (raw.minify === true || raw.protect === true || raw.all === true) return ['--minify']
|
|
194
|
+
const flags = []
|
|
195
|
+
if (raw.syntax) flags.push('--minify-syntax')
|
|
196
|
+
if (raw.whitespace) flags.push('--minify-whitespace')
|
|
197
|
+
if (raw.identifiers) flags.push('--minify-identifiers')
|
|
198
|
+
return flags.length ? flags : ['--minify']
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (typeof raw === 'string' && raw.trim()) return ['--minify']
|
|
202
|
+
return ['--minify']
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function resolveSourcemapFlag(buildConfig = {}, tsconfig = null) {
|
|
206
|
+
if (resolveMinifyEnabled(buildConfig) && buildConfig.sourcemap === undefined) {
|
|
207
|
+
return ''
|
|
208
|
+
}
|
|
209
|
+
const fromTsconfig = sourcemapFromTsconfig(tsconfig?.compilerOptions ?? {})
|
|
210
|
+
const raw = buildConfig.sourcemap ?? fromTsconfig ?? BUILD_DEFAULTS.sourcemap ?? false
|
|
211
|
+
|
|
212
|
+
if (raw === false || raw === 'none' || raw === 'off' || raw === 0) return ''
|
|
213
|
+
if (raw === true || raw === 'linked' || raw === 'external') return '--sourcemap=linked'
|
|
214
|
+
if (raw === 'inline') return '--sourcemap=inline'
|
|
215
|
+
if (typeof raw === 'string' && raw.trim()) return `--sourcemap=${raw.trim()}`
|
|
216
|
+
return ''
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function withTscProject(root, buildConfig, extraArgs) {
|
|
220
|
+
const tsconfigRel = resolveTsconfigRel(root, buildConfig)
|
|
221
|
+
const projectFlag = tsconfigRel ? `--project ${tsconfigRel} ` : ''
|
|
222
|
+
return `bunx tsc ${projectFlag}${extraArgs}`.replace(/\s+/g, ' ').trim()
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function resolveTypecheckCommand(root, buildConfig = {}) {
|
|
226
|
+
const tsconfigRel = resolveTsconfigRel(root, buildConfig)
|
|
227
|
+
if (!tsconfigRel) {
|
|
228
|
+
throw new Error(
|
|
229
|
+
'build.typecheck is enabled but tsconfig was not found. Set build.tsconfig or add tsconfig.json.',
|
|
230
|
+
)
|
|
231
|
+
}
|
|
232
|
+
return withTscProject(root, buildConfig, '--noEmit')
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function resolveTscCommand(root, distRel, buildConfig = {}) {
|
|
236
|
+
const cmd = withTscProject(root, buildConfig, `--emitDeclarationOnly --declaration --outDir ${distRel}`)
|
|
237
|
+
return buildConfig.tscLenient ? `${cmd} || true` : cmd
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export function resolveBunBuildCommand(entryGlobs, distRel, buildConfig = {}, tsconfig = null) {
|
|
241
|
+
const sourcemapFlag = resolveSourcemapFlag(buildConfig, tsconfig)
|
|
242
|
+
const minifyFlags = resolveMinifyFlags(buildConfig)
|
|
243
|
+
const flags = [...minifyFlags, ...(sourcemapFlag ? [sourcemapFlag] : []), '--outdir', distRel, '--target', 'node', "--external", "'*'"]
|
|
244
|
+
return `bun build ${entryGlobs.join(' ')} ${flags.join(' ')}`.replace(/\s+/g, ' ').trim()
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function resolveEffectiveBuildOptions(root, layout, buildConfig = {}) {
|
|
248
|
+
const tsconfig = readTsconfigJson(root, buildConfig)
|
|
249
|
+
const distRel = resolveDistRelWithTsconfig(root, layout, buildConfig, tsconfig)
|
|
250
|
+
const entryGlobs = resolveBuildEntryGlobs(layout.mainFolderPath, buildConfig, tsconfig)
|
|
251
|
+
|
|
252
|
+
return {
|
|
253
|
+
tsconfig,
|
|
254
|
+
tsconfigRel: tsconfig?.rel ?? null,
|
|
255
|
+
distRel,
|
|
256
|
+
entryGlobs,
|
|
257
|
+
typecheck: resolveTypecheckEnabled(buildConfig),
|
|
258
|
+
declarations: resolveDeclarationsEnabled(buildConfig, tsconfig),
|
|
259
|
+
sourcemap: resolveSourcemapFlag(buildConfig, tsconfig) || 'false',
|
|
260
|
+
minify: resolveMinifyFlags(buildConfig).join(' ') || 'off',
|
|
261
|
+
distSource: typeof buildConfig.outDir === 'string'
|
|
262
|
+
? 'tmp.build.outDir'
|
|
263
|
+
: tsconfig?.compilerOptions?.outDir
|
|
264
|
+
? 'tsconfig.outDir'
|
|
265
|
+
: 'tmp.paths.dist',
|
|
266
|
+
globSource: Array.isArray(buildConfig.entries) && buildConfig.entries.length > 0
|
|
267
|
+
? 'tmp.build.entries'
|
|
268
|
+
: typeof buildConfig.glob === 'string' && buildConfig.glob.trim()
|
|
269
|
+
? 'tmp.build.glob'
|
|
270
|
+
: tsconfig?.include?.length
|
|
271
|
+
? 'tsconfig.include'
|
|
272
|
+
: tsconfig?.compilerOptions?.rootDir
|
|
273
|
+
? 'tsconfig.rootDir'
|
|
274
|
+
: 'tmp.mainFolderPath',
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export function resolveCoreBuildSteps(root, distRel, buildConfig = {}) {
|
|
279
|
+
const tsconfigRel = resolveTsconfigRel(root, buildConfig) ?? 'tsconfig.json'
|
|
280
|
+
const steps = [
|
|
281
|
+
`rm -rf ${distRel}`,
|
|
282
|
+
`bun run tsc --project ${tsconfigRel}`,
|
|
283
|
+
`bunx tsc-alias -p ${tsconfigRel}`,
|
|
284
|
+
]
|
|
285
|
+
if (resolveMinifyEnabled(buildConfig)) {
|
|
286
|
+
steps.push('node x/bin/scripts/minify-dist.mjs')
|
|
287
|
+
}
|
|
288
|
+
steps.push('node x/bin/scripts/fix-dist-imports.mjs')
|
|
289
|
+
steps.push('node x/bin/scripts/clean-source-types.mjs')
|
|
290
|
+
return steps
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function resolveServiceBuildSteps(root, layout, buildConfig = {}) {
|
|
294
|
+
const plan = resolveEffectiveBuildOptions(root, layout, buildConfig)
|
|
295
|
+
const steps = []
|
|
296
|
+
|
|
297
|
+
if (plan.typecheck) {
|
|
298
|
+
steps.push(resolveTypecheckCommand(root, buildConfig))
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
steps.push(
|
|
302
|
+
`rm -rf ${plan.distRel}`,
|
|
303
|
+
resolveBunBuildCommand(plan.entryGlobs, plan.distRel, buildConfig, plan.tsconfig),
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
if (plan.declarations) {
|
|
307
|
+
steps.push(resolveTscCommand(root, plan.distRel, buildConfig))
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return steps
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export function summarizeBuildPlan(root, layout, buildConfig = {}) {
|
|
314
|
+
const plan = resolveEffectiveBuildOptions(root, layout, buildConfig)
|
|
315
|
+
return {
|
|
316
|
+
distRel: plan.distRel,
|
|
317
|
+
entryGlobs: plan.entryGlobs,
|
|
318
|
+
tsconfigRel: plan.tsconfigRel,
|
|
319
|
+
typecheck: plan.typecheck,
|
|
320
|
+
declarations: plan.declarations,
|
|
321
|
+
sourcemap: plan.sourcemap,
|
|
322
|
+
minify: plan.minify,
|
|
323
|
+
distSource: plan.distSource,
|
|
324
|
+
globSource: plan.globSource,
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
export function resolveDevEntry(root, layout) {
|
|
329
|
+
const tsEntry = path.join(path.resolve(root, layout.mainFolderPath), 'index.ts')
|
|
330
|
+
if (!fs.existsSync(tsEntry)) {
|
|
331
|
+
throw new Error(
|
|
332
|
+
`No index.ts for dev (expected ${path.relative(root, tsEntry)}). Prod: ${layout.rootFolderPath}/${layout.paths.dist}/index.js via xcore start.`,
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
return relativeFromRoot(root, tsEntry)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export function resolveEnvFiles(envDir, names) {
|
|
339
|
+
return names
|
|
340
|
+
.map((name) => path.join(envDir, name))
|
|
341
|
+
.filter((file) => fs.existsSync(file))
|
|
342
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
|
|
3
|
+
import { CLI_BIN_NAMES } from './cli-identity.mjs'
|
|
4
|
+
|
|
5
|
+
export const LIST_BULLET = chalk.cyan('◆')
|
|
6
|
+
import { brandTitle } from './banner.mjs'
|
|
7
|
+
|
|
8
|
+
const QUICK_COMMANDS = [
|
|
9
|
+
{ cmd: 'create', hint: '<name> [path]', desc: 'Scaffold service · path defaults to cwd' },
|
|
10
|
+
{ cmd: 'dev', desc: 'Watch source/index.ts + dev env' },
|
|
11
|
+
{ cmd: 'build', desc: 'Bundle to dist/ (tmp.yml layout)' },
|
|
12
|
+
{ cmd: 'start', desc: 'Run production dist/index.js' },
|
|
13
|
+
{ cmd: 'test', desc: 'Run tests folder from tmp.yml' },
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
const COMMAND_GROUPS = [
|
|
17
|
+
{
|
|
18
|
+
title: 'Develop',
|
|
19
|
+
items: [
|
|
20
|
+
{ cmd: 'dev', desc: 'Watch TypeScript entry + dev env files' },
|
|
21
|
+
{ cmd: 'build', desc: 'Bun bundle + optional tsc → dist/' },
|
|
22
|
+
{ cmd: 'start', aliases: 'start:dist', desc: 'Run paths.dist/index.js (prod)' },
|
|
23
|
+
{ cmd: 'test', desc: 'Run project tests (paths.tests)' },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
title: 'Project',
|
|
28
|
+
items: [
|
|
29
|
+
{ cmd: 'create', hint: '<name> [path]', desc: 'Scaffold template · optional parent dir' },
|
|
30
|
+
{ cmd: 'tmp', desc: 'Ensure tmp.yml exists (runtime config seed)' },
|
|
31
|
+
{ cmd: 'hooks install', desc: 'Install .git/hooks pre-commit version check' },
|
|
32
|
+
{ cmd: 'hooks status', desc: 'Show whether pre-commit hook is installed' },
|
|
33
|
+
{ cmd: 'sync-toolchain', desc: 'Sync tsconfig include/outDir/@/* from tmp.yml' },
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
title: 'Diagnostics',
|
|
38
|
+
items: [
|
|
39
|
+
{ cmd: 'doctor', desc: 'Runtime · git · @xrystal/core version alignment' },
|
|
40
|
+
{ cmd: 'version', desc: 'CLI tool vs project package.json versions' },
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
title: 'Release',
|
|
45
|
+
items: [
|
|
46
|
+
{ cmd: 'tag', desc: 'Tag HEAD from package.json (+ core npm publish)' },
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
const SECTION_COLORS = {
|
|
52
|
+
Develop: chalk.bold.cyan,
|
|
53
|
+
Project: chalk.bold.green,
|
|
54
|
+
Diagnostics: chalk.bold.yellow,
|
|
55
|
+
Release: chalk.bold.magenta,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function termWidth() {
|
|
59
|
+
return Math.min(100, Math.max(56, process.stdout.columns || 80))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function commandLabel(item) {
|
|
63
|
+
const alias = item.aliases ? chalk.dim(` · ${item.aliases}`) : ''
|
|
64
|
+
const hint = item.hint ? chalk.dim(` ${item.hint}`) : ''
|
|
65
|
+
return `${chalk.bold.cyan(item.cmd)}${hint}${alias}`
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function formatTreeLines(items) {
|
|
69
|
+
const lines = []
|
|
70
|
+
for (const item of items) {
|
|
71
|
+
lines.push(` ${LIST_BULLET} ${commandLabel(item)} ${chalk.gray(item.desc)}`)
|
|
72
|
+
}
|
|
73
|
+
return lines.join('\n')
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Bare `xcore` — banner altında kısa, işe yarayan komutlar. */
|
|
77
|
+
export function printQuickStartGuide({ cliName = 'xcore' } = {}) {
|
|
78
|
+
console.log(chalk.bold.yellow('\n Quick start'))
|
|
79
|
+
console.log(formatTreeLines(QUICK_COMMANDS))
|
|
80
|
+
console.log('')
|
|
81
|
+
console.log(` ${chalk.dim('tip')} ${chalk.bold.white(`${cliName} -h`)} ${chalk.gray('· all commands & options')}`)
|
|
82
|
+
console.log(` ${chalk.dim('tip')} ${chalk.bold.white(`${cliName} doctor`)} ${chalk.gray('· verify install & versions')}`)
|
|
83
|
+
console.log('')
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function formatOptionsSection(cliName) {
|
|
87
|
+
const items = [
|
|
88
|
+
{ cmd: '-V, --version', desc: 'Show @xrystal/core CLI version' },
|
|
89
|
+
{ cmd: '-h, --help', desc: 'Show full command list' },
|
|
90
|
+
]
|
|
91
|
+
const lines = [
|
|
92
|
+
chalk.bold.white('\n Options'),
|
|
93
|
+
formatTreeLines(items.map(({ cmd, desc }) => ({ cmd, desc }))),
|
|
94
|
+
'',
|
|
95
|
+
chalk.bold.white(' Aliases'),
|
|
96
|
+
chalk.gray(` ${CLI_BIN_NAMES.join(' · ')}`),
|
|
97
|
+
'',
|
|
98
|
+
chalk.gray(` ${brandTitle()} ${chalk.dim('·')} loaders · tmp.yml · dto · i18n · multi-protocol`),
|
|
99
|
+
chalk.gray(` docs: ${cliName} help <command>`),
|
|
100
|
+
'',
|
|
101
|
+
]
|
|
102
|
+
return lines.join('\n')
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** `xcore -h` — gruplu, renkli, kompakt tam liste. */
|
|
106
|
+
export function formatRootHelp({ cliName = 'xcore' } = {}) {
|
|
107
|
+
const sections = COMMAND_GROUPS.map((group) => {
|
|
108
|
+
const paint = SECTION_COLORS[group.title] ?? chalk.bold.white
|
|
109
|
+
return `${paint(`\n ${group.title}`)}\n${formatTreeLines(group.items)}`
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
return [
|
|
113
|
+
chalk.bold.white(`\n Usage`),
|
|
114
|
+
chalk.gray(` ${cliName} [options] [command]`),
|
|
115
|
+
...sections,
|
|
116
|
+
formatOptionsSection(cliName),
|
|
117
|
+
].join('\n')
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function formatCreateHelp({ cliName = 'xcore' } = {}) {
|
|
121
|
+
const examples = [
|
|
122
|
+
{ cmd: `${cliName} create my-api`, desc: '→ ./my-api (current folder)' },
|
|
123
|
+
{ cmd: `${cliName} create my-api ..`, desc: '→ ../my-api' },
|
|
124
|
+
{ cmd: `${cliName} create my-api ~/services`, desc: '→ ~/services/my-api' },
|
|
125
|
+
{ cmd: `${cliName} create .`, desc: '→ init in current directory' },
|
|
126
|
+
]
|
|
127
|
+
return [
|
|
128
|
+
chalk.bold.white('\n Usage'),
|
|
129
|
+
chalk.gray(` ${cliName} create ${chalk.cyan('<project-name>')} ${chalk.dim('[target-path]')}`),
|
|
130
|
+
'',
|
|
131
|
+
chalk.bold.yellow(' project-name'),
|
|
132
|
+
` ${LIST_BULLET} ${chalk.gray('Required folder name, or')} ${chalk.cyan('.')} ${chalk.gray('to use the target directory itself')}`,
|
|
133
|
+
'',
|
|
134
|
+
chalk.bold.yellow(' target-path'),
|
|
135
|
+
` ${LIST_BULLET} ${chalk.gray('Optional parent directory · default:')} ${chalk.white('cwd')}`,
|
|
136
|
+
'',
|
|
137
|
+
chalk.bold.white(' Examples'),
|
|
138
|
+
formatTreeLines(examples.map(({ cmd, desc }) => ({ cmd, desc }))),
|
|
139
|
+
'',
|
|
140
|
+
].join('\n')
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function formatCreateCommandHelp({ cliName = 'xcore' } = {}) {
|
|
144
|
+
return [
|
|
145
|
+
formatCreateHelp({ cliName }),
|
|
146
|
+
chalk.bold.white(' Options'),
|
|
147
|
+
` ${LIST_BULLET} ${chalk.bold.cyan('-f, --force')} ${chalk.gray('Allow scaffold in a non-empty directory')}`,
|
|
148
|
+
'',
|
|
149
|
+
].join('\n')
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function isCreateHelpRequest(argv = process.argv) {
|
|
153
|
+
const args = argv.slice(2)
|
|
154
|
+
if (args[0] !== 'create') return false
|
|
155
|
+
if (args.length === 2 && ['-h', '--help'].includes(args[1])) return true
|
|
156
|
+
return false
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function isRootHelpRequest(argv = process.argv) {
|
|
160
|
+
const args = argv.slice(2)
|
|
161
|
+
if (!args.length) return false
|
|
162
|
+
if (args.length === 1 && ['-h', '--help', 'help'].includes(args[0])) return true
|
|
163
|
+
return false
|
|
164
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
3
|
+
export const CLI_PRIMARY_NAME = 'xcore'
|
|
4
|
+
|
|
5
|
+
/** Published bin names — same entry (`x/bin/main-cli.js`), same commands, same project root. */
|
|
6
|
+
export const CLI_BIN_NAMES = Object.freeze(['xcore', 'xrystal', 'tmp'])
|
|
7
|
+
|
|
8
|
+
export function resolveInvokedAs(argv = process.argv) {
|
|
9
|
+
const base = path.basename(argv[1] || CLI_PRIMARY_NAME)
|
|
10
|
+
if (base === 'main-cli.js') return CLI_PRIMARY_NAME
|
|
11
|
+
if (CLI_BIN_NAMES.includes(base)) return base
|
|
12
|
+
return CLI_PRIMARY_NAME
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function isKnownCliBin(name) {
|
|
16
|
+
return CLI_BIN_NAMES.includes(name)
|
|
17
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolve scaffold target directory.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} projectName Folder name or `.` for current directory
|
|
7
|
+
* @param {string | undefined} targetDir Optional parent path (default: cwd)
|
|
8
|
+
*/
|
|
9
|
+
export function resolveCreateTarget(projectName, targetDir) {
|
|
10
|
+
const cwd = process.cwd()
|
|
11
|
+
const name = String(projectName ?? '').trim()
|
|
12
|
+
|
|
13
|
+
if (!name) {
|
|
14
|
+
throw new Error('project-name is required')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (name === '.' || name === './') {
|
|
18
|
+
const parent = targetDir ? path.resolve(cwd, targetDir) : cwd
|
|
19
|
+
return {
|
|
20
|
+
targetPath: parent,
|
|
21
|
+
isCurrentDir: true,
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const base = targetDir ? path.resolve(cwd, targetDir) : cwd
|
|
26
|
+
return {
|
|
27
|
+
targetPath: path.join(base, name),
|
|
28
|
+
isCurrentDir: false,
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function formatCreateTargetPreview(projectName, targetDir) {
|
|
33
|
+
const { targetPath, isCurrentDir } = resolveCreateTarget(projectName, targetDir)
|
|
34
|
+
return { targetPath, isCurrentDir, label: isCurrentDir ? targetPath : targetPath }
|
|
35
|
+
}
|
|
@@ -80,4 +80,47 @@ export function resolveObjWithHandlebars(obj, context) {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
return obj
|
|
83
|
-
}
|
|
83
|
+
}
|
|
84
|
+
export function findAllFilesRecursively(
|
|
85
|
+
startDir,
|
|
86
|
+
baseName,
|
|
87
|
+
extName = '',
|
|
88
|
+
excludedDirs = ['node_modules', '.git'],
|
|
89
|
+
) {
|
|
90
|
+
const targetName = baseName + (extName.startsWith('.') ? extName : extName ? `.${extName}` : '')
|
|
91
|
+
const found = []
|
|
92
|
+
|
|
93
|
+
function walk(dir) {
|
|
94
|
+
if (!fs.existsSync(dir)) return
|
|
95
|
+
|
|
96
|
+
let entries
|
|
97
|
+
try {
|
|
98
|
+
entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
99
|
+
} catch {
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
for (const entry of entries) {
|
|
104
|
+
const fullPath = path.join(dir, entry.name)
|
|
105
|
+
|
|
106
|
+
if (entry.isFile()) {
|
|
107
|
+
if (!extName) {
|
|
108
|
+
const entryExt = path.extname(entry.name)
|
|
109
|
+
const entryBase = path.basename(entry.name, entryExt)
|
|
110
|
+
if (entryBase === baseName) found.push(fullPath)
|
|
111
|
+
} else if (entry.name === targetName) {
|
|
112
|
+
found.push(fullPath)
|
|
113
|
+
}
|
|
114
|
+
continue
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (entry.isDirectory()) {
|
|
118
|
+
if (entry.name.startsWith('.') || excludedDirs.includes(entry.name)) continue
|
|
119
|
+
walk(fullPath)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
walk(path.resolve(startDir))
|
|
125
|
+
return found
|
|
126
|
+
}
|