@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
|
@@ -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,59 +25,96 @@ 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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
31
|
+
// source/utils/helpers/tmp/seed-from-tmp.ts
|
|
32
|
+
import fs from "node:fs";
|
|
33
|
+
import path from "node:path";
|
|
34
|
+
import { fileURLToPath } from "node:url";
|
|
35
|
+
import yaml from "yaml";
|
|
36
|
+
|
|
37
|
+
// source/utils/helpers/tmp/path-normalize.ts
|
|
38
|
+
function normalizeRootFolder(value, fallback) {
|
|
39
|
+
if (typeof value !== "string" || !value.trim())
|
|
40
|
+
return fallback;
|
|
41
|
+
return value.trim().replace(/^\.\/+/, "");
|
|
42
|
+
}
|
|
43
|
+
function normalizeSourceFolder(value, fallback) {
|
|
44
|
+
if (typeof value !== "string" || !value.trim())
|
|
45
|
+
return fallback;
|
|
46
|
+
const trimmed = value.trim();
|
|
47
|
+
if (trimmed.startsWith("./") || trimmed.startsWith("../"))
|
|
48
|
+
return trimmed;
|
|
49
|
+
return `./${trimmed}`;
|
|
50
|
+
}
|
|
51
|
+
function normalizeLayoutPaths(special, fallback) {
|
|
52
|
+
const block = special && typeof special === "object" && !Array.isArray(special) ? special : {};
|
|
53
|
+
const pick = (key) => {
|
|
54
|
+
const raw = block[key];
|
|
55
|
+
return typeof raw === "string" && raw.trim() ? raw.trim() : fallback[key];
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
tests: pick("tests"),
|
|
59
|
+
environments: pick("environments"),
|
|
60
|
+
dist: pick("dist")
|
|
61
|
+
};
|
|
62
|
+
}
|
|
69
63
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
static kafkaLogsTopic = packageDefaults.kafkaLogsTopic;
|
|
79
|
-
static templateRepoUri = packageDefaults.templateRepoUri;
|
|
80
|
-
static bundledCoreTmpPath = path2.join(packageRootDir, packageDefaults.packageRootFolder, tmpFileName);
|
|
64
|
+
// source/utils/helpers/tmp/seed-from-tmp.ts
|
|
65
|
+
var here = path.dirname(fileURLToPath(import.meta.url));
|
|
66
|
+
var tmpFileName = `${defaults_default.tmpBaseName}${defaults_default.tmpExtension}`;
|
|
67
|
+
function requireString(value, label) {
|
|
68
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
69
|
+
throw new Error(`${defaults_default.packageName}: bundled tmp.yml missing ${label}`);
|
|
70
|
+
}
|
|
71
|
+
return value.trim();
|
|
81
72
|
}
|
|
73
|
+
function readLayoutFromSpecial(special) {
|
|
74
|
+
const block = special && typeof special === "object" && !Array.isArray(special) ? special : {};
|
|
75
|
+
return {
|
|
76
|
+
tests: requireString(block.tests, "configs.service.paths.special.tests"),
|
|
77
|
+
environments: requireString(block.environments, "configs.service.paths.special.environments"),
|
|
78
|
+
dist: requireString(block.dist, "configs.service.paths.special.dist")
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function findBundledTmpFile(explicit) {
|
|
82
|
+
if (explicit) {
|
|
83
|
+
if (!fs.existsSync(explicit)) {
|
|
84
|
+
throw new Error(`${defaults_default.packageName}: bundled tmp.yml missing at ${explicit}`);
|
|
85
|
+
}
|
|
86
|
+
return explicit;
|
|
87
|
+
}
|
|
88
|
+
const starts = [here, process.cwd()];
|
|
89
|
+
for (const start of starts) {
|
|
90
|
+
let dir = path.resolve(start);
|
|
91
|
+
for (;; ) {
|
|
92
|
+
const candidate = path.join(dir, defaults_default.packageRootFolder, tmpFileName);
|
|
93
|
+
if (fs.existsSync(candidate))
|
|
94
|
+
return candidate;
|
|
95
|
+
const parent = path.dirname(dir);
|
|
96
|
+
if (parent === dir)
|
|
97
|
+
break;
|
|
98
|
+
dir = parent;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
throw new Error(`${defaults_default.packageName}: bundled ${defaults_default.packageRootFolder}/${tmpFileName} not found from ${here}`);
|
|
102
|
+
}
|
|
103
|
+
function loadSeedFromBundledTmp(tmpFilePath) {
|
|
104
|
+
const file = findBundledTmpFile(tmpFilePath);
|
|
105
|
+
const doc = yaml.parse(fs.readFileSync(file, "utf8"));
|
|
106
|
+
const configs = doc?.configs && typeof doc.configs === "object" ? doc.configs : {};
|
|
107
|
+
const service = configs.service && typeof configs.service === "object" ? configs.service : {};
|
|
108
|
+
const paths = service.paths && typeof service.paths === "object" ? service.paths : {};
|
|
109
|
+
const sourceRaw = requireString(paths.source, "configs.service.paths.source");
|
|
110
|
+
return {
|
|
111
|
+
rootFolder: normalizeRootFolder(paths.root, defaults_default.packageRootFolder),
|
|
112
|
+
sourceFolder: normalizeSourceFolder(sourceRaw, sourceRaw),
|
|
113
|
+
framework: requireString(service.framework, "configs.service.framework"),
|
|
114
|
+
layout: readLayoutFromSpecial(paths.special)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
var seedFromTmp = loadSeedFromBundledTmp();
|
|
82
118
|
|
|
83
119
|
// source/utils/helpers/tmp/tmp-schema.ts
|
|
84
120
|
function isRecord(value) {
|
|
@@ -89,18 +125,11 @@ function readWatchIntervalValue(raw) {
|
|
|
89
125
|
return raw;
|
|
90
126
|
return;
|
|
91
127
|
}
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
return Constants.packageRootFolder;
|
|
95
|
-
return value.trim().replace(/^\.\/+/, "");
|
|
128
|
+
function normalizeRootFolder2(value) {
|
|
129
|
+
return normalizeRootFolder(value, defaults_default.packageRootFolder);
|
|
96
130
|
}
|
|
97
|
-
function
|
|
98
|
-
|
|
99
|
-
return Constants.mainSourceFolder;
|
|
100
|
-
const trimmed = value.trim();
|
|
101
|
-
if (trimmed.startsWith("./") || trimmed.startsWith("../"))
|
|
102
|
-
return trimmed;
|
|
103
|
-
return `./${trimmed}`;
|
|
131
|
+
function normalizeSourceFolder2(value) {
|
|
132
|
+
return normalizeSourceFolder(value, seedFromTmp.sourceFolder);
|
|
104
133
|
}
|
|
105
134
|
function readTmpCoreBlock(configs) {
|
|
106
135
|
const core = isRecord(configs?.core) ? configs.core : {};
|
|
@@ -142,21 +171,16 @@ function readTmpServiceBlock(configs) {
|
|
|
142
171
|
};
|
|
143
172
|
}
|
|
144
173
|
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
|
-
};
|
|
174
|
+
return normalizeLayoutPaths(service.paths?.special, seedFromTmp.layout);
|
|
151
175
|
}
|
|
152
176
|
function buildNormalizedService(service) {
|
|
153
177
|
const layoutPaths = resolveServiceLayoutPaths(service);
|
|
154
178
|
return {
|
|
155
179
|
name: service.name,
|
|
156
|
-
framework: service.framework ??
|
|
180
|
+
framework: service.framework ?? seedFromTmp.framework,
|
|
157
181
|
paths: {
|
|
158
|
-
root: service.paths?.root ??
|
|
159
|
-
source: service.paths?.source ??
|
|
182
|
+
root: service.paths?.root ?? defaults_default.packageRootFolder,
|
|
183
|
+
source: service.paths?.source ?? seedFromTmp.sourceFolder,
|
|
160
184
|
special: layoutPaths
|
|
161
185
|
},
|
|
162
186
|
protocols: service.protocols,
|
|
@@ -179,7 +203,7 @@ function resolveTmpRuntimeConfigs(tmp) {
|
|
|
179
203
|
return {
|
|
180
204
|
service: normalizedService,
|
|
181
205
|
core: buildNormalizedCore(core),
|
|
182
|
-
rootFolderPath:
|
|
206
|
+
rootFolderPath: normalizeRootFolder2(normalizedService.paths.root)
|
|
183
207
|
};
|
|
184
208
|
}
|
|
185
209
|
function normalizeTmpDocument(tmp) {
|
|
@@ -194,6 +218,6 @@ export {
|
|
|
194
218
|
readTmpServiceBlock,
|
|
195
219
|
readTmpCoreBlock,
|
|
196
220
|
normalizeTmpDocument,
|
|
197
|
-
normalizeSourceFolder,
|
|
198
|
-
normalizeRootFolder
|
|
221
|
+
normalizeSourceFolder2 as normalizeSourceFolder,
|
|
222
|
+
normalizeRootFolder2 as normalizeRootFolder
|
|
199
223
|
};
|
package/x/bin/helpers/banner.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
2
|
|
|
3
3
|
import { CLI_BIN_NAMES, CLI_PRIMARY_NAME } from './cli-identity.mjs'
|
|
4
|
+
import { packageDefaults } from './package-defaults.mjs'
|
|
4
5
|
|
|
5
6
|
/** figlet standard — lowercase wordmark, split for two-tone print */
|
|
6
7
|
const XRYSTAL_LINES = [
|
|
@@ -36,7 +37,7 @@ export function brandTitle() {
|
|
|
36
37
|
return `${chalk.bold.white('xrystal ')}${chalk.bold.magenta('core')}`
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
/** Full banner — bare `
|
|
40
|
+
/** Full banner — bare `xry` / `xry -h` (root help). */
|
|
40
41
|
export function printBanner({ version, runtimeName, invokedAs } = {}) {
|
|
41
42
|
const bin = invokedAs && invokedAs !== 'main-cli.js' ? invokedAs : CLI_PRIMARY_NAME
|
|
42
43
|
const versionLabel = version ? chalk.bold.green(`v${version}`) : chalk.gray('v?')
|
|
@@ -50,10 +51,10 @@ export function printBanner({ version, runtimeName, invokedAs } = {}) {
|
|
|
50
51
|
|
|
51
52
|
console.log('')
|
|
52
53
|
console.log(
|
|
53
|
-
` ${chalk.bold.cyan(bin)} ${chalk.gray('·')} ${chalk.bold(
|
|
54
|
+
` ${chalk.bold.cyan(bin)} ${chalk.gray('·')} ${chalk.bold(packageDefaults.packageName)} ${versionLabel}${runtimeLabel ? ` ${chalk.gray('·')} ${runtimeLabel}` : ''}`,
|
|
54
55
|
)
|
|
55
56
|
console.log(chalk.bold.gray(' loaders · tmp.yml · dto · i18n · multi-protocol · scaffold'))
|
|
56
|
-
console.log(chalk.dim(`
|
|
57
|
+
console.log(chalk.dim(` cli: ${BIN_ALIASES_LABEL}`))
|
|
57
58
|
console.log('')
|
|
58
59
|
}
|
|
59
60
|
|
|
@@ -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,9 +1,10 @@
|
|
|
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'
|
|
7
|
+
import { packageDefaults } from './package-defaults.mjs'
|
|
7
8
|
|
|
8
9
|
const QUICK_COMMANDS = [
|
|
9
10
|
{ cmd: 'create', hint: '<name> [path]', desc: 'Scaffold service · path defaults to cwd' },
|
|
@@ -30,13 +31,13 @@ const COMMAND_GROUPS = [
|
|
|
30
31
|
{ cmd: 'tmp', desc: 'Ensure tmp.yml exists (runtime config seed)' },
|
|
31
32
|
{ cmd: 'hooks install', desc: 'Install .git/hooks pre-commit version check' },
|
|
32
33
|
{ cmd: 'hooks status', desc: 'Show whether pre-commit hook is installed' },
|
|
33
|
-
{ cmd: 'sync
|
|
34
|
+
{ cmd: 'sync', desc: 'Sync tsconfig include/outDir/@/* from tmp.yml' },
|
|
34
35
|
],
|
|
35
36
|
},
|
|
36
37
|
{
|
|
37
38
|
title: 'Diagnostics',
|
|
38
39
|
items: [
|
|
39
|
-
{ cmd: 'doctor', desc:
|
|
40
|
+
{ cmd: 'doctor', desc: `Runtime · git · ${packageDefaults.packageName} version alignment` },
|
|
40
41
|
{ cmd: 'version', desc: 'CLI tool vs project package.json versions' },
|
|
41
42
|
],
|
|
42
43
|
},
|
|
@@ -73,8 +74,8 @@ function formatTreeLines(items) {
|
|
|
73
74
|
return lines.join('\n')
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
/** Bare
|
|
77
|
-
export function printQuickStartGuide({ cliName =
|
|
77
|
+
/** Bare CLI — banner altında kısa, işe yarayan komutlar. */
|
|
78
|
+
export function printQuickStartGuide({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
78
79
|
console.log(chalk.bold.yellow('\n Quick start'))
|
|
79
80
|
console.log(formatTreeLines(QUICK_COMMANDS))
|
|
80
81
|
console.log('')
|
|
@@ -85,14 +86,14 @@ export function printQuickStartGuide({ cliName = 'xcore' } = {}) {
|
|
|
85
86
|
|
|
86
87
|
function formatOptionsSection(cliName) {
|
|
87
88
|
const items = [
|
|
88
|
-
{ cmd: '-V, --version', desc:
|
|
89
|
+
{ cmd: '-V, --version', desc: `Show ${packageDefaults.packageName} CLI version` },
|
|
89
90
|
{ cmd: '-h, --help', desc: 'Show full command list' },
|
|
90
91
|
]
|
|
91
92
|
const lines = [
|
|
92
93
|
chalk.bold.white('\n Options'),
|
|
93
94
|
formatTreeLines(items.map(({ cmd, desc }) => ({ cmd, desc }))),
|
|
94
95
|
'',
|
|
95
|
-
chalk.bold.white('
|
|
96
|
+
chalk.bold.white(' CLI'),
|
|
96
97
|
chalk.gray(` ${CLI_BIN_NAMES.join(' · ')}`),
|
|
97
98
|
'',
|
|
98
99
|
chalk.gray(` ${brandTitle()} ${chalk.dim('·')} loaders · tmp.yml · dto · i18n · multi-protocol`),
|
|
@@ -102,8 +103,8 @@ function formatOptionsSection(cliName) {
|
|
|
102
103
|
return lines.join('\n')
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
/**
|
|
106
|
-
export function formatRootHelp({ cliName =
|
|
106
|
+
/** Root `-h` — gruplu, renkli, kompakt tam liste. */
|
|
107
|
+
export function formatRootHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
107
108
|
const sections = COMMAND_GROUPS.map((group) => {
|
|
108
109
|
const paint = SECTION_COLORS[group.title] ?? chalk.bold.white
|
|
109
110
|
return `${paint(`\n ${group.title}`)}\n${formatTreeLines(group.items)}`
|
|
@@ -117,7 +118,7 @@ export function formatRootHelp({ cliName = 'xcore' } = {}) {
|
|
|
117
118
|
].join('\n')
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
export function formatCreateHelp({ cliName =
|
|
121
|
+
export function formatCreateHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
121
122
|
const examples = [
|
|
122
123
|
{ cmd: `${cliName} create my-api`, desc: '→ ./my-api (current folder)' },
|
|
123
124
|
{ cmd: `${cliName} create my-api ..`, desc: '→ ../my-api' },
|
|
@@ -140,7 +141,7 @@ export function formatCreateHelp({ cliName = 'xcore' } = {}) {
|
|
|
140
141
|
].join('\n')
|
|
141
142
|
}
|
|
142
143
|
|
|
143
|
-
export function formatCreateCommandHelp({ cliName =
|
|
144
|
+
export function formatCreateCommandHelp({ cliName = CLI_PRIMARY_NAME } = {}) {
|
|
144
145
|
return [
|
|
145
146
|
formatCreateHelp({ cliName }),
|
|
146
147
|
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,52 @@
|
|
|
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
|
+
`package defaults.json not found. Expected ${AUTHORED_DEFAULTS} or ${PUBLISHED_DEFAULTS}`,
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const raw = loadRawDefaults()
|
|
23
|
+
const seed = loadSeedLayoutFromBundledTmp(packageRoot, raw)
|
|
7
24
|
|
|
8
25
|
export const packageDefaults = Object.freeze({
|
|
9
|
-
...
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
...raw,
|
|
27
|
+
mainSourceFolder: seed.mainSourceFolder,
|
|
28
|
+
framework: seed.framework,
|
|
29
|
+
layoutPaths: seed.layoutPaths,
|
|
30
|
+
buildDefaults: Object.freeze({ ...(raw.buildDefaults ?? {}) }),
|
|
31
|
+
tmpWatchDefaults: Object.freeze({ ...(raw.tmpWatchDefaults ?? {}) }),
|
|
32
|
+
cliBinNames: Object.freeze([...(raw.cliBinNames ?? [raw.cliName])]),
|
|
33
|
+
pathAliasKey: raw.pathAliasKey,
|
|
34
|
+
eslintRestrictedImportDepth: raw.eslintRestrictedImportDepth,
|
|
18
35
|
})
|
|
19
36
|
|
|
20
37
|
export const coreVersionPattern = /^\d{2}\.\d{2}\.\d{2}-v\d+$/
|
|
21
38
|
export const semverVersionPattern = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/
|
|
39
|
+
|
|
40
|
+
export const CLI_PRIMARY_NAME = packageDefaults.cliName
|
|
41
|
+
export const CLI_BIN_NAMES = packageDefaults.cliBinNames
|
|
42
|
+
|
|
43
|
+
export function resolveInvokedAs(argv = process.argv) {
|
|
44
|
+
const base = path.basename(argv[1] || CLI_PRIMARY_NAME)
|
|
45
|
+
if (base === 'main-cli.js') return CLI_PRIMARY_NAME
|
|
46
|
+
if (CLI_BIN_NAMES.includes(base)) return base
|
|
47
|
+
return CLI_PRIMARY_NAME
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function isKnownCliBin(name) {
|
|
51
|
+
return CLI_BIN_NAMES.includes(name)
|
|
52
|
+
}
|
|
@@ -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')
|
|
@@ -100,7 +103,7 @@ export function syncCliTmpSchema(root = process.cwd(), { force = false } = {}) {
|
|
|
100
103
|
|
|
101
104
|
fs.mkdirSync(outDir, { recursive: true })
|
|
102
105
|
execSync(
|
|
103
|
-
`bun build "${srcAbs}" --outfile "${CLI_GENERATED_SCHEMA}" --target node --format esm`,
|
|
106
|
+
`bun build "${srcAbs}" --outfile "${CLI_GENERATED_SCHEMA}" --target node --format esm --external yaml`,
|
|
104
107
|
{ cwd: root, stdio: 'pipe' },
|
|
105
108
|
)
|
|
106
109
|
fs.writeFileSync(path.join(outDir, '.generated-from'), `${CLI_SCHEMA_SOURCE}\n`)
|
|
@@ -113,16 +116,20 @@ export function syncPackageManifest(root = process.cwd(), { write = true } = {})
|
|
|
113
116
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
114
117
|
|
|
115
118
|
if (!isCorePackageName(pkg.name)) {
|
|
116
|
-
return { synced: false, reason:
|
|
119
|
+
return { synced: false, reason: `not ${packageDefaults.packageName}` }
|
|
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))
|
|
@@ -14,10 +14,10 @@ export function resolveProjectRoot(startDir = process.cwd()) {
|
|
|
14
14
|
const pkgPath = path.join(dir, 'package.json')
|
|
15
15
|
if (fs.existsSync(pkgPath)) {
|
|
16
16
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
17
|
-
if (pkg.name ===
|
|
17
|
+
if (pkg.name === packageDefaults.packageName) return dir
|
|
18
18
|
|
|
19
19
|
const deps = { ...pkg.dependencies, ...pkg.devDependencies }
|
|
20
|
-
if (deps[
|
|
20
|
+
if (deps[packageDefaults.packageName]) return dir
|
|
21
21
|
}
|
|
22
22
|
dir = path.dirname(dir)
|
|
23
23
|
}
|
|
@@ -48,8 +48,8 @@ export function readProjectPackageJson(root = resolveProjectRoot()) {
|
|
|
48
48
|
export function getInstalledCoreVersion(root = resolveProjectRoot()) {
|
|
49
49
|
const project = readProjectPackageJson(root)
|
|
50
50
|
const declared =
|
|
51
|
-
project.dependencies?.[
|
|
52
|
-
?? project.devDependencies?.[
|
|
51
|
+
project.dependencies?.[packageDefaults.packageName]
|
|
52
|
+
?? project.devDependencies?.[packageDefaults.packageName]
|
|
53
53
|
?? null
|
|
54
54
|
|
|
55
55
|
const installedPath = path.join(root, 'node_modules', '@xrystal', 'core', 'package.json')
|