23

Scaffolding & Automated Delivery

⏱️ 15 min

Scaffolding & Automated Delivery

Script your common dev/release tasks, then combine AI to generate and maintain scaffolding. It cuts repetitive work dramatically.

Generating CLI / Script Skeletons

Generate a bash script `scripts/check.sh`:
- Run lint, typecheck, test in sequence
- Exit immediately on any failure and print the error
- Print elapsed time at the end

Have AI give you the structure first, then swap in your project-specific commands.

Code Templates & Scaffolding

  • Have AI generate templates for "new page / component / endpoint" (including tests, styles, types).
  • Put templates in scripts/generate-* and wire them up with npm run for quick creation.

CI/CD Integration

  • Ask AI for CI config snippets (e.g. GitHub Actions) covering caching, parallelism, and failure strategies.
  • Have it write "manual fallback steps" -- like a pre-release verification checklist.

Keeping Scripts Maintainable

  • Have AI add comments and usage docs inside scripts to avoid "black box" tooling.
  • Centralize important commands in package.json scripts or a Makefile for consistent access.

Exercise

Ask AI to generate a "new API module" scaffold for your project: controller / service / dto / tests / README. Then have it output a single npm command that generates the entire skeleton.

📚 相关资源

❓ 常见问题

关于本章主题最常被搜索的问题,点击展开答案

让 AI 写检查脚本 `scripts/check.sh` 必须有哪几样?

本章模板的硬要求:(1) 顺序执行 lint、typecheck、test;(2) 任一步失败立即退出并打印错误;(3) 最后输出耗时统计。先让 AI 给出结构,再根据项目实际命令替换 —— 比如 `npm run lint` vs `pnpm run lint`。结构对了再 swap 命令,比一次让 AI 猜全套要稳。

怎么用 AI 生成“新增页面/组件/接口”的脚手架模板?

让 AI 一次生成完整模板:含测试 + 样式 + 类型,不要分开。然后把模板放进 `scripts/generate-*`,配合 `npm run` 一行命令创建。这样团队新成员加 feature 不用每次手敲 8 个文件,也不会漏掉测试 —— 把脚手架沉到工具里,比写在 wiki 里靠“大家自觉”靠谱得多。

AI 生成 CI 配置要覆盖什么才算完整?

本章要求 4 件事:缓存、并行、失败策略,外加“人工兜底步骤”(比如发布前手动验证清单)。前三个是工程效率,最后一个是给关键发布留 safety net —— AI 写的 CI 经常忘记给人工 gate,全自动到底一旦出错就直接到生产。

怎么让 AI 写的脚本不变成“黑盒”?

两条习惯:(1) 让 AI 在脚本内加注释和用法说明 —— 至少有 `# Usage:` header;(2) 重要命令集中到 `package.json` 的 scripts 字段或 `Makefile`,让团队走统一入口而不是各自记 shell 命令。这两条做了,3 个月后回来读自己的脚本不会瞎,新人 onboard 也快。

“新增 API 模块”脚手架练习要交付什么?

本章练习给的清单:controller + service + dto + 测试 + README,5 件齐全。最后让 AI 输出“一条 `npm` 命令即可生成整套骨架”。验收点是这条命令能不能在干净 repo 里跑通生成完整可启动模块,不缺文件、不报 import 错。