@kevlns/u-cli-mod 0.2.0 → 0.2.2
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/AGENTS.md +2 -2
- package/README.md +2 -2
- package/dist/commands/exec.d.ts +14 -4
- package/dist/commands/exec.js +34 -14
- package/package.json +2 -2
package/AGENTS.md
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
6. `exec` 每次调用前都会重新校验 CLI 哈希(防篡改),属正常行为;校验失败按提示跑 `u-cli-mod cli install --force` 修复即可。
|
|
29
29
|
7. **读取 Editor 当前 Console 首选 `command read_console`**,`get_console_logs` 是兼容别名;`command console` 读取回调捕获流,适合 `since`/cursor 跟随,但不能代替原生 Console 快照。工具必须经 `command <名>` 调用。若实际 schema 中缺少 `read_console`,先检查 `doctor` 的 `patchVersion`/`installedPatchVersion` 和 `state`,不要将其误认成 `console` 的别名。
|
|
30
30
|
|
|
31
|
-
8.
|
|
31
|
+
8. **全量测试必须走 `--async_tests`**:Unity CLI 对同步命令有 30 秒硬性等待上限(`--timeout` 无法延长),同步 `run_tests` 全量必然超时且不入 `test_status` 跟踪。全量:`run_tests --mode EditMode --async_tests`(立即返回)→ 轮询 `test_status` 至 `completed` 拿完整 Summary;小范围用 `--filter` 缩到单命名空间/类,可直接同步等待拿 Summary。
|
|
32
32
|
## 典型流程
|
|
33
33
|
|
|
34
34
|
```bash
|
|
@@ -36,7 +36,7 @@ u-cli-mod doctor <project> # 1. 体检(只读)
|
|
|
36
36
|
u-cli-mod setup <project> # 2. 就绪(CLI + 适配包)
|
|
37
37
|
u-cli-mod exec <project> -- command editor_status # 3. 执行
|
|
38
38
|
u-cli-mod exec <project> -- command run_tests --mode EditMode --filter <命名空间或类名> # 小范围:同步返回 Summary
|
|
39
|
-
u-cli-mod exec <project> -- command run_tests --mode EditMode
|
|
39
|
+
u-cli-mod exec <project> -- command run_tests --mode EditMode --async_tests # 全量:立即返回,轮询 test_status
|
|
40
40
|
u-cli-mod exec <project> -- command read_console --types error,warning --count 100
|
|
41
41
|
```
|
|
42
42
|
|
package/README.md
CHANGED
|
@@ -123,7 +123,7 @@ npm run check # build + lint + vitest 测试 + pack guard
|
|
|
123
123
|
|
|
124
124
|
`pack:guard` 会执行真实 `npm pack`(含文件清单校验),断言发布包:
|
|
125
125
|
|
|
126
|
-
- 包名为 `@kevlns/u-cli-mod`,tgz 文件名精确为 `kevlns-u-cli-mod-0.2.
|
|
126
|
+
- 包名为 `@kevlns/u-cli-mod`,tgz 文件名精确为 `kevlns-u-cli-mod-0.2.1.tgz`(与 package.json 版本一致);
|
|
127
127
|
- `files` 必须包含 `v-cli.plugin.json`,且清单身份字段(schemaVersion/package/command/bin/platforms)与包一致;
|
|
128
128
|
- 不出现:
|
|
129
129
|
|
|
@@ -193,7 +193,7 @@ kevlns 工具家族共享同一套发布约定(tag 驱动、CI 护栏、MIT)
|
|
|
193
193
|
| --- | --- | --- |
|
|
194
194
|
| [`v-cli`](https://github.com/kevlns/v-cli) | 个人工具箱 CLI | v0.2.3 |
|
|
195
195
|
| [`xlmerge`](https://github.com/kevlns/xlmerge) | Git 中 .xlsx/.xlsm 冲突可视化解决工具 | v1.2.2 |
|
|
196
|
-
| [`u-cli-mod`](https://github.com/kevlns/u-cli-mod) | Unity 精确版本路由 + CLI + pipeline 包(Windows-first,本仓库) | v0.2.
|
|
196
|
+
| [`u-cli-mod`](https://github.com/kevlns/u-cli-mod) | Unity 精确版本路由 + CLI + pipeline 包(Windows-first,本仓库) | v0.2.1 |
|
|
197
197
|
|
|
198
198
|
## Compatibility
|
|
199
199
|
|
package/dist/commands/exec.d.ts
CHANGED
|
@@ -8,9 +8,10 @@ export declare function findProjectPathOverride(args: string[]): string | null;
|
|
|
8
8
|
export declare function buildExecArgs(cliArgs: string[], projectPath: string): string[];
|
|
9
9
|
/**
|
|
10
10
|
* Pipeline commands that block until the Editor-side work finishes.
|
|
11
|
-
* The routed Unity CLI caps that wait at 30s
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* The routed Unity CLI caps that wait at 30s (`--timeout` is not wired in the
|
|
12
|
+
* shipped build), so the wait budget belongs to this wrapper; full-suite run_tests
|
|
13
|
+
* must instead use the pipeline-side `--async_tests` flag (immediate return +
|
|
14
|
+
* `test_status` polling).
|
|
14
15
|
*/
|
|
15
16
|
export declare const LONG_RUNNING_PIPELINE_COMMANDS: ReadonlySet<string>;
|
|
16
17
|
/**
|
|
@@ -24,7 +25,7 @@ export declare function extractPipelineCommandName(cliArgs: string[]): string |
|
|
|
24
25
|
* Wait budget (ms) for the Unity CLI child process:
|
|
25
26
|
* - an explicit `--wait` wins (0 returns immediately);
|
|
26
27
|
* - long-running pipeline commands get a short budget so callers can poll status;
|
|
27
|
-
* - null means "wait synchronously for the CLI to finish"
|
|
28
|
+
* - null means "wait synchronously for the CLI to finish".
|
|
28
29
|
*/
|
|
29
30
|
export declare function resolveWaitMilliseconds(cliArgs: string[], explicitWaitSeconds?: number): number | null;
|
|
30
31
|
/**
|
|
@@ -39,6 +40,15 @@ export declare function extractWaitOption(args: string[]): {
|
|
|
39
40
|
};
|
|
40
41
|
/** Exec output log of a handed-back run: project-scoped, beside the install receipts. */
|
|
41
42
|
export declare function execLogPath(projectPath: string, commandName: string | null, now?: Date): string;
|
|
43
|
+
/**
|
|
44
|
+
* Command line for a handed-back exec, written into a temp .cmd batch: the batch
|
|
45
|
+
* owns the output redirection and is spawned as a single clean path argument, so
|
|
46
|
+
* the CLI outlives the wrapper process (numeric-fd stdio kills the detached child
|
|
47
|
+
* on Windows, and Node's quoting of an inline quoted command string breaks cmd).
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildDetachedExecCommand(cliPath: string, args: string[], logPath: string): string;
|
|
50
|
+
/** Temp batch path for a handed-back exec: wrapper plumbing, never project state. */
|
|
51
|
+
export declare function detachedExecBatchPath(logPath: string, tmpDir?: string): string;
|
|
42
52
|
export interface ExecOptions {
|
|
43
53
|
downloadIfMissing?: boolean;
|
|
44
54
|
waitSeconds?: number;
|
package/dist/commands/exec.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
-
import {
|
|
3
|
-
import { dirname, join } from 'node:path';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { basename, dirname, join } from 'node:path';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
4
5
|
import { readProjectInfo } from '../projectVersion.js';
|
|
5
6
|
import { resolveRouteForProject } from '../routes.js';
|
|
6
7
|
import { verifyCliBinary, ensureCliBinary } from '../ensure.js';
|
|
@@ -25,9 +26,10 @@ export function buildExecArgs(cliArgs, projectPath) {
|
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
28
|
* Pipeline commands that block until the Editor-side work finishes.
|
|
28
|
-
* The routed Unity CLI caps that wait at 30s
|
|
29
|
-
*
|
|
30
|
-
*
|
|
29
|
+
* The routed Unity CLI caps that wait at 30s (`--timeout` is not wired in the
|
|
30
|
+
* shipped build), so the wait budget belongs to this wrapper; full-suite run_tests
|
|
31
|
+
* must instead use the pipeline-side `--async_tests` flag (immediate return +
|
|
32
|
+
* `test_status` polling).
|
|
31
33
|
*/
|
|
32
34
|
export const LONG_RUNNING_PIPELINE_COMMANDS = new Set(['run_tests']);
|
|
33
35
|
/**
|
|
@@ -48,7 +50,7 @@ export function extractPipelineCommandName(cliArgs) {
|
|
|
48
50
|
* Wait budget (ms) for the Unity CLI child process:
|
|
49
51
|
* - an explicit `--wait` wins (0 returns immediately);
|
|
50
52
|
* - long-running pipeline commands get a short budget so callers can poll status;
|
|
51
|
-
* - null means "wait synchronously for the CLI to finish"
|
|
53
|
+
* - null means "wait synchronously for the CLI to finish".
|
|
52
54
|
*/
|
|
53
55
|
export function resolveWaitMilliseconds(cliArgs, explicitWaitSeconds) {
|
|
54
56
|
if (explicitWaitSeconds !== undefined) {
|
|
@@ -81,7 +83,7 @@ export function extractWaitOption(args) {
|
|
|
81
83
|
if (arg === undefined) {
|
|
82
84
|
continue;
|
|
83
85
|
}
|
|
84
|
-
if (arg === '--wait'
|
|
86
|
+
if (arg === '--wait') {
|
|
85
87
|
const value = args[i + 1];
|
|
86
88
|
if (value === undefined) {
|
|
87
89
|
throw new CliError('--wait 需要非负秒数。');
|
|
@@ -104,6 +106,25 @@ export function execLogPath(projectPath, commandName, now = new Date()) {
|
|
|
104
106
|
const suffix = commandName === null ? '' : `-${commandName}`;
|
|
105
107
|
return join(projectPath, 'Library', 'editor-pipeline-cli', 'exec-logs', `${stamp}${suffix}.log`);
|
|
106
108
|
}
|
|
109
|
+
/** Quotes one token for a cmd.exe command line; embedded quotes double up. */
|
|
110
|
+
function quoteForCmd(value) {
|
|
111
|
+
return `"${value.replace(/"/g, '""')}"`;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Command line for a handed-back exec, written into a temp .cmd batch: the batch
|
|
115
|
+
* owns the output redirection and is spawned as a single clean path argument, so
|
|
116
|
+
* the CLI outlives the wrapper process (numeric-fd stdio kills the detached child
|
|
117
|
+
* on Windows, and Node's quoting of an inline quoted command string breaks cmd).
|
|
118
|
+
*/
|
|
119
|
+
export function buildDetachedExecCommand(cliPath, args, logPath) {
|
|
120
|
+
const cli = `${quoteForCmd(cliPath)} ${args.map(quoteForCmd).join(' ')}`;
|
|
121
|
+
return `${cli} > ${quoteForCmd(logPath)} 2>&1`;
|
|
122
|
+
}
|
|
123
|
+
/** Temp batch path for a handed-back exec: wrapper plumbing, never project state. */
|
|
124
|
+
export function detachedExecBatchPath(logPath, tmpDir = tmpdir()) {
|
|
125
|
+
const base = basename(logPath).replace(/\.log$/, '.cmd');
|
|
126
|
+
return join(tmpDir, `u-cli-mod-exec-${base}`);
|
|
127
|
+
}
|
|
107
128
|
export async function runExec(projectPath, cliArgs, options = {}) {
|
|
108
129
|
const project = readProjectInfo(projectPath);
|
|
109
130
|
const route = resolveRouteForProject(project);
|
|
@@ -112,7 +133,6 @@ export async function runExec(projectPath, cliArgs, options = {}) {
|
|
|
112
133
|
throw new CliError(`exec 统一管理 --project-path,禁止在参数中覆盖目标工程:${override}`);
|
|
113
134
|
}
|
|
114
135
|
let cliPath = cliBinaryPath(route.cli);
|
|
115
|
-
const { existsSync } = await import('node:fs');
|
|
116
136
|
if (!existsSync(cliPath)) {
|
|
117
137
|
if (!options.downloadIfMissing) {
|
|
118
138
|
throw new CliError(`该路由的 CLI 尚未下载:${cliPath}。请先运行 "u-cli-mod cli install",或使用 --download-if-missing。`);
|
|
@@ -135,25 +155,25 @@ export async function runExec(projectPath, cliArgs, options = {}) {
|
|
|
135
155
|
}
|
|
136
156
|
/**
|
|
137
157
|
* Runs the CLI under a wait budget. When the budget expires the child keeps running
|
|
138
|
-
* (the
|
|
139
|
-
* with the output log path, so callers can poll the matching status command.
|
|
158
|
+
* (cmd owns the redirection, so the CLI survives the wrapper) and the wrapper hands
|
|
159
|
+
* control back with the output log path, so callers can poll the matching status command.
|
|
140
160
|
*/
|
|
141
161
|
async function runWithWaitBudget(cliPath, args, projectPath, waitMs, commandName) {
|
|
142
162
|
const logPath = execLogPath(projectPath, commandName);
|
|
143
163
|
mkdirSync(dirname(logPath), { recursive: true });
|
|
144
|
-
const
|
|
145
|
-
|
|
164
|
+
const batchPath = detachedExecBatchPath(logPath);
|
|
165
|
+
writeFileSync(batchPath, `@${buildDetachedExecCommand(cliPath, args, logPath)}\r\n`);
|
|
166
|
+
const child = spawn('cmd.exe', ['/d', '/c', batchPath], { stdio: 'ignore', windowsHide: true });
|
|
146
167
|
const spawnState = { error: null };
|
|
147
168
|
child.once('error', (error) => {
|
|
148
169
|
spawnState.error = error;
|
|
149
170
|
});
|
|
150
171
|
const finished = await waitForExit(child, waitMs);
|
|
151
|
-
closeSync(logFd);
|
|
152
172
|
if (finished) {
|
|
153
173
|
if (spawnState.error !== null) {
|
|
154
174
|
throw new CliError(`CLI 执行失败:${spawnState.error.message}`);
|
|
155
175
|
}
|
|
156
|
-
process.stdout.write(readFileSync(logPath, 'utf8'));
|
|
176
|
+
process.stdout.write(existsSync(logPath) ? readFileSync(logPath, 'utf8') : '');
|
|
157
177
|
return { exitCode: child.exitCode ?? 1 };
|
|
158
178
|
}
|
|
159
179
|
child.unref();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevlns/u-cli-mod",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "u-cli-mod: pin exact Unity Editor version routes and install the adapted com.unity.pipeline package for Unity 2022 (Windows-first). Downloads Unity assets at runtime into the user cache; the package itself contains no Unity binaries or package source. Not an official Unity project.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -68,4 +68,4 @@
|
|
|
68
68
|
"vitest": "^3.2.7"
|
|
69
69
|
},
|
|
70
70
|
"license": "MIT"
|
|
71
|
-
}
|
|
71
|
+
}
|