@xrystal/core 3.38.3 → 3.40.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 +397 -65
- package/package.json +2 -4
- package/x/bin/commands/create.mjs +2 -1
- package/x/bin/commands/doctor.mjs +5 -4
- package/x/bin/commands/hooks.mjs +2 -1
- package/x/bin/commands/project.mjs +2 -1
- package/x/bin/commands/release.mjs +3 -2
- package/x/bin/commands/sync.mjs +51 -0
- package/x/bin/commands/tmp.mjs +2 -1
- package/x/bin/helpers/.generated/tmp-schema.mjs +54 -85
- package/x/bin/helpers/banner.mjs +2 -2
- package/x/bin/helpers/build-config.mjs +11 -2
- package/x/bin/helpers/cli-help.mjs +9 -9
- package/x/bin/helpers/cli-identity.mjs +7 -17
- package/x/bin/helpers/defaults.json +14 -30
- package/x/bin/helpers/package-defaults.mjs +46 -12
- package/x/bin/helpers/project-artifacts.mjs +7 -0
- package/x/bin/helpers/seed-from-tmp.mjs +52 -0
- package/x/bin/helpers/toolchain-config.mjs +6 -12
- package/x/bin/main-cli.js +2 -2
- package/x/bin/scripts/install-git-hooks.mjs +3 -2
- package/x/bin/scripts/sync-cli-defaults.mjs +7 -2
- package/x/dist/project/index.js +1 -1
- package/x/dist/utils/constants/defaults.json +14 -30
- package/x/dist/utils/constants/index.d.ts +20 -12
- package/x/dist/utils/constants/index.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 +10 -0
- package/x/dist/utils/helpers/tmp/path-normalize.js +1 -0
- package/x/dist/utils/helpers/tmp/seed-from-tmp.d.ts +9 -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 +1 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -1
- package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -1
- package/x/bin/commands/sync-toolchain.mjs +0 -43
|
@@ -3,6 +3,7 @@ import fs from 'node:fs'
|
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import chalk from 'chalk'
|
|
5
5
|
|
|
6
|
+
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
6
7
|
import {
|
|
7
8
|
isCorePackageName,
|
|
8
9
|
readTmpBuildContext,
|
|
@@ -34,7 +35,7 @@ function resolveTestTarget(root) {
|
|
|
34
35
|
)
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
export function registerProjectCommands(cli, { cliName =
|
|
38
|
+
export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
38
39
|
cli
|
|
39
40
|
.command('dev')
|
|
40
41
|
.description('Watch source/index.ts with dev env files')
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
2
|
import { readCliPackageJson, readProjectPackageJson, getProjectRoot } from '../helpers/project-root.mjs'
|
|
3
3
|
import { compareSemver, getVersionState, resolveVersionBaseline, runTagRelease } from '../scripts/version-check.mjs'
|
|
4
|
+
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
4
5
|
|
|
5
|
-
export function registerTagCommand(cli, { cliName =
|
|
6
|
+
export function registerTagCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
6
7
|
cli
|
|
7
8
|
.command('tag')
|
|
8
9
|
.description('Git tag from package.json (+ npm publish for core)')
|
|
@@ -27,7 +28,7 @@ export function registerTagCommand(cli, { cliName = 'xcore' } = {}) {
|
|
|
27
28
|
})
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
export function registerVersionCommand(cli, { cliName =
|
|
31
|
+
export function registerVersionCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
31
32
|
cli
|
|
32
33
|
.command('version')
|
|
33
34
|
.description('Show CLI and project package versions')
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
|
|
3
|
+
import { printCommandHeader } from '../helpers/banner.mjs'
|
|
4
|
+
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
5
|
+
import { getProjectRoot, readCliPackageJson } from '../helpers/project-root.mjs'
|
|
6
|
+
import { auditTsconfigAlignment, syncProjectToolchain } from '../helpers/toolchain-config.mjs'
|
|
7
|
+
|
|
8
|
+
/** Sync tsconfig include/outDir/@/* from project tmp.yml. */
|
|
9
|
+
export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
10
|
+
const run = (options) => {
|
|
11
|
+
const root = getProjectRoot()
|
|
12
|
+
const auditBefore = auditTsconfigAlignment(root)
|
|
13
|
+
|
|
14
|
+
printCommandHeader({ cliName, command: 'sync', version: readCliPackageJson().version })
|
|
15
|
+
console.log(chalk.gray(` root: ${root}`))
|
|
16
|
+
|
|
17
|
+
const lo = auditBefore.layoutOptions ?? {}
|
|
18
|
+
console.log(chalk.gray(' from tmp.yml:'))
|
|
19
|
+
console.log(chalk.gray(` paths.root: ${lo.rootFolderPath ?? '—'}`))
|
|
20
|
+
console.log(chalk.gray(` paths.source: ${lo.mainFolderPath ?? '—'}`))
|
|
21
|
+
console.log(chalk.gray(` paths.dist: ${lo.pathsDist ?? '—'}`))
|
|
22
|
+
|
|
23
|
+
if (options.dryRun) {
|
|
24
|
+
const preview = syncProjectToolchain(root, { write: false })
|
|
25
|
+
console.log(chalk.gray('\n would write tsconfig.json:'))
|
|
26
|
+
console.log(chalk.gray(` include: ${JSON.stringify(preview.merged.include)}`))
|
|
27
|
+
console.log(chalk.gray(` outDir: ${preview.merged.compilerOptions.outDir}`))
|
|
28
|
+
console.log(chalk.gray(` paths: ${JSON.stringify(preview.merged.compilerOptions.paths)}`))
|
|
29
|
+
console.log(chalk.gray(`\n bunfig → ${preview.paths.bunfigAliasLine}\n`))
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const result = syncProjectToolchain(root, { write: true })
|
|
34
|
+
console.log(result.created
|
|
35
|
+
? chalk.green(` created ${result.tsconfigRel}`)
|
|
36
|
+
: chalk.green(` updated ${result.tsconfigRel}`))
|
|
37
|
+
console.log(chalk.gray(` include → ${JSON.stringify(result.merged.include)}`))
|
|
38
|
+
console.log(chalk.gray(` outDir → ${result.merged.compilerOptions.outDir}`))
|
|
39
|
+
console.log(chalk.yellow(`\n bunfig.toml [resolve.alias]: ${result.paths.bunfigAliasLine}\n`))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
cli
|
|
43
|
+
.command('sync')
|
|
44
|
+
.alias('sync-toolchain')
|
|
45
|
+
.description('Sync tsconfig paths from tmp.yml')
|
|
46
|
+
.option('--dry-run', 'Preview without writing')
|
|
47
|
+
.action(run)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** @deprecated use registerSyncCommand */
|
|
51
|
+
export const registerSyncToolchainCommand = registerSyncCommand
|
package/x/bin/commands/tmp.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import yaml from 'yaml'
|
|
|
5
5
|
import { printCommandHeader } from '../helpers/banner.mjs'
|
|
6
6
|
import { resolveObjWithHandlebars } from '../helpers/index.mjs'
|
|
7
7
|
import { getProjectRoot, readCliPackageJson } from '../helpers/project-root.mjs'
|
|
8
|
+
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
8
9
|
import {
|
|
9
10
|
ensureTmpFile,
|
|
10
11
|
ownerTmpFilePath,
|
|
@@ -13,7 +14,7 @@ import {
|
|
|
13
14
|
} from '../helpers/tmp-layout.mjs'
|
|
14
15
|
import { formatLoaderSummary, summarizeLoaders } from '../helpers/tmp-config.mjs'
|
|
15
16
|
|
|
16
|
-
export function registerTmpCommand(cli, { cliName =
|
|
17
|
+
export function registerTmpCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
17
18
|
cli
|
|
18
19
|
.command('tmp')
|
|
19
20
|
.description('Ensure tmp.yml exists (seed from @xrystal/core)')
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
// source/utils/constants/index.ts
|
|
2
|
-
import path2 from "node:path";
|
|
3
|
-
|
|
4
|
-
// source/utils/package-root.ts
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
var utilsDir = path.dirname(fileURLToPath(import.meta.url));
|
|
8
|
-
var sourceDir = path.resolve(utilsDir, "..");
|
|
9
|
-
var packageRootDir = path.resolve(utilsDir, "..", "..");
|
|
10
1
|
// source/utils/constants/defaults.json
|
|
11
2
|
var defaults_default = {
|
|
12
3
|
packageName: "@xrystal/core",
|
|
13
4
|
packageRootFolder: "x",
|
|
5
|
+
cliName: "xry",
|
|
6
|
+
cliBinNames: [
|
|
7
|
+
"xry"
|
|
8
|
+
],
|
|
14
9
|
tmpBaseName: "tmp",
|
|
15
10
|
tmpExtension: ".yml",
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
templateRepoUri: "https://github.com/xdloper/api-gpt-svc",
|
|
12
|
+
publicFolderName: "public",
|
|
13
|
+
kafkaLogsTopic: "log",
|
|
14
|
+
pathAliasKey: "@/*",
|
|
15
|
+
eslintRestrictedImportDepth: 2,
|
|
16
|
+
tmpWatchDefaults: {
|
|
17
|
+
intervalMs: 500,
|
|
18
|
+
minIntervalMs: 100,
|
|
19
|
+
maxIntervalMs: 1e4
|
|
21
20
|
},
|
|
22
21
|
buildDefaults: {
|
|
23
22
|
tsconfig: "tsconfig.json",
|
|
@@ -26,61 +25,43 @@ var defaults_default = {
|
|
|
26
25
|
declarations: false,
|
|
27
26
|
sourcemap: false,
|
|
28
27
|
minify: false
|
|
29
|
-
}
|
|
30
|
-
tsconfigDefaults: {
|
|
31
|
-
pathAliasKey: "@/*",
|
|
32
|
-
compilerOptions: {
|
|
33
|
-
noEmit: false,
|
|
34
|
-
noEmitOnError: false,
|
|
35
|
-
declaration: true,
|
|
36
|
-
emitDeclarationOnly: false,
|
|
37
|
-
sourceMap: false,
|
|
38
|
-
declarationMap: false,
|
|
39
|
-
strict: true,
|
|
40
|
-
noImplicitAny: true
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
eslintDefaults: {
|
|
44
|
-
restrictedImportDepth: 2
|
|
45
|
-
},
|
|
46
|
-
tmpWatchDefaults: {
|
|
47
|
-
intervalMs: 500,
|
|
48
|
-
minIntervalMs: 100,
|
|
49
|
-
maxIntervalMs: 1e4
|
|
50
|
-
},
|
|
51
|
-
publicFolderName: "public",
|
|
52
|
-
kafkaLogsTopic: "log",
|
|
53
|
-
templateRepoUri: "https://github.com/xdloper/api-gpt-svc"
|
|
28
|
+
}
|
|
54
29
|
};
|
|
55
30
|
|
|
56
|
-
// source/utils/
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
tsconfigDefaults: Object.freeze({
|
|
62
|
-
...defaults_default.tsconfigDefaults,
|
|
63
|
-
compilerOptions: Object.freeze({ ...defaults_default.tsconfigDefaults.compilerOptions })
|
|
64
|
-
}),
|
|
65
|
-
eslintDefaults: Object.freeze({ ...defaults_default.eslintDefaults }),
|
|
66
|
-
tmpWatchDefaults: Object.freeze({ ...defaults_default.tmpWatchDefaults })
|
|
31
|
+
// source/utils/helpers/tmp/path-normalize.ts
|
|
32
|
+
var DEFAULT_LAYOUT_PATHS = Object.freeze({
|
|
33
|
+
tests: "tests",
|
|
34
|
+
environments: "environments",
|
|
35
|
+
dist: "dist"
|
|
67
36
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
37
|
+
function normalizeRootFolder(value, fallback = "x") {
|
|
38
|
+
if (typeof value !== "string" || !value.trim())
|
|
39
|
+
return fallback;
|
|
40
|
+
return value.trim().replace(/^\.\/+/, "");
|
|
41
|
+
}
|
|
42
|
+
function normalizeSourceFolder(value, fallback = "./source") {
|
|
43
|
+
if (typeof value !== "string" || !value.trim())
|
|
44
|
+
return fallback;
|
|
45
|
+
const trimmed = value.trim();
|
|
46
|
+
if (trimmed.startsWith("./") || trimmed.startsWith("../"))
|
|
47
|
+
return trimmed;
|
|
48
|
+
return `./${trimmed}`;
|
|
49
|
+
}
|
|
50
|
+
function normalizeLayoutPaths(special, fallback = DEFAULT_LAYOUT_PATHS) {
|
|
51
|
+
const block = special && typeof special === "object" && !Array.isArray(special) ? special : {};
|
|
52
|
+
const pick = (key) => {
|
|
53
|
+
const raw = block[key];
|
|
54
|
+
return typeof raw === "string" && raw.trim() ? raw.trim() : fallback[key];
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
tests: pick("tests"),
|
|
58
|
+
environments: pick("environments"),
|
|
59
|
+
dist: pick("dist")
|
|
60
|
+
};
|
|
81
61
|
}
|
|
82
62
|
|
|
83
63
|
// source/utils/helpers/tmp/tmp-schema.ts
|
|
64
|
+
var BOOTSTRAP_SOURCE = "./source";
|
|
84
65
|
function isRecord(value) {
|
|
85
66
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
86
67
|
}
|
|
@@ -89,18 +70,11 @@ function readWatchIntervalValue(raw) {
|
|
|
89
70
|
return raw;
|
|
90
71
|
return;
|
|
91
72
|
}
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
return Constants.packageRootFolder;
|
|
95
|
-
return value.trim().replace(/^\.\/+/, "");
|
|
73
|
+
function normalizeRootFolder2(value) {
|
|
74
|
+
return normalizeRootFolder(value, defaults_default.packageRootFolder);
|
|
96
75
|
}
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
return Constants.mainSourceFolder;
|
|
100
|
-
const trimmed = value.trim();
|
|
101
|
-
if (trimmed.startsWith("./") || trimmed.startsWith("../"))
|
|
102
|
-
return trimmed;
|
|
103
|
-
return `./${trimmed}`;
|
|
76
|
+
function normalizeSourceFolder2(value) {
|
|
77
|
+
return normalizeSourceFolder(value, BOOTSTRAP_SOURCE);
|
|
104
78
|
}
|
|
105
79
|
function readTmpCoreBlock(configs) {
|
|
106
80
|
const core = isRecord(configs?.core) ? configs.core : {};
|
|
@@ -142,12 +116,7 @@ function readTmpServiceBlock(configs) {
|
|
|
142
116
|
};
|
|
143
117
|
}
|
|
144
118
|
function resolveServiceLayoutPaths(service) {
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
tests: special.tests?.trim() || Constants.layoutPaths.tests,
|
|
148
|
-
environments: special.environments?.trim() || Constants.layoutPaths.environments,
|
|
149
|
-
dist: special.dist?.trim() || Constants.layoutPaths.dist
|
|
150
|
-
};
|
|
119
|
+
return normalizeLayoutPaths(service.paths?.special, DEFAULT_LAYOUT_PATHS);
|
|
151
120
|
}
|
|
152
121
|
function buildNormalizedService(service) {
|
|
153
122
|
const layoutPaths = resolveServiceLayoutPaths(service);
|
|
@@ -155,8 +124,8 @@ function buildNormalizedService(service) {
|
|
|
155
124
|
name: service.name,
|
|
156
125
|
framework: service.framework ?? "elysia",
|
|
157
126
|
paths: {
|
|
158
|
-
root: service.paths?.root ??
|
|
159
|
-
source: service.paths?.source ??
|
|
127
|
+
root: service.paths?.root ?? defaults_default.packageRootFolder,
|
|
128
|
+
source: service.paths?.source ?? BOOTSTRAP_SOURCE,
|
|
160
129
|
special: layoutPaths
|
|
161
130
|
},
|
|
162
131
|
protocols: service.protocols,
|
|
@@ -179,7 +148,7 @@ function resolveTmpRuntimeConfigs(tmp) {
|
|
|
179
148
|
return {
|
|
180
149
|
service: normalizedService,
|
|
181
150
|
core: buildNormalizedCore(core),
|
|
182
|
-
rootFolderPath:
|
|
151
|
+
rootFolderPath: normalizeRootFolder2(normalizedService.paths.root)
|
|
183
152
|
};
|
|
184
153
|
}
|
|
185
154
|
function normalizeTmpDocument(tmp) {
|
|
@@ -194,6 +163,6 @@ export {
|
|
|
194
163
|
readTmpServiceBlock,
|
|
195
164
|
readTmpCoreBlock,
|
|
196
165
|
normalizeTmpDocument,
|
|
197
|
-
normalizeSourceFolder,
|
|
198
|
-
normalizeRootFolder
|
|
166
|
+
normalizeSourceFolder2 as normalizeSourceFolder,
|
|
167
|
+
normalizeRootFolder2 as normalizeRootFolder
|
|
199
168
|
};
|
package/x/bin/helpers/banner.mjs
CHANGED
|
@@ -36,7 +36,7 @@ export function brandTitle() {
|
|
|
36
36
|
return `${chalk.bold.white('xrystal ')}${chalk.bold.magenta('core')}`
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
/** Full banner — bare `
|
|
39
|
+
/** Full banner — bare `xry` / `xry -h` (root help). */
|
|
40
40
|
export function printBanner({ version, runtimeName, invokedAs } = {}) {
|
|
41
41
|
const bin = invokedAs && invokedAs !== 'main-cli.js' ? invokedAs : CLI_PRIMARY_NAME
|
|
42
42
|
const versionLabel = version ? chalk.bold.green(`v${version}`) : chalk.gray('v?')
|
|
@@ -53,7 +53,7 @@ export function printBanner({ version, runtimeName, invokedAs } = {}) {
|
|
|
53
53
|
` ${chalk.bold.cyan(bin)} ${chalk.gray('·')} ${chalk.bold('@xrystal/core')} ${versionLabel}${runtimeLabel ? ` ${chalk.gray('·')} ${runtimeLabel}` : ''}`,
|
|
54
54
|
)
|
|
55
55
|
console.log(chalk.bold.gray(' loaders · tmp.yml · dto · i18n · multi-protocol · scaffold'))
|
|
56
|
-
console.log(chalk.dim(`
|
|
56
|
+
console.log(chalk.dim(` cli: ${BIN_ALIASES_LABEL}`))
|
|
57
57
|
console.log('')
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -6,7 +6,16 @@ import { packageDefaults } from '../paths.mjs'
|
|
|
6
6
|
import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
|
|
7
7
|
import { normalizeTmpDocument, readTmpServiceBlock } from './tmp-schema.mjs'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
import { CLI_BIN_NAMES, CLI_PRIMARY_NAME } from './cli-identity.mjs'
|
|
10
|
+
|
|
11
|
+
function escapeRegExp(value) {
|
|
12
|
+
return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const CLI_BUILD_SCRIPT_RE = new RegExp(
|
|
16
|
+
`^(${CLI_BIN_NAMES.map(escapeRegExp).join('|')})\\s+build\\b`,
|
|
17
|
+
)
|
|
18
|
+
|
|
10
19
|
|
|
11
20
|
const BUILD_DEFAULTS = packageDefaults.buildDefaults ?? {}
|
|
12
21
|
|
|
@@ -331,7 +340,7 @@ export function resolveDevEntry(root, layout) {
|
|
|
331
340
|
const tsEntry = path.join(path.resolve(root, layout.mainFolderPath), 'index.ts')
|
|
332
341
|
if (!fs.existsSync(tsEntry)) {
|
|
333
342
|
throw new Error(
|
|
334
|
-
`No index.ts for dev (expected ${path.relative(root, tsEntry)}). Prod: ${layout.rootFolderPath}/${layout.paths.dist}/index.js via
|
|
343
|
+
`No index.ts for dev (expected ${path.relative(root, tsEntry)}). Prod: ${layout.rootFolderPath}/${layout.paths.dist}/index.js via ${CLI_PRIMARY_NAME} start.`,
|
|
335
344
|
)
|
|
336
345
|
}
|
|
337
346
|
return relativeFromRoot(root, tsEntry)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
2
|
|
|
3
|
-
import { CLI_BIN_NAMES } from './cli-identity.mjs'
|
|
3
|
+
import { CLI_BIN_NAMES, CLI_PRIMARY_NAME } from './cli-identity.mjs'
|
|
4
4
|
|
|
5
5
|
export const LIST_BULLET = chalk.cyan('◆')
|
|
6
6
|
import { brandTitle } from './banner.mjs'
|
|
@@ -30,7 +30,7 @@ const COMMAND_GROUPS = [
|
|
|
30
30
|
{ cmd: 'tmp', desc: 'Ensure tmp.yml exists (runtime config seed)' },
|
|
31
31
|
{ cmd: 'hooks install', desc: 'Install .git/hooks pre-commit version check' },
|
|
32
32
|
{ cmd: 'hooks status', desc: 'Show whether pre-commit hook is installed' },
|
|
33
|
-
{ cmd: 'sync
|
|
33
|
+
{ cmd: 'sync', desc: 'Sync tsconfig include/outDir/@/* from tmp.yml' },
|
|
34
34
|
],
|
|
35
35
|
},
|
|
36
36
|
{
|
|
@@ -73,8 +73,8 @@ function formatTreeLines(items) {
|
|
|
73
73
|
return lines.join('\n')
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
/** Bare
|
|
77
|
-
export function printQuickStartGuide({ cliName =
|
|
76
|
+
/** Bare CLI — banner altında kısa, işe yarayan komutlar. */
|
|
77
|
+
export function printQuickStartGuide({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
78
78
|
console.log(chalk.bold.yellow('\n Quick start'))
|
|
79
79
|
console.log(formatTreeLines(QUICK_COMMANDS))
|
|
80
80
|
console.log('')
|
|
@@ -92,7 +92,7 @@ function formatOptionsSection(cliName) {
|
|
|
92
92
|
chalk.bold.white('\n Options'),
|
|
93
93
|
formatTreeLines(items.map(({ cmd, desc }) => ({ cmd, desc }))),
|
|
94
94
|
'',
|
|
95
|
-
chalk.bold.white('
|
|
95
|
+
chalk.bold.white(' CLI'),
|
|
96
96
|
chalk.gray(` ${CLI_BIN_NAMES.join(' · ')}`),
|
|
97
97
|
'',
|
|
98
98
|
chalk.gray(` ${brandTitle()} ${chalk.dim('·')} loaders · tmp.yml · dto · i18n · multi-protocol`),
|
|
@@ -102,8 +102,8 @@ function formatOptionsSection(cliName) {
|
|
|
102
102
|
return lines.join('\n')
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
/**
|
|
106
|
-
export function formatRootHelp({ cliName =
|
|
105
|
+
/** Root `-h` — gruplu, renkli, kompakt tam liste. */
|
|
106
|
+
export function formatRootHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
107
107
|
const sections = COMMAND_GROUPS.map((group) => {
|
|
108
108
|
const paint = SECTION_COLORS[group.title] ?? chalk.bold.white
|
|
109
109
|
return `${paint(`\n ${group.title}`)}\n${formatTreeLines(group.items)}`
|
|
@@ -117,7 +117,7 @@ export function formatRootHelp({ cliName = 'xcore' } = {}) {
|
|
|
117
117
|
].join('\n')
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
export function formatCreateHelp({ cliName =
|
|
120
|
+
export function formatCreateHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
121
121
|
const examples = [
|
|
122
122
|
{ cmd: `${cliName} create my-api`, desc: '→ ./my-api (current folder)' },
|
|
123
123
|
{ cmd: `${cliName} create my-api ..`, desc: '→ ../my-api' },
|
|
@@ -140,7 +140,7 @@ export function formatCreateHelp({ cliName = 'xcore' } = {}) {
|
|
|
140
140
|
].join('\n')
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
export function formatCreateCommandHelp({ cliName =
|
|
143
|
+
export function formatCreateCommandHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
144
144
|
return [
|
|
145
145
|
formatCreateHelp({ cliName }),
|
|
146
146
|
chalk.bold.white(' Options'),
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import path
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
}
|
|
1
|
+
/** @deprecated import from package-defaults.mjs — kept as stable path for existing imports */
|
|
2
|
+
export {
|
|
3
|
+
CLI_PRIMARY_NAME,
|
|
4
|
+
CLI_BIN_NAMES,
|
|
5
|
+
resolveInvokedAs,
|
|
6
|
+
isKnownCliBin,
|
|
7
|
+
} from './package-defaults.mjs'
|
|
@@ -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,21 +1,55 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { fileURLToPath } from 'node:url'
|
|
1
|
+
import fs from 'node:fs'
|
|
3
2
|
import path from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
|
|
5
|
+
import { loadSeedLayoutFromBundledTmp } from './seed-from-tmp.mjs'
|
|
4
6
|
|
|
5
7
|
const here = path.dirname(fileURLToPath(import.meta.url))
|
|
6
|
-
const
|
|
8
|
+
const packageRoot = path.resolve(here, '..', '..', '..')
|
|
9
|
+
|
|
10
|
+
const AUTHORED_DEFAULTS = path.join(packageRoot, 'source', 'utils', 'constants', 'defaults.json')
|
|
11
|
+
const PUBLISHED_DEFAULTS = path.join(here, 'defaults.json')
|
|
12
|
+
|
|
13
|
+
function loadRawDefaults() {
|
|
14
|
+
for (const file of [AUTHORED_DEFAULTS, PUBLISHED_DEFAULTS]) {
|
|
15
|
+
if (fs.existsSync(file)) return JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
16
|
+
}
|
|
17
|
+
throw new Error(
|
|
18
|
+
`@xrystal/core defaults.json not found. Expected ${AUTHORED_DEFAULTS} or ${PUBLISHED_DEFAULTS}`,
|
|
19
|
+
)
|
|
20
|
+
}
|
|
7
21
|
|
|
22
|
+
const raw = loadRawDefaults()
|
|
23
|
+
const seed = loadSeedLayoutFromBundledTmp(packageRoot, raw)
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* defaults.json → package identity + CLI + build flags
|
|
27
|
+
* helpers/seed-from-tmp → layout from bundled x/tmp.yml
|
|
28
|
+
*/
|
|
8
29
|
export const packageDefaults = Object.freeze({
|
|
9
|
-
...
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
tmpWatchDefaults: Object.freeze({ ...defaults.tmpWatchDefaults }),
|
|
30
|
+
...raw,
|
|
31
|
+
mainSourceFolder: seed.mainSourceFolder,
|
|
32
|
+
layoutPaths: seed.layoutPaths,
|
|
33
|
+
buildDefaults: Object.freeze({ ...(raw.buildDefaults ?? {}) }),
|
|
34
|
+
tmpWatchDefaults: Object.freeze({ ...(raw.tmpWatchDefaults ?? {}) }),
|
|
35
|
+
cliBinNames: Object.freeze([...(raw.cliBinNames ?? [raw.cliName])]),
|
|
36
|
+
pathAliasKey: raw.pathAliasKey || '@/*',
|
|
37
|
+
eslintRestrictedImportDepth: raw.eslintRestrictedImportDepth ?? 2,
|
|
18
38
|
})
|
|
19
39
|
|
|
20
40
|
export const coreVersionPattern = /^\d{2}\.\d{2}\.\d{2}-v\d+$/
|
|
21
41
|
export const semverVersionPattern = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/
|
|
42
|
+
|
|
43
|
+
export const CLI_PRIMARY_NAME = packageDefaults.cliName
|
|
44
|
+
export const CLI_BIN_NAMES = packageDefaults.cliBinNames
|
|
45
|
+
|
|
46
|
+
export function resolveInvokedAs(argv = process.argv) {
|
|
47
|
+
const base = path.basename(argv[1] || CLI_PRIMARY_NAME)
|
|
48
|
+
if (base === 'main-cli.js') return CLI_PRIMARY_NAME
|
|
49
|
+
if (CLI_BIN_NAMES.includes(base)) return base
|
|
50
|
+
return CLI_PRIMARY_NAME
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function isKnownCliBin(name) {
|
|
54
|
+
return CLI_BIN_NAMES.includes(name)
|
|
55
|
+
}
|
|
@@ -6,6 +6,7 @@ import { fileURLToPath } from 'node:url'
|
|
|
6
6
|
import { isCorePackageName } from './build-config.mjs'
|
|
7
7
|
import { syncProjectToolchain } from './toolchain-config.mjs'
|
|
8
8
|
import { ensureTmpFile, relativeFromRoot } from './tmp-layout.mjs'
|
|
9
|
+
import { packageDefaults } from './package-defaults.mjs'
|
|
9
10
|
|
|
10
11
|
const CLI_BIN_DIR = path.dirname(fileURLToPath(import.meta.url))
|
|
11
12
|
const CLI_GENERATED_SCHEMA = path.join(CLI_BIN_DIR, '.generated/tmp-schema.mjs')
|
|
@@ -70,10 +71,12 @@ function stablePackageShape(pkg) {
|
|
|
70
71
|
types: pkg.types,
|
|
71
72
|
exports: pkg.exports,
|
|
72
73
|
files: pkg.files,
|
|
74
|
+
bin: pkg.bin,
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
|
|
79
|
+
/** Publish artifact copy of authored source/utils/constants/defaults.json */
|
|
77
80
|
export function syncCliDefaults(root = process.cwd()) {
|
|
78
81
|
const src = path.join(root, 'source/utils/constants/defaults.json')
|
|
79
82
|
const dest = path.join(root, 'x/bin/helpers/defaults.json')
|
|
@@ -117,12 +120,16 @@ export function syncPackageManifest(root = process.cwd(), { write = true } = {})
|
|
|
117
120
|
}
|
|
118
121
|
|
|
119
122
|
const { distPrefix, distRel } = resolveDistLayout(root)
|
|
123
|
+
const binEntry = './x/bin/main-cli.js'
|
|
124
|
+
const bin = Object.fromEntries(packageDefaults.cliBinNames.map((name) => [name, binEntry]))
|
|
125
|
+
|
|
120
126
|
const next = {
|
|
121
127
|
...pkg,
|
|
122
128
|
main: `${distPrefix}/project/index.js`,
|
|
123
129
|
types: `${distPrefix}/project/index.d.ts`,
|
|
124
130
|
exports: buildCorePackageExports(distPrefix),
|
|
125
131
|
files: normalizeFilesList(pkg.files, distRel),
|
|
132
|
+
bin,
|
|
126
133
|
}
|
|
127
134
|
|
|
128
135
|
const changed = JSON.stringify(stablePackageShape(pkg)) !== JSON.stringify(stablePackageShape(next))
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import yaml from 'yaml'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* CLI twin of source/utils/helpers/tmp/seed-from-tmp.ts
|
|
7
|
+
* Layout seed = bundled x/tmp.yml (not defaults.json).
|
|
8
|
+
*/
|
|
9
|
+
export function loadSeedLayoutFromBundledTmp(packageRoot, raw = {}) {
|
|
10
|
+
const rootFolder = raw.packageRootFolder || 'x'
|
|
11
|
+
const tmpFile = path.join(
|
|
12
|
+
packageRoot,
|
|
13
|
+
rootFolder,
|
|
14
|
+
`${raw.tmpBaseName || 'tmp'}${raw.tmpExtension || '.yml'}`,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
const fallback = {
|
|
18
|
+
rootFolder,
|
|
19
|
+
mainSourceFolder: './source',
|
|
20
|
+
layoutPaths: Object.freeze({
|
|
21
|
+
tests: 'tests',
|
|
22
|
+
environments: 'environments',
|
|
23
|
+
dist: 'dist',
|
|
24
|
+
}),
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!fs.existsSync(tmpFile)) return fallback
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const doc = yaml.parse(fs.readFileSync(tmpFile, 'utf8'))
|
|
31
|
+
const paths = doc?.configs?.service?.paths ?? {}
|
|
32
|
+
const special = paths.special ?? {}
|
|
33
|
+
const sourceRaw = typeof paths.source === 'string' && paths.source.trim()
|
|
34
|
+
? paths.source.trim()
|
|
35
|
+
: './source'
|
|
36
|
+
const mainSourceFolder = sourceRaw.startsWith('.') ? sourceRaw : `./${sourceRaw}`
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
rootFolder: typeof paths.root === 'string' && paths.root.trim()
|
|
40
|
+
? paths.root.trim().replace(/^\.\/+/, '')
|
|
41
|
+
: rootFolder,
|
|
42
|
+
mainSourceFolder,
|
|
43
|
+
layoutPaths: Object.freeze({
|
|
44
|
+
tests: special.tests || 'tests',
|
|
45
|
+
environments: special.environments || 'environments',
|
|
46
|
+
dist: special.dist || 'dist',
|
|
47
|
+
}),
|
|
48
|
+
}
|
|
49
|
+
} catch {
|
|
50
|
+
return fallback
|
|
51
|
+
}
|
|
52
|
+
}
|