@xrystal/core 3.52.9 → 3.53.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/package.json +1 -1
- package/x/bin/commands/create.mjs +7 -0
- package/x/bin/commands/doctor.mjs +8 -2
- package/x/bin/commands/hooks.mjs +9 -3
- package/x/bin/commands/project.mjs +83 -79
- package/x/bin/commands/release.mjs +7 -3
- package/x/bin/commands/sync.mjs +3 -0
- package/x/bin/commands/tmp.mjs +40 -20
- package/x/bin/helpers/cli-context-guard.mjs +76 -0
- package/x/bin/helpers/project-context.mjs +2 -1
- package/x/bin/helpers/project-root.mjs +19 -6
- package/x/bin/helpers/sync-scope.mjs +5 -0
- package/x/bin/helpers/workspace-tmp.mjs +20 -0
package/package.json
CHANGED
|
@@ -109,6 +109,13 @@ export function registerCreateCommand(cli, { cliName = CLI_PRIMARY_NAME, runtime
|
|
|
109
109
|
process.exit(1)
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
if (isCurrentDir && inWorkspace && workspaceRoot) {
|
|
113
|
+
console.error(chalk.red('\n✗ Cannot init workspace root as a service (create .)\n'))
|
|
114
|
+
console.error(chalk.gray(' Use xry create <name> to add api/web/mobile project'))
|
|
115
|
+
console.error(chalk.gray(' Or xry create <name> --workspace to scaffold a new workspace\n'))
|
|
116
|
+
process.exit(1)
|
|
117
|
+
}
|
|
118
|
+
|
|
112
119
|
if (inWorkspace) {
|
|
113
120
|
const version = readCliPackageJson().version
|
|
114
121
|
printCommandHeader({ cliName, command: 'create (workspace link)', version })
|
|
@@ -5,10 +5,10 @@ import { resolveDistLayout } from '../helpers/project-artifacts.mjs'
|
|
|
5
5
|
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
6
6
|
import {
|
|
7
7
|
getInstalledCoreVersion,
|
|
8
|
-
getProjectRoot,
|
|
9
8
|
readCliPackageJson,
|
|
10
9
|
readProjectPackageJson,
|
|
11
10
|
} from '../helpers/project-root.mjs'
|
|
11
|
+
import { requireServiceRoot, exitOnCliContextError } from '../helpers/cli-context-guard.mjs'
|
|
12
12
|
import { listRuntimeInventory, resolveRuntimeInfo } from '../helpers/runtime-info.mjs'
|
|
13
13
|
import { evaluateVersionBump, getVersionState, resolveCommitVersionHint, resolveVersionBaseline, VERSION_PATTERN } from '../scripts/version-check.mjs'
|
|
14
14
|
import { auditTsconfigAlignment, resolveToolchainPathsFromProject } from '../helpers/toolchain-config.mjs'
|
|
@@ -30,7 +30,13 @@ export function registerDoctorCommand(cli, { cliName = CLI_PRIMARY_NAME } = {})
|
|
|
30
30
|
.command('doctor')
|
|
31
31
|
.description(`Check runtime, git, and ${packageDefaults.packageName} alignment`)
|
|
32
32
|
.action(async () => {
|
|
33
|
-
|
|
33
|
+
let root
|
|
34
|
+
try {
|
|
35
|
+
;({ root } = requireServiceRoot(process.cwd(), { cliName, command: 'doctor' }))
|
|
36
|
+
} catch (error) {
|
|
37
|
+
exitOnCliContextError(error)
|
|
38
|
+
}
|
|
39
|
+
|
|
34
40
|
const cliPkg = readCliPackageJson()
|
|
35
41
|
const projectPkg = readProjectPackageJson(root)
|
|
36
42
|
const core = getInstalledCoreVersion(root)
|
package/x/bin/commands/hooks.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import chalk from 'chalk'
|
|
|
3
3
|
import { printCommandHeader } from '../helpers/banner.mjs'
|
|
4
4
|
import { readCliPackageJson } from '../helpers/project-root.mjs'
|
|
5
5
|
import { installGitHooks, isGitHookInstalled } from '../scripts/install-git-hooks.mjs'
|
|
6
|
-
import {
|
|
6
|
+
import { requireServiceRoot, exitOnCliContextError } from '../helpers/cli-context-guard.mjs'
|
|
7
7
|
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
8
8
|
import { packageDefaults } from '../helpers/package-defaults.mjs'
|
|
9
9
|
|
|
@@ -25,7 +25,7 @@ export function registerHooksCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
25
25
|
.description('Write pre-commit hook to .git/hooks (core repo + services)')
|
|
26
26
|
.action(() => {
|
|
27
27
|
try {
|
|
28
|
-
const root =
|
|
28
|
+
const { root } = requireServiceRoot(process.cwd(), { cliName, command: 'hooks install' })
|
|
29
29
|
printCommandHeader({ cliName, command: 'hooks install', version: readCliPackageJson().version })
|
|
30
30
|
|
|
31
31
|
if (isGitHookInstalled(root)) {
|
|
@@ -39,6 +39,7 @@ export function registerHooksCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
39
39
|
console.log(chalk.gray(` checker: ${result.scriptPath}`))
|
|
40
40
|
console.log(chalk.dim('\n Runs on git commit when package.json version changes.\n'))
|
|
41
41
|
} catch (error) {
|
|
42
|
+
exitOnCliContextError(error)
|
|
42
43
|
console.error(chalk.red(`\n✗ ${error.message}\n`))
|
|
43
44
|
process.exit(1)
|
|
44
45
|
}
|
|
@@ -48,7 +49,12 @@ export function registerHooksCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
48
49
|
.command('status')
|
|
49
50
|
.description(`Show whether ${packageDefaults.packageName} pre-commit hook is installed`)
|
|
50
51
|
.action(() => {
|
|
51
|
-
|
|
52
|
+
let root
|
|
53
|
+
try {
|
|
54
|
+
;({ root } = requireServiceRoot(process.cwd(), { cliName, command: 'hooks status' }))
|
|
55
|
+
} catch (error) {
|
|
56
|
+
exitOnCliContextError(error)
|
|
57
|
+
}
|
|
52
58
|
printCommandHeader({ cliName, command: 'hooks status', version: readCliPackageJson().version })
|
|
53
59
|
const installed = isGitHookInstalled(root)
|
|
54
60
|
console.log(` pre-commit: ${installed ? chalk.green('installed') : chalk.yellow('not installed')}`)
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
shouldDelegatePackageBuild,
|
|
19
19
|
summarizeBuildPlan,
|
|
20
20
|
} from '../helpers/build-config.mjs'
|
|
21
|
-
import {
|
|
21
|
+
import { runWithServiceRoot } from '../helpers/cli-context-guard.mjs'
|
|
22
22
|
import { printCommandHeader } from '../helpers/banner.mjs'
|
|
23
23
|
import { readCliPackageJson } from '../helpers/project-root.mjs'
|
|
24
24
|
import { ensureTmpFile, relativeFromRoot } from '../helpers/tmp-layout.mjs'
|
|
@@ -41,100 +41,104 @@ function resolveTestTarget(root) {
|
|
|
41
41
|
export function registerProjectCommands(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
42
42
|
cli
|
|
43
43
|
.command('dev')
|
|
44
|
-
.description('Watch TypeScript entry with dev env files')
|
|
44
|
+
.description('Watch TypeScript entry with dev env files (service repo only — not workspace root)')
|
|
45
45
|
.action(() => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
46
|
+
runWithServiceRoot((root) => {
|
|
47
|
+
const { layout, runtime } = readTmpBuildContext(root)
|
|
48
|
+
const entry = resolveDevEntry(root, layout)
|
|
49
|
+
const envFiles = resolveEnvFiles(layout.pathsAbs.environments, ['.global.env', '.dev.env'])
|
|
50
|
+
const envArgs = envFiles.map((file) => `--env-file=${file}`).join(' ')
|
|
51
|
+
const runner = resolveRuntimeRunner(runtime)
|
|
52
|
+
|
|
53
|
+
printCommandHeader({ cliName, command: 'dev', version: readCliPackageJson().version })
|
|
54
|
+
console.log(chalk.gray(` root: ${root}`))
|
|
55
|
+
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
56
|
+
console.log(chalk.gray(` entry: ${entry} (.ts)\n`))
|
|
57
|
+
runInProject(root, `${runner} --watch ${envArgs} ${entry}`.trim())
|
|
58
|
+
}, { cliName, command: 'dev' })
|
|
58
59
|
})
|
|
59
60
|
|
|
60
61
|
cli
|
|
61
62
|
.command('build')
|
|
62
|
-
.description('Bundle to dist/ (
|
|
63
|
+
.description('Bundle to dist/ (service repo only — not workspace root)')
|
|
63
64
|
.action(() => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
65
|
+
runWithServiceRoot((root) => {
|
|
66
|
+
ensureProjectArtifacts(root, { writeToolchain: true, writeManifest: true })
|
|
67
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'))
|
|
68
|
+
const { layout, build, runtime, bundler } = readTmpBuildContext(root)
|
|
69
|
+
|
|
70
|
+
printCommandHeader({ cliName, command: 'build', version: readCliPackageJson().version })
|
|
71
|
+
console.log(chalk.gray(` root: ${root}`))
|
|
72
|
+
|
|
73
|
+
if (shouldDelegatePackageBuild(pkg)) {
|
|
74
|
+
runInProject(root, `${resolvePackageScriptRunner(runtime)} build`)
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const plan = summarizeBuildPlan(root, layout, build, runtime)
|
|
79
|
+
const steps = isCorePackageName(pkg.name)
|
|
80
|
+
? resolveCoreBuildSteps(root, plan.distRel, build)
|
|
81
|
+
: resolveServiceBuildSteps(root, layout, build, runtime)
|
|
82
|
+
console.log(chalk.gray(` mode: ${isCorePackageName(pkg.name) ? 'core entries' : 'service tsconfig + tmp overrides'}`))
|
|
83
|
+
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
84
|
+
if (!isCorePackageName(pkg.name)) {
|
|
85
|
+
console.log(chalk.gray(` bundler: ${plan.bundler || bundler}`))
|
|
86
|
+
}
|
|
87
|
+
if (plan.tsconfigRel) {
|
|
88
|
+
console.log(chalk.gray(` tsconfig: ${plan.tsconfigRel}`))
|
|
89
|
+
}
|
|
90
|
+
console.log(chalk.gray(` dist: ${plan.distRel}/ (${plan.distSource})`))
|
|
91
|
+
console.log(chalk.gray(` glob: ${plan.entryGlobs.join(', ')} (${plan.globSource})`))
|
|
92
|
+
if (plan.typecheck) console.log(chalk.gray(' typecheck: tsc --noEmit'))
|
|
93
|
+
if (plan.declarations) console.log(chalk.gray(' declarations: tsc --emitDeclarationOnly'))
|
|
94
|
+
if (plan.sourcemap !== 'false') console.log(chalk.gray(` sourcemap: ${plan.sourcemap}`))
|
|
95
|
+
if (plan.minify && plan.minify !== 'off') console.log(chalk.gray(` minify: ${plan.minify}`))
|
|
96
|
+
console.log('')
|
|
97
|
+
|
|
98
|
+
runInProject(root, steps.join(' && '))
|
|
99
|
+
}, { cliName, command: 'build' })
|
|
98
100
|
})
|
|
99
101
|
|
|
100
102
|
cli
|
|
101
103
|
.command('start')
|
|
102
104
|
.alias('start:dist')
|
|
103
|
-
.description('Run dist/index.js with prod env files')
|
|
105
|
+
.description('Run dist/index.js with prod env files (service repo only)')
|
|
104
106
|
.action(() => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
107
|
+
runWithServiceRoot((root) => {
|
|
108
|
+
const { layout, build, runtime } = readTmpBuildContext(root)
|
|
109
|
+
const entryAbs = resolveDistEntryAbs(root, layout, build)
|
|
110
|
+
|
|
111
|
+
if (!fs.existsSync(entryAbs)) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
`Build output not found: ${path.relative(root, entryAbs)}. Run ${cliName} build first.`,
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const entry = relativeFromRoot(root, entryAbs)
|
|
118
|
+
const envFiles = resolveEnvFiles(layout.pathsAbs.environments, ['.global.env', '.prod.env'])
|
|
119
|
+
const envArgs = envFiles.map((file) => `--env-file=${file}`).join(' ')
|
|
120
|
+
const runner = resolveRuntimeRunner(runtime)
|
|
121
|
+
|
|
122
|
+
printCommandHeader({ cliName, command: 'start', version: readCliPackageJson().version })
|
|
123
|
+
console.log(chalk.gray(` root: ${root}`))
|
|
124
|
+
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
125
|
+
console.log(chalk.gray(` entry: ${entry} (.js)\n`))
|
|
126
|
+
runInProject(root, `${runner} ${envArgs} ${entry}`.trim())
|
|
127
|
+
}, { cliName, command: 'start' })
|
|
125
128
|
})
|
|
126
129
|
|
|
127
130
|
cli
|
|
128
131
|
.command('test')
|
|
129
|
-
.description('Run tests from tmp.yml paths')
|
|
132
|
+
.description('Run tests from tmp.yml paths (service repo only)')
|
|
130
133
|
.action(() => {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
runWithServiceRoot((root) => {
|
|
135
|
+
const { runtime } = readTmpBuildContext(root)
|
|
136
|
+
const target = resolveTestTarget(root)
|
|
137
|
+
|
|
138
|
+
printCommandHeader({ cliName, command: 'test', version: readCliPackageJson().version })
|
|
139
|
+
console.log(chalk.gray(` runtime: ${runtime}`))
|
|
140
|
+
console.log(chalk.gray(` target: ${target}\n`))
|
|
141
|
+
runInProject(root, resolveTestCommand(runtime, target))
|
|
142
|
+
}, { cliName, command: 'test' })
|
|
139
143
|
})
|
|
140
144
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
|
-
import { readCliPackageJson, readProjectPackageJson
|
|
2
|
+
import { readCliPackageJson, readProjectPackageJson } from '../helpers/project-root.mjs'
|
|
3
|
+
import { requireServiceRoot, exitOnCliContextError } from '../helpers/cli-context-guard.mjs'
|
|
3
4
|
import { compareSemver, getVersionState, resolveVersionBaseline, runTagRelease } from '../scripts/version-check.mjs'
|
|
4
5
|
import { CLI_PRIMARY_NAME, PACKAGE_NAME } from '../helpers/cli-identity.mjs'
|
|
5
6
|
import { packageDefaults } from '../helpers/package-defaults.mjs'
|
|
@@ -13,16 +14,18 @@ export function registerTagCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
13
14
|
.option('--skip-prepare', 'Skip lint, test, and build:prod (core only)')
|
|
14
15
|
.action(async (options) => {
|
|
15
16
|
try {
|
|
17
|
+
const { root } = requireServiceRoot(process.cwd(), { cliName, command: 'tag' })
|
|
16
18
|
await runTagRelease({
|
|
17
19
|
dryRun: options.dryRun,
|
|
18
20
|
requireClean: options.strictClean,
|
|
19
21
|
skipPrepare: options.skipPrepare,
|
|
20
|
-
root
|
|
22
|
+
root,
|
|
21
23
|
})
|
|
22
24
|
if (!options.dryRun) {
|
|
23
25
|
console.log(chalk.green('\n✓ Tag pushed.\n'))
|
|
24
26
|
}
|
|
25
27
|
} catch (error) {
|
|
28
|
+
if (error?.name === 'CliContextError') exitOnCliContextError(error)
|
|
26
29
|
console.error(chalk.red(`\n✗ ${error.message}\n`))
|
|
27
30
|
process.exit(1)
|
|
28
31
|
}
|
|
@@ -35,7 +38,7 @@ export function registerVersionCommand(cli, { cliName = CLI_PRIMARY_NAME } = {})
|
|
|
35
38
|
.description('Show CLI and project package versions')
|
|
36
39
|
.action(() => {
|
|
37
40
|
try {
|
|
38
|
-
const root =
|
|
41
|
+
const { root } = requireServiceRoot(process.cwd(), { cliName, command: 'version' })
|
|
39
42
|
const cliPkg = readCliPackageJson()
|
|
40
43
|
const projectPkg = readProjectPackageJson(root)
|
|
41
44
|
const state = getVersionState('HEAD', root)
|
|
@@ -61,6 +64,7 @@ export function registerVersionCommand(cli, { cliName = CLI_PRIMARY_NAME } = {})
|
|
|
61
64
|
console.log(` working tree: ${state.isClean ? chalk.green('clean') : chalk.yellow('dirty')}`)
|
|
62
65
|
console.log('')
|
|
63
66
|
} catch (error) {
|
|
67
|
+
if (error?.name === 'CliContextError') exitOnCliContextError(error)
|
|
64
68
|
console.error(chalk.red(`\n✗ ${error.message}\n`))
|
|
65
69
|
process.exit(1)
|
|
66
70
|
}
|
package/x/bin/commands/sync.mjs
CHANGED
|
@@ -25,6 +25,9 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
printCommandHeader({ cliName, command: 'sync', version: coreVersion })
|
|
28
|
+
if (scope.warnAllIgnored) {
|
|
29
|
+
console.log(chalk.yellow(' note: not in a workspace — --all ignored, syncing this repo only'))
|
|
30
|
+
}
|
|
28
31
|
console.log(chalk.gray(` scope: ${scope.label} (${scope.mode})`))
|
|
29
32
|
if (scope.workspaceRoot) {
|
|
30
33
|
console.log(chalk.gray(` workspace: ${scope.workspaceRoot}`))
|
package/x/bin/commands/tmp.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import yaml from 'yaml'
|
|
|
4
4
|
|
|
5
5
|
import { printCommandFooter, printCommandHeader } from '../helpers/banner.mjs'
|
|
6
6
|
import { resolveObjWithHandlebars } from '../helpers/index.mjs'
|
|
7
|
-
import {
|
|
7
|
+
import { readCliPackageJson } from '../helpers/project-root.mjs'
|
|
8
8
|
import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
|
|
9
9
|
import {
|
|
10
10
|
ensureTmpFile,
|
|
@@ -15,55 +15,75 @@ import {
|
|
|
15
15
|
import { formatLoaderSummary, summarizeLoaders } from '../helpers/tmp-config.mjs'
|
|
16
16
|
import { packageDefaults } from '../helpers/package-defaults.mjs'
|
|
17
17
|
import { ensureTmpSchemaVersion, readTmpSchemaVersion } from '../helpers/tmp-schema-version.mjs'
|
|
18
|
-
import {
|
|
18
|
+
import { getCliContext } from '../helpers/cli-context-guard.mjs'
|
|
19
|
+
import { ensureOuterWorkspaceTmp } from '../helpers/workspace-tmp.mjs'
|
|
20
|
+
|
|
21
|
+
function ensureTmpForContext(ctx) {
|
|
22
|
+
if (ctx.kind === 'workspace-root') {
|
|
23
|
+
const outer = ensureOuterWorkspaceTmp(ctx.workspaceRoot)
|
|
24
|
+
return {
|
|
25
|
+
tmpFilePath: outer.tmpFilePath,
|
|
26
|
+
created: outer.created,
|
|
27
|
+
layout: null,
|
|
28
|
+
schema: outer.schema,
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const result = ensureTmpFile(ctx.projectRoot)
|
|
32
|
+
return { ...result, schema: ensureTmpSchemaVersion(result.tmpFilePath) }
|
|
33
|
+
}
|
|
19
34
|
|
|
20
35
|
export function registerTmpCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
|
|
21
36
|
cli
|
|
22
37
|
.command('tmp')
|
|
23
|
-
.description(
|
|
38
|
+
.description('Ensure tmp.yml for current scope (outer workspace or inner service)')
|
|
24
39
|
.option('--dry-run', 'Show target path without writing')
|
|
25
40
|
.action((options) => {
|
|
26
|
-
const
|
|
41
|
+
const ctx = getCliContext()
|
|
27
42
|
const version = readCliPackageJson().version
|
|
43
|
+
const root = ctx.kind === 'workspace-root' ? ctx.workspaceRoot : ctx.projectRoot
|
|
28
44
|
|
|
29
45
|
if (options.dryRun) {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
46
|
+
const target = ctx.kind === 'workspace-root'
|
|
47
|
+
? `${ctx.workspaceRoot}/tmp.yml`
|
|
48
|
+
: (resolveTmpLayoutOrDefaults(root).tmpFilePath ?? ownerTmpFilePath(root))
|
|
33
49
|
|
|
34
50
|
printCommandHeader({ cliName, command: 'tmp (dry-run)', version })
|
|
51
|
+
console.log(chalk.gray(` scope: ${ctx.label}`))
|
|
35
52
|
console.log(chalk.gray(` root: ${root}`))
|
|
36
|
-
console.log(` ${
|
|
53
|
+
console.log(` ${fs.existsSync(target) ? 'exists' : 'would create'}: ${target}`)
|
|
37
54
|
printCommandFooter({ version })
|
|
38
55
|
return
|
|
39
56
|
}
|
|
40
57
|
|
|
41
|
-
const result =
|
|
58
|
+
const result = ensureTmpForContext(ctx)
|
|
42
59
|
const rel = relativeFromRoot(root, result.tmpFilePath)
|
|
43
|
-
const schema = ensureTmpSchemaVersion(result.tmpFilePath)
|
|
44
60
|
|
|
45
|
-
const ctx = resolveProjectContext()
|
|
46
61
|
printCommandHeader({ cliName, command: 'tmp', version })
|
|
47
62
|
console.log(chalk.gray(` scope: ${ctx.label}`))
|
|
48
63
|
console.log(chalk.gray(` root: ${root}`))
|
|
49
64
|
console.log(result.created ? chalk.green(` created ${rel}`) : chalk.gray(` ok ${rel}`))
|
|
65
|
+
|
|
50
66
|
const schemaVersion = readTmpSchemaVersion(result.tmpFilePath)
|
|
51
67
|
if (schemaVersion) {
|
|
52
|
-
const schemaLabel = schema
|
|
68
|
+
const schemaLabel = result.schema?.patched
|
|
53
69
|
? chalk.green(` end.version → ${schemaVersion} (schema)`)
|
|
54
70
|
: chalk.gray(` end.version: ${schemaVersion} (schema)`)
|
|
55
71
|
console.log(schemaLabel)
|
|
56
72
|
}
|
|
57
73
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
74
|
+
if (ctx.kind !== 'workspace-root') {
|
|
75
|
+
try {
|
|
76
|
+
const tmp = yaml.parse(fs.readFileSync(result.tmpFilePath, 'utf8'))
|
|
77
|
+
const summary = summarizeLoaders(resolveObjWithHandlebars(tmp, tmp))
|
|
78
|
+
console.log(chalk.gray(` root: ${result.layout?.rootFolderPath ?? 'x'} · project: ${summary.project ?? '-'}`))
|
|
79
|
+
if (summary.items?.length) {
|
|
80
|
+
console.log(chalk.gray(` loaders: ${formatLoaderSummary(summary)}`))
|
|
81
|
+
}
|
|
82
|
+
} catch {
|
|
83
|
+
// summary optional
|
|
64
84
|
}
|
|
65
|
-
}
|
|
66
|
-
|
|
85
|
+
} else {
|
|
86
|
+
console.log(chalk.gray(' outer workspace tmp — layout only (no loaders)'))
|
|
67
87
|
}
|
|
68
88
|
|
|
69
89
|
printCommandFooter({ version })
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
|
|
6
|
+
import { resolveProjectContext } from './project-context.mjs'
|
|
7
|
+
|
|
8
|
+
export class CliContextError extends Error {
|
|
9
|
+
constructor(message, { hints = [] } = {}) {
|
|
10
|
+
super(message)
|
|
11
|
+
this.name = 'CliContextError'
|
|
12
|
+
this.hints = hints
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getCliContext(startDir = process.cwd()) {
|
|
17
|
+
return resolveProjectContext(startDir)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function requireServiceRoot(startDir = process.cwd(), { cliName = 'xry', command = 'dev' } = {}) {
|
|
21
|
+
const ctx = getCliContext(startDir)
|
|
22
|
+
|
|
23
|
+
if (ctx.kind === 'workspace-root') {
|
|
24
|
+
const examples = (ctx.workspaceEntries ?? [])
|
|
25
|
+
.slice(0, 3)
|
|
26
|
+
.map((entry) => {
|
|
27
|
+
const rel = path.relative(ctx.cwd, entry.path) || entry.path
|
|
28
|
+
return `cd ${rel} && ${cliName} ${command}`
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
throw new CliContextError(
|
|
32
|
+
'Workspace root is layout-only (outer tmp.yml) — not a runnable service.',
|
|
33
|
+
{
|
|
34
|
+
hints: [
|
|
35
|
+
'Use a linked project under api/, web/, or mobile/',
|
|
36
|
+
...examples,
|
|
37
|
+
`${cliName} project — list linked services`,
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const pkgPath = path.join(ctx.projectRoot, 'package.json')
|
|
44
|
+
if (!fs.existsSync(pkgPath)) {
|
|
45
|
+
throw new CliContextError(
|
|
46
|
+
`No service package.json here (${ctx.projectRoot}).`,
|
|
47
|
+
{
|
|
48
|
+
hints: [
|
|
49
|
+
`${cliName} project — see current scope`,
|
|
50
|
+
'cd into api/<service>, web/<app>, or mobile/<app>',
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { ctx, root: ctx.projectRoot }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function exitOnCliContextError(error) {
|
|
60
|
+
if (error?.name !== 'CliContextError') throw error
|
|
61
|
+
console.error(chalk.red(`\n✗ ${error.message}\n`))
|
|
62
|
+
for (const hint of error.hints ?? []) {
|
|
63
|
+
console.error(chalk.gray(` → ${hint}`))
|
|
64
|
+
}
|
|
65
|
+
console.error('')
|
|
66
|
+
process.exit(1)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function runWithServiceRoot(fn, { cliName = 'xry', command = 'dev' } = {}) {
|
|
70
|
+
try {
|
|
71
|
+
const { root, ctx } = requireServiceRoot(process.cwd(), { cliName, command })
|
|
72
|
+
return fn(root, ctx)
|
|
73
|
+
} catch (error) {
|
|
74
|
+
exitOnCliContextError(error)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -109,7 +109,8 @@ export function resolveProjectContext(startDir = process.cwd()) {
|
|
|
109
109
|
if (kind === 'workspace-root') {
|
|
110
110
|
hints.push('Outer tmp: ./tmp.yml · inner tmp: each api|web|mobile project (admin → web/)')
|
|
111
111
|
hints.push('xry sync — all linked projects + ~/.xrystal registry')
|
|
112
|
-
hints.push('xry
|
|
112
|
+
hints.push('xry create <name> — adds api/<name> (or --web / --mobile)')
|
|
113
|
+
hints.push('dev/build/start — run inside a linked service, not here')
|
|
113
114
|
hints.push('xry workspaces — global registry (~/.xrystal), not repo tmp files')
|
|
114
115
|
} else if (kind === 'workspace-service') {
|
|
115
116
|
hints.push(`Outer workspace: ${workspaceRoot}`)
|
|
@@ -2,24 +2,37 @@ import fs from 'node:fs'
|
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
|
|
4
4
|
import { packageDefaults, packageRoot } from '../paths.mjs'
|
|
5
|
+
import { findWorkspaceRoot } from './workspace-resolve.mjs'
|
|
5
6
|
|
|
6
7
|
export function getProjectRoot(startDir = process.cwd()) {
|
|
7
8
|
return resolveProjectRoot(startDir)
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
/** Nearest package.json with @xrystal/core — never walks above workspace root. */
|
|
10
12
|
export function resolveProjectRoot(startDir = process.cwd()) {
|
|
11
13
|
let dir = path.resolve(startDir)
|
|
14
|
+
const workspaceRoot = findWorkspaceRoot(dir)
|
|
15
|
+
const floor = workspaceRoot ? path.resolve(workspaceRoot) : null
|
|
12
16
|
|
|
13
|
-
while (
|
|
17
|
+
while (true) {
|
|
14
18
|
const pkgPath = path.join(dir, 'package.json')
|
|
15
19
|
if (fs.existsSync(pkgPath)) {
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
try {
|
|
21
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
22
|
+
if (pkg.name === packageDefaults.packageName) return dir
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies }
|
|
25
|
+
if (deps[packageDefaults.packageName]) return dir
|
|
26
|
+
} catch {
|
|
27
|
+
// ignore malformed package.json
|
|
28
|
+
}
|
|
21
29
|
}
|
|
22
|
-
|
|
30
|
+
|
|
31
|
+
if (floor && path.resolve(dir) === floor) break
|
|
32
|
+
|
|
33
|
+
const parent = path.dirname(dir)
|
|
34
|
+
if (parent === dir) break
|
|
35
|
+
dir = parent
|
|
23
36
|
}
|
|
24
37
|
|
|
25
38
|
return path.resolve(startDir)
|
|
@@ -32,9 +32,14 @@ export function resolveSyncScope(cwd = process.cwd(), options = {}) {
|
|
|
32
32
|
targetRoot: projectRoot,
|
|
33
33
|
workspaceRoot: null,
|
|
34
34
|
entries: [{ path: projectRoot, name: path.basename(projectRoot), type: 'project' }],
|
|
35
|
+
warnAllIgnored: wantAll,
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
if (atWorkspaceRoot && wantSelf) {
|
|
40
|
+
throw new Error('At workspace root use plain sync (all linked projects). --self is for inner api/web/mobile folders.')
|
|
41
|
+
}
|
|
42
|
+
|
|
38
43
|
const entries = findEntries(workspaceRoot)
|
|
39
44
|
|
|
40
45
|
if (atWorkspaceRoot || wantAll) {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { ensureTmpSchemaVersion } from './tmp-schema-version.mjs'
|
|
5
|
+
import { workspaceProjectName, workspaceTmpTemplate } from './workspace-resolve.mjs'
|
|
6
|
+
|
|
7
|
+
export function ensureOuterWorkspaceTmp(workspaceRoot, { projectName } = {}) {
|
|
8
|
+
const resolved = path.resolve(workspaceRoot)
|
|
9
|
+
const tmpPath = path.join(resolved, 'tmp.yml')
|
|
10
|
+
let created = false
|
|
11
|
+
|
|
12
|
+
if (!fs.existsSync(tmpPath)) {
|
|
13
|
+
const name = projectName ?? workspaceProjectName(resolved)
|
|
14
|
+
fs.writeFileSync(tmpPath, workspaceTmpTemplate(name))
|
|
15
|
+
created = true
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const schema = ensureTmpSchemaVersion(tmpPath)
|
|
19
|
+
return { tmpFilePath: tmpPath, created, schema, workspaceRoot: resolved }
|
|
20
|
+
}
|