clack-kit 0.0.1-beta.1
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 +161 -0
- package/dist/index.d.mts +2976 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +13343 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# clack-kit
|
|
2
|
+
|
|
3
|
+
`clack-kit` 是一个面向终端 workflow 的 TypeScript ESM 库
|
|
4
|
+
|
|
5
|
+
默认就是轻量模式,适合快速搭终端交互流程
|
|
6
|
+
|
|
7
|
+
需要历史记录、断点恢复、日志落盘时,再按需打开
|
|
8
|
+
|
|
9
|
+
## 它适合什么场景
|
|
10
|
+
|
|
11
|
+
- 把一整条终端流程写成可复用的 workflow
|
|
12
|
+
- 把 prompt、条件分支、命令执行放到同一条流程里
|
|
13
|
+
- 在交互步骤和 CLI 参数之间做映射
|
|
14
|
+
- 在需要的时候,再补上历史、checkpoint 和日志
|
|
15
|
+
|
|
16
|
+
## 默认行为
|
|
17
|
+
|
|
18
|
+
`clack-kit` 默认不会自动启用下面这三类持久化能力:
|
|
19
|
+
|
|
20
|
+
- 历史记录
|
|
21
|
+
- 断点恢复
|
|
22
|
+
- 日志保存
|
|
23
|
+
|
|
24
|
+
也就是说,不做额外配置时,它更像一个专门用来搭终端交互工作流的工具
|
|
25
|
+
|
|
26
|
+
只有显式开启时,才会写入 `.clack-kit/`
|
|
27
|
+
|
|
28
|
+
## 安装与开发
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
bun install
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
常用命令:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
bun run typecheck
|
|
38
|
+
bun run lint
|
|
39
|
+
CI=1 bun run test
|
|
40
|
+
bun run build
|
|
41
|
+
bun run docs:dev
|
|
42
|
+
bun run docs:build
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 先跑一个最小 workflow
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { defineStep, runWorkflowSafely } from 'clack-kit';
|
|
49
|
+
|
|
50
|
+
const result = await runWorkflowSafely({
|
|
51
|
+
id: 'hello-workflow',
|
|
52
|
+
steps: [
|
|
53
|
+
defineStep.text({
|
|
54
|
+
id: 'name',
|
|
55
|
+
message: '名字',
|
|
56
|
+
required: true,
|
|
57
|
+
}),
|
|
58
|
+
defineStep.autocomplete({
|
|
59
|
+
id: 'framework',
|
|
60
|
+
message: '框架',
|
|
61
|
+
options: ['react', 'vue', 'svelte'],
|
|
62
|
+
}),
|
|
63
|
+
],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (!result) return;
|
|
67
|
+
|
|
68
|
+
console.log(result.values.name);
|
|
69
|
+
console.log(result.values.framework);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
这个例子故意很短
|
|
73
|
+
|
|
74
|
+
先把交互流程跑通,抓住 `workflow -> steps -> result` 这条主线就够了
|
|
75
|
+
|
|
76
|
+
## 开启历史、断点和日志
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import {
|
|
80
|
+
createWorkflowKit,
|
|
81
|
+
defineStep,
|
|
82
|
+
defineSteps,
|
|
83
|
+
defineWorkflow,
|
|
84
|
+
} from 'clack-kit';
|
|
85
|
+
|
|
86
|
+
const kit = createWorkflowKit({
|
|
87
|
+
checkpoints: true,
|
|
88
|
+
history: true,
|
|
89
|
+
logs: true,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const workflow = defineWorkflow({
|
|
93
|
+
id: 'create-project',
|
|
94
|
+
intro: '创建项目',
|
|
95
|
+
log: {
|
|
96
|
+
completion: {
|
|
97
|
+
initialValue: true,
|
|
98
|
+
mode: 'confirm',
|
|
99
|
+
message: '保存这次运行日志吗?',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
steps: defineSteps([
|
|
103
|
+
defineStep.text({
|
|
104
|
+
id: 'name',
|
|
105
|
+
message: '项目名',
|
|
106
|
+
required: true,
|
|
107
|
+
}),
|
|
108
|
+
defineStep.confirm({
|
|
109
|
+
id: 'install',
|
|
110
|
+
message: '现在安装依赖吗?',
|
|
111
|
+
}),
|
|
112
|
+
]),
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const result = await kit.runSafely(workflow, {
|
|
116
|
+
checkpoint: {
|
|
117
|
+
resume: 'ask',
|
|
118
|
+
save: true,
|
|
119
|
+
},
|
|
120
|
+
history: {
|
|
121
|
+
reuse: 'ask',
|
|
122
|
+
saveSnapshot: true,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
if (!result) return;
|
|
127
|
+
|
|
128
|
+
console.log(result.savedLogPath);
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
这时候库才会开始保存快照、恢复中断流程、落盘运行日志
|
|
132
|
+
|
|
133
|
+
## 阅读顺序
|
|
134
|
+
|
|
135
|
+
第一次接触这个库时,建议按这个顺序看:
|
|
136
|
+
|
|
137
|
+
1. [`docs/getting-started.md`](./docs/getting-started.md)
|
|
138
|
+
2. [`docs/core-concepts.md`](./docs/core-concepts.md)
|
|
139
|
+
3. [`docs/examples.md`](./docs/examples.md)
|
|
140
|
+
4. [`docs/workflows.md`](./docs/workflows.md)
|
|
141
|
+
5. [`docs/commands.md`](./docs/commands.md)
|
|
142
|
+
6. [`docs/cli-integration.md`](./docs/cli-integration.md)
|
|
143
|
+
7. [`docs/persistence.md`](./docs/persistence.md)
|
|
144
|
+
8. [`docs/runtime-context.md`](./docs/runtime-context.md)
|
|
145
|
+
9. [`docs/api-reference.md`](./docs/api-reference.md)
|
|
146
|
+
10. [`docs/troubleshooting.md`](./docs/troubleshooting.md)
|
|
147
|
+
11. [`docs/architecture.md`](./docs/architecture.md)
|
|
148
|
+
|
|
149
|
+
想先看总览时,可直接从 [`docs/README.md`](./docs/README.md) 开始
|
|
150
|
+
|
|
151
|
+
## 示例
|
|
152
|
+
|
|
153
|
+
可直接查看 `examples/`,或者先读 [`examples/README.md`](./examples/README.md)
|
|
154
|
+
|
|
155
|
+
比较常用的几个示例:
|
|
156
|
+
|
|
157
|
+
- `examples/create-project.ts`
|
|
158
|
+
- `examples/command-modes.ts`
|
|
159
|
+
- `examples/release-workflow.ts`
|
|
160
|
+
- `examples/deploy-service.ts`
|
|
161
|
+
- `examples/incident-runbook.ts`
|