Replace the old exercise files (challenges, maze, sandbox, etc.) with a runnable order/inventory TypeScript app under training/ that ships with unit tests, typecheck, lint, and format scripts. Merge the full task checklist from TRAINING.md into README.md and drop the obsolete docs and challenge files. Add a root .gitignore for .zed, .reasonix, and build artifacts, untrack the previously committed local configs, and fix the root tsconfig to point at the new training sources.
56 lines
2.5 KiB
Markdown
56 lines
2.5 KiB
Markdown
# 🎯 training —— VIMX 训练工程(模块化 TS 小应用)
|
||
|
||
一个模块化、互相调用、可运行的“订单/库存”应用。根目录 `README.md` 里的每一项训练,
|
||
**都直接在这个应用的真实代码、测试与调试上进行**,不再另设练习文件。
|
||
|
||
## 工程结构
|
||
|
||
```
|
||
training/
|
||
├── package.json start / test / typecheck / lint / format
|
||
├── tsconfig.json 类型检查(src + tests)
|
||
├── eslint.config.js ESLint 9(只检查 src/ 与 tests/)
|
||
├── .prettierrc.json
|
||
├── src/ 应用(互相调用)
|
||
│ ├── cli.ts 命令行入口(list/order/ship/report/demo/stock)
|
||
│ ├── config.ts 税率 / 折扣 / 运费阈值
|
||
│ ├── catalog.ts 商品目录(数据 + findProduct)
|
||
│ ├── pricing.ts 计价 lineTotal / 运费 shippingCost
|
||
│ ├── inventory.ts 库存 reserve / release / available
|
||
│ ├── orders.ts 订单 createOrder(聚合调用上面三者)
|
||
│ ├── reporting.ts 报表(跨模块只读统计)
|
||
│ └── receipt.ts class Receipt(类练习目标)
|
||
└── tests/ vitest 单元测试(每个领域模块一个文件)
|
||
```
|
||
|
||
## 常用命令
|
||
|
||
```sh
|
||
npm install
|
||
npm run start -- list # 商品目录
|
||
npm run start -- order apple 3 milk 1 # 下一单
|
||
npm run start -- demo # 两单+发货+报表
|
||
npm run test # 单元测试(当前 13 个)
|
||
npm run typecheck # tsc 严格模式
|
||
npm run lint # ESLint
|
||
npm run format # Prettier
|
||
```
|
||
|
||
## 调试
|
||
|
||
在 Zed 中按 `f4`(`debugger: start`)会自动列出:package.json 的 `start` 脚本、
|
||
每个 vitest 用例,直接选目标打断点即可(TypeScript 由内置 js-debug 支持)。
|
||
|
||
推荐调试练习:
|
||
|
||
- `src/orders.ts` 的 `createOrder` 打断点,跑一个 `tests/orders.test.ts`,单步看
|
||
`subtotal → tax → shipping → total`;
|
||
- `src/reporting.ts` 打断点跑 `start`(参数 `demo`),看跨模块调用栈;
|
||
- 故意改坏一个常量让 `npm test` 变红,再用断点/单步把它找回来——这就是“调试训练”。
|
||
|
||
## 任务清单怎么用
|
||
|
||
训练任务全在根目录 `README.md` 里,每条都标注了“在哪练”:打开对应 `src/` 或
|
||
`tests/` 文件,按任务里列的按键操作。改动只是为了练习的话,`:q!` 退出不保存即可;
|
||
改坏了也能用 `npm run test` 立刻发现。
|