@xrystal/core 3.39.0 → 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 +65 -34
- 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/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
|
@@ -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
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CLI_PRIMARY_NAME } from './cli-identity.mjs'
|
|
1
2
|
import fs from 'node:fs'
|
|
2
3
|
import path from 'node:path'
|
|
3
4
|
|
|
@@ -32,7 +33,7 @@ export function resolveToolchainPaths(options = {}) {
|
|
|
32
33
|
outDir: `./${rootFolder}/${distSegment}`,
|
|
33
34
|
include: [mainFolder],
|
|
34
35
|
exclude: [`${rootFolder}/${testsSegment}`],
|
|
35
|
-
pathAliasKey: packageDefaults.
|
|
36
|
+
pathAliasKey: packageDefaults.pathAliasKey ?? '@/*',
|
|
36
37
|
pathAliasTarget: [`${mainFolder}/*`],
|
|
37
38
|
eslintFiles: [`${mainFolder}/**/*.ts`, `${mainFolder}/**/*.tsx`],
|
|
38
39
|
eslintIgnores: [
|
|
@@ -51,23 +52,16 @@ export function resolveToolchainPathsFromProject(root = process.cwd()) {
|
|
|
51
52
|
|
|
52
53
|
export function resolveRecommendedTsconfig(options = {}) {
|
|
53
54
|
const paths = resolveToolchainPaths(options)
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
// compilerOptions language lives in tsconfig.base.json (extends);
|
|
56
|
+
// sync only overlays layout fields from tmp.yml
|
|
56
57
|
return {
|
|
57
58
|
include: [...paths.include],
|
|
58
59
|
exclude: [...paths.exclude],
|
|
59
60
|
compilerOptions: {
|
|
60
|
-
target: 'ESNext',
|
|
61
|
-
module: 'ESNext',
|
|
62
|
-
moduleResolution: 'Bundler',
|
|
63
61
|
baseUrl: '.',
|
|
64
62
|
paths: { [paths.pathAliasKey]: paths.pathAliasTarget },
|
|
65
63
|
rootDir: paths.mainSourceFolder,
|
|
66
64
|
outDir: paths.outDir,
|
|
67
|
-
esModuleInterop: true,
|
|
68
|
-
forceConsistentCasingInFileNames: true,
|
|
69
|
-
skipLibCheck: true,
|
|
70
|
-
...baseOptions,
|
|
71
65
|
},
|
|
72
66
|
}
|
|
73
67
|
}
|
|
@@ -148,7 +142,7 @@ export function auditTsconfigAlignment(root, options = null) {
|
|
|
148
142
|
const recommended = resolveRecommendedTsconfig(resolvedOptions)
|
|
149
143
|
const onDisk = readProjectTsconfig(root)
|
|
150
144
|
if (!onDisk) {
|
|
151
|
-
return { ok: false, missing: true, notes: [
|
|
145
|
+
return { ok: false, missing: true, notes: [`tsconfig.json not found — run ${CLI_PRIMARY_NAME} sync`] }
|
|
152
146
|
}
|
|
153
147
|
|
|
154
148
|
const notes = []
|
|
@@ -175,7 +169,7 @@ export function auditTsconfigAlignment(root, options = null) {
|
|
|
175
169
|
|
|
176
170
|
export function createEslintConfigFromProject(root = process.cwd(), tseslint) {
|
|
177
171
|
const paths = resolveToolchainPathsFromProject(root)
|
|
178
|
-
const depth = packageDefaults.
|
|
172
|
+
const depth = packageDefaults.eslintRestrictedImportDepth ?? 2
|
|
179
173
|
const deepRelative = '../'.repeat(depth + 1)
|
|
180
174
|
|
|
181
175
|
return tseslint.config(
|
package/x/bin/main-cli.js
CHANGED
|
@@ -7,7 +7,7 @@ import { registerCreateCommand } from './commands/create.mjs'
|
|
|
7
7
|
import { registerDoctorCommand } from './commands/doctor.mjs'
|
|
8
8
|
import { registerProjectCommands } from './commands/project.mjs'
|
|
9
9
|
import { registerTmpCommand } from './commands/tmp.mjs'
|
|
10
|
-
import {
|
|
10
|
+
import { registerSyncCommand } from './commands/sync.mjs'
|
|
11
11
|
import { registerTagCommand, registerVersionCommand } from './commands/release.mjs'
|
|
12
12
|
import { registerHooksCommand } from './commands/hooks.mjs'
|
|
13
13
|
import { printBanner, shouldShowBanner } from './helpers/banner.mjs'
|
|
@@ -65,7 +65,7 @@ registerVersionCommand(cli, cliContext)
|
|
|
65
65
|
registerTagCommand(cli, cliContext)
|
|
66
66
|
registerDoctorCommand(cli, cliContext)
|
|
67
67
|
registerTmpCommand(cli, cliContext)
|
|
68
|
-
|
|
68
|
+
registerSyncCommand(cli, cliContext)
|
|
69
69
|
registerHooksCommand(cli, cliContext)
|
|
70
70
|
registerProjectCommands(cli, cliContext)
|
|
71
71
|
|
|
@@ -4,6 +4,7 @@ import path from 'node:path'
|
|
|
4
4
|
import { fileURLToPath } from 'node:url'
|
|
5
5
|
|
|
6
6
|
import { resolveProjectRoot } from '../helpers/project-root.mjs'
|
|
7
|
+
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
7
8
|
|
|
8
9
|
const verifyScriptPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'verify-version-bump.mjs')
|
|
9
10
|
const HOOK_MARKER = '@xrystal/core version-bump pre-commit'
|
|
@@ -50,7 +51,7 @@ set -e
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
|
|
53
|
-
export function ensureHooksInstallScript(projectRoot, cliName =
|
|
54
|
+
export function ensureHooksInstallScript(projectRoot, cliName = CLI_PRIMARY_NAME) {
|
|
54
55
|
const packageJsonPath = path.join(projectRoot, 'package.json')
|
|
55
56
|
if (!fs.existsSync(packageJsonPath)) return false
|
|
56
57
|
|
|
@@ -66,7 +67,7 @@ export function ensureHooksInstallScript(projectRoot, cliName = 'xcore') {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
/** Install pre-commit hook + package.json hooks:install script (create + manual). */
|
|
69
|
-
export function setupProjectGitHooks(projectRoot, { cliName =
|
|
70
|
+
export function setupProjectGitHooks(projectRoot, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
70
71
|
ensureHooksInstallScript(projectRoot, cliName)
|
|
71
72
|
const refreshed = isGitHookInstalled(projectRoot)
|
|
72
73
|
const result = installGitHooks(projectRoot)
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Publish artifact only.
|
|
4
|
+
* Authoring source of truth: source/utils/constants/defaults.json
|
|
5
|
+
* Local CLI prefers the authored file; npm pack needs this copy under x/bin.
|
|
6
|
+
*/
|
|
2
7
|
import fs from 'node:fs'
|
|
3
8
|
import path from 'node:path'
|
|
4
9
|
|
|
@@ -7,10 +12,10 @@ const src = path.join(root, 'source/utils/constants/defaults.json')
|
|
|
7
12
|
const dest = path.join(root, 'x/bin/helpers/defaults.json')
|
|
8
13
|
|
|
9
14
|
if (!fs.existsSync(src)) {
|
|
10
|
-
console.error('sync-cli-defaults: source
|
|
15
|
+
console.error('sync-cli-defaults: source/utils/constants/defaults.json missing')
|
|
11
16
|
process.exit(1)
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
fs.mkdirSync(path.dirname(dest), { recursive: true })
|
|
15
20
|
fs.copyFileSync(src, dest)
|
|
16
|
-
console.log('sync-cli-defaults:
|
|
21
|
+
console.log('sync-cli-defaults: publish copy → x/bin/helpers/defaults.json')
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"packageName": "@xrystal/core",
|
|
3
3
|
"packageRootFolder": "x",
|
|
4
|
+
"cliName": "xry",
|
|
5
|
+
"cliBinNames": [
|
|
6
|
+
"xry"
|
|
7
|
+
],
|
|
4
8
|
"tmpBaseName": "tmp",
|
|
5
9
|
"tmpExtension": ".yml",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
"templateRepoUri": "https://github.com/xdloper/api-gpt-svc",
|
|
11
|
+
"publicFolderName": "public",
|
|
12
|
+
"kafkaLogsTopic": "log",
|
|
13
|
+
"pathAliasKey": "@/*",
|
|
14
|
+
"eslintRestrictedImportDepth": 2,
|
|
15
|
+
"tmpWatchDefaults": {
|
|
16
|
+
"intervalMs": 500,
|
|
17
|
+
"minIntervalMs": 100,
|
|
18
|
+
"maxIntervalMs": 10000
|
|
11
19
|
},
|
|
12
20
|
"buildDefaults": {
|
|
13
21
|
"tsconfig": "tsconfig.json",
|
|
@@ -16,29 +24,5 @@
|
|
|
16
24
|
"declarations": false,
|
|
17
25
|
"sourcemap": false,
|
|
18
26
|
"minify": false
|
|
19
|
-
}
|
|
20
|
-
"tsconfigDefaults": {
|
|
21
|
-
"pathAliasKey": "@/*",
|
|
22
|
-
"compilerOptions": {
|
|
23
|
-
"noEmit": false,
|
|
24
|
-
"noEmitOnError": false,
|
|
25
|
-
"declaration": true,
|
|
26
|
-
"emitDeclarationOnly": false,
|
|
27
|
-
"sourceMap": false,
|
|
28
|
-
"declarationMap": false,
|
|
29
|
-
"strict": true,
|
|
30
|
-
"noImplicitAny": true
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"eslintDefaults": {
|
|
34
|
-
"restrictedImportDepth": 2
|
|
35
|
-
},
|
|
36
|
-
"tmpWatchDefaults": {
|
|
37
|
-
"intervalMs": 500,
|
|
38
|
-
"minIntervalMs": 100,
|
|
39
|
-
"maxIntervalMs": 10000
|
|
40
|
-
},
|
|
41
|
-
"publicFolderName": "public",
|
|
42
|
-
"kafkaLogsTopic": "log",
|
|
43
|
-
"templateRepoUri": "https://github.com/xdloper/api-gpt-svc"
|
|
27
|
+
}
|
|
44
28
|
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import defaults from './defaults.json';
|
|
2
|
-
export type PackageDefaults = typeof defaults
|
|
3
|
-
|
|
4
|
-
layoutPaths:
|
|
5
|
-
|
|
2
|
+
export type PackageDefaults = typeof defaults & {
|
|
3
|
+
mainSourceFolder: string;
|
|
4
|
+
layoutPaths: {
|
|
5
|
+
tests: string;
|
|
6
|
+
environments: string;
|
|
7
|
+
dist: string;
|
|
8
|
+
};
|
|
9
|
+
cliBinNames: readonly string[];
|
|
10
|
+
};
|
|
11
|
+
export declare const packageDefaults: Readonly<PackageDefaults>;
|
|
6
12
|
export declare const coreVersionPattern: RegExp;
|
|
7
13
|
export declare const semverVersionPattern: RegExp;
|
|
8
14
|
export declare class Constants {
|
|
@@ -10,18 +16,20 @@ export declare class Constants {
|
|
|
10
16
|
static readonly packageRootFolder: string;
|
|
11
17
|
static readonly tmpBaseName: string;
|
|
12
18
|
static readonly tmpExtension: string;
|
|
19
|
+
static readonly publicFolderName: string;
|
|
20
|
+
static readonly kafkaLogsTopic: string;
|
|
21
|
+
static readonly templateRepoUri: string;
|
|
22
|
+
static readonly cliName: string;
|
|
23
|
+
static readonly cliBinNames: string[] & readonly string[];
|
|
24
|
+
static readonly pathAliasKey: string;
|
|
25
|
+
/** From bundled x/tmp.yml — used only when project tmp.yml omits paths */
|
|
13
26
|
static readonly mainSourceFolder: string;
|
|
14
27
|
static readonly layoutPaths: {
|
|
15
28
|
tests: string;
|
|
16
29
|
environments: string;
|
|
17
30
|
dist: string;
|
|
18
|
-
}
|
|
19
|
-
tests: string;
|
|
20
|
-
environments: string;
|
|
21
|
-
dist: string;
|
|
22
|
-
}>;
|
|
23
|
-
static readonly publicFolderName: string;
|
|
24
|
-
static readonly kafkaLogsTopic: string;
|
|
25
|
-
static readonly templateRepoUri: string;
|
|
31
|
+
};
|
|
26
32
|
static readonly bundledCoreTmpPath: string;
|
|
27
33
|
}
|
|
34
|
+
/** Stable public re-exports — implementation lives in helpers/tmp. */
|
|
35
|
+
export { seedFromTmp, loadSeedFromBundledTmp } from '../../utils/helpers/tmp/seed-from-tmp';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import n from"node:path";import{packageRootDir as q}from"../../utils/package-root";import b from"./defaults.json" with { type: 'json' };import{seedFromTmp as j}from"../../utils/helpers/tmp/seed-from-tmp";export const packageDefaults=Object.freeze({...b,mainSourceFolder:j.sourceFolder,layoutPaths:Object.freeze({...j.layout}),buildDefaults:Object.freeze({...b.buildDefaults}),tmpWatchDefaults:Object.freeze({...b.tmpWatchDefaults}),cliBinNames:Object.freeze([...b.cliBinNames??[b.cliName]])}),coreVersionPattern=/^\d{2}\.\d{2}\.\d{2}-v\d+$/,semverVersionPattern=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?(?:\+[0-9A-Za-z-.]+)?$/;const v=`${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;export class Constants{static packageName=packageDefaults.packageName;static packageRootFolder=packageDefaults.packageRootFolder;static tmpBaseName=packageDefaults.tmpBaseName;static tmpExtension=packageDefaults.tmpExtension;static publicFolderName=packageDefaults.publicFolderName;static kafkaLogsTopic=packageDefaults.kafkaLogsTopic;static templateRepoUri=packageDefaults.templateRepoUri;static cliName=packageDefaults.cliName;static cliBinNames=packageDefaults.cliBinNames;static pathAliasKey=packageDefaults.pathAliasKey;static mainSourceFolder=packageDefaults.mainSourceFolder;static layoutPaths=packageDefaults.layoutPaths;static bundledCoreTmpPath=n.join(q,packageDefaults.packageRootFolder,v)}export{seedFromTmp,loadSeedFromBundledTmp}from"../../utils/helpers/tmp/seed-from-tmp";
|
|
@@ -3,3 +3,5 @@ export { getTmpLoader, getTmpLoaderPath, getTmpSnapshot, onTmpReload, resetTmpLo
|
|
|
3
3
|
export { bindLoaderTmpSync, type ITmpSyncLoader, } from '../../../utils/helpers/tmp/loader-tmp-sync';
|
|
4
4
|
export { resolveTmpWatchIntervalMs } from '../../../utils/helpers/tmp/tmp-watch';
|
|
5
5
|
export { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, readTmpCoreBlock, readTmpServiceBlock, resolveServiceLayoutPaths, resolveTmpRuntimeConfigs, } from '../../../utils/helpers/tmp/tmp-schema';
|
|
6
|
+
export { loadSeedFromBundledTmp, seedFromTmp, type SeedFromTmp, type SeedLayoutPaths, } from '../../../utils/helpers/tmp/seed-from-tmp';
|
|
7
|
+
export { DEFAULT_LAYOUT_PATHS, normalizeLayoutPaths, type LayoutPaths, } from '../../../utils/helpers/tmp/path-normalize';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{setRuntimeTmpConfigs,getRuntimeTmpConfigs,onRuntimeTmpChange,notifyRuntimeTmpChange,clearRuntimeTmpConfigs}from"../../../utils/helpers/tmp/runtime-tmp";export{getTmpLoader,getTmpLoaderPath,getTmpSnapshot,onTmpReload,resetTmpLoaderForTests,stopTmpLoader}from"../../../utils/helpers/tmp/tmp-loader";export{bindLoaderTmpSync}from"../../../utils/helpers/tmp/loader-tmp-sync";export{resolveTmpWatchIntervalMs}from"../../../utils/helpers/tmp/tmp-watch";export{normalizeTmpDocument,normalizeRootFolder,normalizeSourceFolder,readTmpCoreBlock,readTmpServiceBlock,resolveServiceLayoutPaths,resolveTmpRuntimeConfigs}from"../../../utils/helpers/tmp/tmp-schema";
|
|
1
|
+
export{setRuntimeTmpConfigs,getRuntimeTmpConfigs,onRuntimeTmpChange,notifyRuntimeTmpChange,clearRuntimeTmpConfigs}from"../../../utils/helpers/tmp/runtime-tmp";export{getTmpLoader,getTmpLoaderPath,getTmpSnapshot,onTmpReload,resetTmpLoaderForTests,stopTmpLoader}from"../../../utils/helpers/tmp/tmp-loader";export{bindLoaderTmpSync}from"../../../utils/helpers/tmp/loader-tmp-sync";export{resolveTmpWatchIntervalMs}from"../../../utils/helpers/tmp/tmp-watch";export{normalizeTmpDocument,normalizeRootFolder,normalizeSourceFolder,readTmpCoreBlock,readTmpServiceBlock,resolveServiceLayoutPaths,resolveTmpRuntimeConfigs}from"../../../utils/helpers/tmp/tmp-schema";export{loadSeedFromBundledTmp,seedFromTmp}from"../../../utils/helpers/tmp/seed-from-tmp";export{DEFAULT_LAYOUT_PATHS,normalizeLayoutPaths}from"../../../utils/helpers/tmp/path-normalize";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Pure path normalizers — no Constants / no I/O (shared by seed + schema). */
|
|
2
|
+
export type LayoutPaths = {
|
|
3
|
+
tests: string;
|
|
4
|
+
environments: string;
|
|
5
|
+
dist: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const DEFAULT_LAYOUT_PATHS: Readonly<LayoutPaths>;
|
|
8
|
+
export declare function normalizeRootFolder(value: unknown, fallback?: string): string;
|
|
9
|
+
export declare function normalizeSourceFolder(value: unknown, fallback?: string): string;
|
|
10
|
+
export declare function normalizeLayoutPaths(special: unknown, fallback?: LayoutPaths): LayoutPaths;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_LAYOUT_PATHS=Object.freeze({tests:"tests",environments:"environments",dist:"dist"});export function normalizeRootFolder(t,n="x"){if(typeof t!=="string"||!t.trim())return n;return t.trim().replace(/^\.\/+/,"")}export function normalizeSourceFolder(t,n="./source"){if(typeof t!=="string"||!t.trim())return n;const r=t.trim();if(r.startsWith("./")||r.startsWith("../"))return r;return`./${r}`}export function normalizeLayoutPaths(t,n=DEFAULT_LAYOUT_PATHS){const r=t&&typeof t==="object"&&!Array.isArray(t)?t:{},e=(s)=>{const o=r[s];return typeof o==="string"&&o.trim()?o.trim():n[s]};return{tests:e("tests"),environments:e("environments"),dist:e("dist")}}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type LayoutPaths } from '../../../utils/helpers/tmp/path-normalize';
|
|
2
|
+
export type SeedLayoutPaths = LayoutPaths;
|
|
3
|
+
export type SeedFromTmp = {
|
|
4
|
+
rootFolder: string;
|
|
5
|
+
sourceFolder: string;
|
|
6
|
+
layout: SeedLayoutPaths;
|
|
7
|
+
};
|
|
8
|
+
export declare function loadSeedFromBundledTmp(tmpFilePath?: string): SeedFromTmp;
|
|
9
|
+
export declare const seedFromTmp: SeedFromTmp;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import I from"node:fs";import N from"node:path";import Q from"yaml";import j from"../../../utils/constants/defaults.json" with { type: 'json' };import{packageRootDir as V}from"../../../utils/package-root";import{DEFAULT_LAYOUT_PATHS as J,normalizeLayoutPaths as W,normalizeRootFolder as X,normalizeSourceFolder as Z}from"../../../utils/helpers/tmp/path-normalize";export function loadSeedFromBundledTmp(K){const G=K??N.join(V,j.packageRootFolder,`${j.tmpBaseName}${j.tmpExtension}`),M={rootFolder:j.packageRootFolder,sourceFolder:"./source",layout:{...J}};if(!I.existsSync(G))return M;const q=Q.parse(I.readFileSync(G,"utf8")),w=q?.configs&&typeof q.configs==="object"?q.configs:{},x=w.service&&typeof w.service==="object"?w.service:{},C=x.paths&&typeof x.paths==="object"?x.paths:{};return{rootFolder:X(C.root,j.packageRootFolder),sourceFolder:Z(C.source,"./source"),layout:W(C.special,J)}}export const seedFromTmp=loadSeedFromBundledTmp();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import J from"node:fs";import K from"node:path";import{Constants as
|
|
1
|
+
import J from"node:fs";import K from"node:path";import{Constants as z}from"../../../utils/constants";import{assertCoreTmpGuard as M,coreCanonicalTmpPath as O,isCorePackageRoot as Q}from"../../../utils/helpers/core/tmp-layout";import{findFileRecursively as U}from"../../../utils/helpers/core/paths";import{TmpFileLoader as V}from"../../../utils/models/classes/class.tmp-file-loader";import{registerGracefulShutdown as W}from"../../../utils/helpers/runtime/shutdown";let q=null,B=null;function X(D=process.cwd(),j=z.tmpBaseName,b=z.tmpExtension){const A=K.resolve(D);if(Q(A)){const E=O(A);if(!J.existsSync(E))throw Error(`${z.packageRootFolder}/tmp.yml not found. Run ${z.cliName} tmp or ensureCoreTmpEntry() before starting ${z.packageName}`);M(A,E);return E}const H=U(A,j,b);if(!H)throw Error(`${j}${b.startsWith(".")?b:`.${b}`} file not found`);return H}export function getTmpLoaderPath(){if(!B)B=X();return B}export function getTmpLoader(){if(!q){q=new V({filePath:getTmpLoaderPath()});W()}return q}export function getTmpSnapshot(){return getTmpLoader().getResolvedTmpFile()}export function onTmpReload(D){const j=getTmpLoader(),b=()=>D(j.getResolvedTmpFile());j.on("reload",b);return()=>j.off("reload",b)}export function stopTmpLoader(){if(q){q.stop();q=null;B=null}}export function resetTmpLoaderForTests(){stopTmpLoader()}
|
|
@@ -41,6 +41,7 @@ export declare function normalizeRootFolder(value?: string): string;
|
|
|
41
41
|
export declare function normalizeSourceFolder(value?: string): string;
|
|
42
42
|
export declare function readTmpCoreBlock(configs?: Record<string, unknown>): TmpCoreBlock;
|
|
43
43
|
export declare function readTmpServiceBlock(configs?: Record<string, unknown>): TmpServiceBlock;
|
|
44
|
+
/** Project layout from tmp.yml; omitted specials → bootstrap layout (same as bundled x/tmp.yml). */
|
|
44
45
|
export declare function resolveServiceLayoutPaths(service: TmpServiceBlock): TmpLayoutPathsFlat;
|
|
45
46
|
/** Canonical tmp.yml shape — `service` + `core` + derived `rootFolderPath`. */
|
|
46
47
|
export declare function resolveTmpRuntimeConfigs(tmp?: Record<string, unknown> | null): TmpRuntimeConfigs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import X from"../../../utils/constants/defaults.json" with { type: 'json' };import{DEFAULT_LAYOUT_PATHS as D,normalizeLayoutPaths as H,normalizeRootFolder as I,normalizeSourceFolder as W}from"../../../utils/helpers/tmp/path-normalize";const Z="./source";function G(j){return typeof j==="object"&&j!==null&&!Array.isArray(j)}function Y(j){if(typeof j==="number"||typeof j==="string")return j;return}export function normalizeRootFolder(j){return I(j,X.packageRootFolder)}export function normalizeSourceFolder(j){return W(j,Z)}export function readTmpCoreBlock(j){const q=G(j?.core)?j.core:{},x=G(q.tmp)?q.tmp:{};return{tmp:{fileWatchIntervalMs:Y(x.fileWatchIntervalMs)}}}export function readTmpServiceBlock(j){const q=G(j?.service)?j.service:{},x=G(q.paths)?q.paths:{},J=G(x.special)?x.special:{};let K=G(q.loaders)?{...q.loaders}:void 0,M=G(q.build)?q.build:void 0;if(K&&G(K.build)){const{build:Q,...$}=K;K=$;if(!M&&G(Q))M=Q}return{name:typeof q.name==="string"?q.name:void 0,framework:typeof q.framework==="string"?q.framework:void 0,paths:{root:typeof x.root==="string"?x.root:void 0,source:typeof x.source==="string"?x.source:void 0,special:{tests:typeof J.tests==="string"?J.tests:void 0,environments:typeof J.environments==="string"?J.environments:void 0,dist:typeof J.dist==="string"?J.dist:void 0}},protocols:q.protocols,loaders:K,build:M}}export function resolveServiceLayoutPaths(j){return H(j.paths?.special,D)}function k(j){const q=resolveServiceLayoutPaths(j);return{name:j.name,framework:j.framework??"elysia",paths:{root:j.paths?.root??X.packageRootFolder,source:j.paths?.source??Z,special:q},protocols:j.protocols,loaders:j.loaders,build:j.build}}function N(j){return{tmp:{fileWatchIntervalMs:j.tmp?.fileWatchIntervalMs}}}export function resolveTmpRuntimeConfigs(j){const q=G(j?.configs)?j.configs:{},x=readTmpServiceBlock(q),J=readTmpCoreBlock(q),K=k(x);return{service:K,core:N(J),rootFolderPath:normalizeRootFolder(K.paths.root)}}export function normalizeTmpDocument(j){return{...j,configs:resolveTmpRuntimeConfigs(j)}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import I
|
|
1
|
+
import{packageDefaults as I}from"../../../utils/constants";import{readTmpCoreBlock as J}from"../../../utils/helpers/tmp/tmp-schema";const b=I.tmpWatchDefaults;export function resolveTmpWatchIntervalMs(q){const v=q?.configs,y=J(v).tmp?.fileWatchIntervalMs??b.intervalMs,j=Number(y);if(!Number.isFinite(j))return b.intervalMs;const z=b.minIntervalMs??100,G=b.maxIntervalMs??1e4;return Math.min(G,Math.max(z,Math.round(j)))}
|