@ultime/cli 0.1.3 → 0.1.4
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/CHANGELOG.md +6 -0
- package/CONTRIBUTING.md +4 -1
- package/README.md +1 -1
- package/dist/index.d.ts +34 -0
- package/dist/index.js +4 -1
- package/package.json +21 -8
- package/src/args.ts +0 -50
- package/src/context.ts +0 -15
- package/src/index.ts +0 -3
- package/src/run.ts +0 -54
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.4 - 2026-11-10
|
|
4
|
+
|
|
5
|
+
- 构建改用 `vp pack`,产物同时生成 `dist/index.js` 与 `dist/index.d.ts`。
|
|
6
|
+
- `exports.types` 指向 `dist/index.d.ts`,包体不再包含 `src/`;安装后类型解析不依赖源码。
|
|
7
|
+
- 无运行时 API 变化。
|
|
8
|
+
|
|
3
9
|
## 0.1.3 - 2026-11-10
|
|
4
10
|
|
|
5
11
|
- 修复 `--key=value` 的值含等号时被截断:`--define=KEY=VALUE` 现在完整保留。
|
package/CONTRIBUTING.md
CHANGED
|
@@ -27,6 +27,8 @@
|
|
|
27
27
|
- **冗余**:同一事实只有一份正文;新增说明先改真源,其他位置只留指针。
|
|
28
28
|
- **缺漏**:新增能力是否有入口、示例与验证命令。
|
|
29
29
|
- **漂移**:`package.json` / README / `CHANGELOG` / VERSION(及适用的 AI 文档)版本是否一致。
|
|
30
|
+
- **包体**:`npm pack --dry-run` 不含 `tests` / `scripts` / `rules` / 包根 `AGENTS.md` / 构建配置 / lockfile;`exports` 与类型入口一致。
|
|
31
|
+
- **基线**:`engines.node >= 22.18`、产物 `target: node22` 未偏离;开发端脚本与依赖不进入发布包。
|
|
30
32
|
|
|
31
33
|
机械检查交给 CI;人审看架构、边界、语义与取舍。
|
|
32
34
|
|
|
@@ -35,7 +37,8 @@
|
|
|
35
37
|
```bash
|
|
36
38
|
pnpm check
|
|
37
39
|
pnpm test
|
|
38
|
-
pnpm
|
|
40
|
+
pnpm build # 含 publint / attw / unused
|
|
41
|
+
pnpm size # 体积只报告,不设门禁
|
|
39
42
|
npm pack --dry-run
|
|
40
43
|
```
|
|
41
44
|
|
package/README.md
CHANGED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* args.ts — 命令行参数解析(纯函数)
|
|
3
|
+
* ---------------------------------------------------------------------------
|
|
4
|
+
* 只认三种形态:`command`、`--flag`、`--key value` / `--key=value`;
|
|
5
|
+
* 不引第三方解析库 —— CLI 必须零依赖可跑。
|
|
6
|
+
*/
|
|
7
|
+
interface ParsedArgs {
|
|
8
|
+
command: string;
|
|
9
|
+
flags: Record<string, string | true>;
|
|
10
|
+
positional: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare function parseArgs(argv: string[]): ParsedArgs;
|
|
13
|
+
/** 命令上下文:把「往哪写、怎么写」抽出来,测试里换成内存收集器即可,不用起子进程。 */
|
|
14
|
+
interface CliContext {
|
|
15
|
+
/** 工作目录:配置与产物路径都相对它解析 */
|
|
16
|
+
cwd: string;
|
|
17
|
+
out: (line: string) => void;
|
|
18
|
+
err: (line: string) => void;
|
|
19
|
+
}
|
|
20
|
+
export declare function processContext(): CliContext;
|
|
21
|
+
interface CommandSpec {
|
|
22
|
+
/** 单条命令的 help;缺省时回落到全局 usage */
|
|
23
|
+
help?: string;
|
|
24
|
+
run: (args: ParsedArgs, ctx: CliContext) => number;
|
|
25
|
+
}
|
|
26
|
+
interface CliSpec {
|
|
27
|
+
/** 用于错误与帮助文案,例如 `ultime` */
|
|
28
|
+
name: string;
|
|
29
|
+
version: string;
|
|
30
|
+
usage: string;
|
|
31
|
+
commands: Record<string, CommandSpec>;
|
|
32
|
+
}
|
|
33
|
+
export declare function runCli(spec: CliSpec, argv: string[], ctx?: CliContext): number;
|
|
34
|
+
export type { CliContext, CliSpec, CommandSpec, ParsedArgs };
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,7 @@ function parseArgs(argv) {
|
|
|
36
36
|
positional
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
+
|
|
39
40
|
// src/context.ts
|
|
40
41
|
function processContext() {
|
|
41
42
|
return {
|
|
@@ -44,6 +45,7 @@ function processContext() {
|
|
|
44
45
|
err: (line) => console.error(line)
|
|
45
46
|
};
|
|
46
47
|
}
|
|
48
|
+
|
|
47
49
|
// src/run.ts
|
|
48
50
|
/**
|
|
49
51
|
* run.ts — 命令注册与退出码
|
|
@@ -78,4 +80,5 @@ function runCli(spec, argv, ctx = processContext()) {
|
|
|
78
80
|
return 1;
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
|
-
|
|
83
|
+
|
|
84
|
+
export { parseArgs, processContext, runCli };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultime/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Ultime · cli:通用命令行设施(参数 / 命令注册 / 上下文 / 退出码),零领域依赖",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"argument-parser",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"dist",
|
|
25
|
-
"src",
|
|
26
25
|
"README.md",
|
|
27
26
|
"llms.txt",
|
|
28
27
|
"SKILLS.md",
|
|
@@ -33,7 +32,7 @@
|
|
|
33
32
|
"type": "module",
|
|
34
33
|
"exports": {
|
|
35
34
|
".": {
|
|
36
|
-
"types": "./
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
37
36
|
"import": "./dist/index.js"
|
|
38
37
|
}
|
|
39
38
|
},
|
|
@@ -41,18 +40,32 @@
|
|
|
41
40
|
"access": "public"
|
|
42
41
|
},
|
|
43
42
|
"scripts": {
|
|
44
|
-
"build": "vp
|
|
45
|
-
"check": "vp check",
|
|
43
|
+
"build": "vp pack",
|
|
44
|
+
"check": "vp check && checks run && pnpm cycles",
|
|
45
|
+
"checks": "checks run",
|
|
46
|
+
"cycles": "vp lint --import-plugin --deny=import/no-cycle src",
|
|
46
47
|
"test": "vp test",
|
|
47
|
-
"
|
|
48
|
-
"prepublishOnly": "pnpm check && pnpm test && pnpm build"
|
|
48
|
+
"size": "size-limit --json",
|
|
49
|
+
"prepublishOnly": "pnpm check && pnpm test && pnpm build",
|
|
50
|
+
"prepare": "vp config --no-agent"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
53
|
+
"@arethetypeswrong/core": "^0.18.5",
|
|
54
|
+
"@size-limit/preset-small-lib": "^14.3.0",
|
|
51
55
|
"@types/node": "^22.20.5",
|
|
52
|
-
"
|
|
56
|
+
"@ultime/checks": "^0.2.0",
|
|
57
|
+
"publint": "^0.3.25",
|
|
58
|
+
"size-limit": "^14.3.0",
|
|
53
59
|
"typescript": "^5.9.3",
|
|
60
|
+
"unplugin-unused": "^0.6.0",
|
|
54
61
|
"vite-plus": "1.5.1"
|
|
55
62
|
},
|
|
63
|
+
"size-limit": [
|
|
64
|
+
{
|
|
65
|
+
"name": "@ultime/cli",
|
|
66
|
+
"path": "dist/index.js"
|
|
67
|
+
}
|
|
68
|
+
],
|
|
56
69
|
"engines": {
|
|
57
70
|
"node": ">=22.18"
|
|
58
71
|
},
|
package/src/args.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* args.ts — 命令行参数解析(纯函数)
|
|
3
|
-
* ---------------------------------------------------------------------------
|
|
4
|
-
* 只认三种形态:`command`、`--flag`、`--key value` / `--key=value`;
|
|
5
|
-
* 不引第三方解析库 —— CLI 必须零依赖可跑。
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export interface ParsedArgs {
|
|
9
|
-
command: string
|
|
10
|
-
flags: Record<string, string | true>
|
|
11
|
-
positional: string[]
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function parseArgs(argv: string[]): ParsedArgs {
|
|
15
|
-
const flags: Record<string, string | true> = {}
|
|
16
|
-
const positional: string[] = []
|
|
17
|
-
let command = ''
|
|
18
|
-
|
|
19
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
20
|
-
const token = argv[i]
|
|
21
|
-
if (token === '-h' || token === '--help') {
|
|
22
|
-
flags.help = true
|
|
23
|
-
continue
|
|
24
|
-
}
|
|
25
|
-
if (token === '-v' || token === '--version') {
|
|
26
|
-
flags.version = true
|
|
27
|
-
continue
|
|
28
|
-
}
|
|
29
|
-
if (token.startsWith('--')) {
|
|
30
|
-
const body = token.slice(2)
|
|
31
|
-
const equal = body.indexOf('=')
|
|
32
|
-
if (equal !== -1) {
|
|
33
|
-
flags[body.slice(0, equal)] = body.slice(equal + 1)
|
|
34
|
-
continue
|
|
35
|
-
}
|
|
36
|
-
const next = argv[i + 1]
|
|
37
|
-
if (next && !next.startsWith('-')) {
|
|
38
|
-
flags[body] = next
|
|
39
|
-
i += 1
|
|
40
|
-
} else {
|
|
41
|
-
flags[body] = true
|
|
42
|
-
}
|
|
43
|
-
continue
|
|
44
|
-
}
|
|
45
|
-
if (!command) command = token
|
|
46
|
-
else positional.push(token)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return { command, flags, positional }
|
|
50
|
-
}
|
package/src/context.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** 命令上下文:把「往哪写、怎么写」抽出来,测试里换成内存收集器即可,不用起子进程。 */
|
|
2
|
-
export interface CliContext {
|
|
3
|
-
/** 工作目录:配置与产物路径都相对它解析 */
|
|
4
|
-
cwd: string
|
|
5
|
-
out: (line: string) => void
|
|
6
|
-
err: (line: string) => void
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function processContext(): CliContext {
|
|
10
|
-
return {
|
|
11
|
-
cwd: process.cwd(),
|
|
12
|
-
out: (line) => console.log(line),
|
|
13
|
-
err: (line) => console.error(line),
|
|
14
|
-
}
|
|
15
|
-
}
|
package/src/index.ts
DELETED
package/src/run.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* run.ts — 命令注册与退出码
|
|
3
|
-
* ---------------------------------------------------------------------------
|
|
4
|
-
* 通用设施:只负责版本 / 帮助 / 未知命令 / 异常转退出码;
|
|
5
|
-
* 具体命令由调用方注册,cli 包不出现任何领域命令。
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { parseArgs, type ParsedArgs } from './args.ts'
|
|
9
|
-
import { processContext, type CliContext } from './context.ts'
|
|
10
|
-
|
|
11
|
-
export interface CommandSpec {
|
|
12
|
-
/** 单条命令的 help;缺省时回落到全局 usage */
|
|
13
|
-
help?: string
|
|
14
|
-
run: (args: ParsedArgs, ctx: CliContext) => number
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface CliSpec {
|
|
18
|
-
/** 用于错误与帮助文案,例如 `ultime` */
|
|
19
|
-
name: string
|
|
20
|
-
version: string
|
|
21
|
-
usage: string
|
|
22
|
-
commands: Record<string, CommandSpec>
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function runCli(spec: CliSpec, argv: string[], ctx: CliContext = processContext()): number {
|
|
26
|
-
const args = parseArgs(argv)
|
|
27
|
-
|
|
28
|
-
if (args.flags.version) {
|
|
29
|
-
ctx.out(spec.version)
|
|
30
|
-
return 0
|
|
31
|
-
}
|
|
32
|
-
if (args.flags.help) {
|
|
33
|
-
ctx.out(args.command && spec.commands[args.command]?.help ? spec.commands[args.command]!.help! : spec.usage)
|
|
34
|
-
return 0
|
|
35
|
-
}
|
|
36
|
-
if (!args.command) {
|
|
37
|
-
ctx.out(spec.usage)
|
|
38
|
-
return 1
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const command = spec.commands[args.command]
|
|
42
|
-
if (!command) {
|
|
43
|
-
ctx.err(`✗ 未知命令:${args.command}\n`)
|
|
44
|
-
ctx.out(spec.usage)
|
|
45
|
-
return 1
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
return command.run(args, ctx)
|
|
50
|
-
} catch (error) {
|
|
51
|
-
ctx.err(`✗ ${error instanceof Error ? error.message : String(error)}`)
|
|
52
|
-
return 1
|
|
53
|
-
}
|
|
54
|
-
}
|