zod-env-integration
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseZod 环境变量集成
Zod Environment Variable Integration
提供生成基于 Zod 验证的类型安全环境变量管理代码的指导和模板。包含创建 schema、getter 函数和桶导出的示例和最佳实践。
Provides guidance and templates for generating type-safe environment variable management code based on Zod validation. Includes examples and best practices for creating schemas, getter functions, and barrel exports.
工作原理
How It Works
- 在项目根目录准备 .env.example 文件
- 严格参照 best-practice-examples/ 中的代码结构和模式
- 对于单环境:生成 包含 schema、getter 和导出
integrations/env/ - 对于多环境:为每个环境生成独立的 目录
integrations/{env}-env/ - 按照代码生成指南创建 Zod schema
- 实现带有适当错误处理的 getter 函数
- 创建桶导出以实现干净的导入
- 在应用程序中使用生成的代码
- Prepare a .env.example file in the project root directory
- Strictly follow the code structure and patterns in best-practice-examples/
- For single environment: Generate containing schema, getter, and exports
integrations/env/ - For multiple environments: Generate independent directories for each environment
integrations/{env}-env/ - Create Zod schemas according to the code generation guidelines
- Implement getter functions with appropriate error handling
- Create barrel exports for clean imports
- Use the generated code in your application
使用方法
Usage
此技能提供文档和示例。按照参考指南中的步骤操作:
- 单环境代码生成指南 - 单环境代码生成的详细规则
- 多环境代码生成指南 - 多环境代码生成的详细规则
- .env.example 模板 - .env 文件的模板
- 最佳实践示例 - 必须严格参照的单环境和多环境代码示例
重要: 实现时必须严格遵循 best-practice-examples 中的代码结构、命名约定和错误处理模式。任何修改都可能破坏类型安全保证。
This skill provides documentation and examples. Follow the steps in the reference guides:
- Single Environment Code Generation Guide - Detailed rules for single environment code generation
- Multiple Environments Code Generation Guide - Detailed rules for multiple environments code generation
- .env.example Template - Template for .env files
- Best Practice Examples - Must strictly follow single and multiple environment code examples
Important: When implementing, you must strictly follow the code structure, naming conventions, and error handling patterns in best-practice-examples. Any modifications may break the type safety guarantees.
故障排除
Troubleshooting
- 缺少 .env.example:从 references/.env.example.template 复制模板
- 未安装 Zod:在项目中运行
pnpm install zod - 类型错误:检查代码生成指南中的正确 schema 语法
- 导入错误:确保 index.ts 中的桶导出正确
- 偏离最佳实践:如果遇到问题,首先确认代码结构是否严格遵循 best-practice-examples 中的模式
- Missing .env.example: Copy the template from references/.env.example.template
- Zod Not Installed: Run in your project
pnpm install zod - Type Errors: Check the correct schema syntax in the code generation guides
- Import Errors: Ensure the barrel exports in index.ts are correct
- Deviation from Best Practices: If you encounter issues, first confirm whether the code structure strictly follows the patterns in best-practice-examples