Communitygithub.com

ComeOnOliver/skillshub

验证环境变量和配置文件,确保所有必需设置都已记录。适用于处理 .env 文件、配置或部署设置时使用。

skillshub 是什么?

该技能是一个配置验证器,用于检查环境变量和配置文件的一致性与正确性,防止因缺失或错误的设置导致运行时错误。它支持多种配置文件格式(如 .env、config.js、settings.py 等),并提供详细的验证步骤:从查找配置文件、比较 .env.example 与 .env 的变量差异、验证变量格式(如引号、协议、布尔值类型),到运行时强制校验必需变量和类型检查。技能还包含安全性检查(如确保 .env 被 .gitignore 忽略、检测硬编码密钥)、环境特定配置管理、自动生成 .env.example 模板以及创建 CONFIG.md 文档的功能。它适用于所有主流平台(Node.js、Python 等),并提供了大量可操作的代码示例和最佳实践建议,帮助开发者在开发、部署和 CI/CD 流程中快速发现并修复配置问题。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/aiskillstore/marketplace/crazydubya/configuration-validator

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

配置验证器

验证配置文件和环境变量,防止运行时错误和缺失设置。

何时使用

  • 处理环境变量或配置文件时
  • 部署或配置问题
  • 用户提及“.env”、“config”、“环境变量”或“设置”

指令

1. 查找配置文件

搜索以下文件:

  • .env、.env.example、.env.local
  • config/、config.js、config.json
  • settings.py、application.yml
  • appsettings.json、.env.production

2. 检测缺失变量

比较 .env.example 与 .env:

# 在示例中存在但 .env 中缺失的变量
comm -23 <(grep -o '^[A-Z_]*' .env.example | sort) <(grep -o '^[A-Z_]*' .env | sort)

常见必需变量:

DATABASE_URL
API_KEY
SECRET_KEY
NODE_ENV
PORT

3. 验证变量格式

检查常见问题:

// 值中包含空格却缺少引号
DATABASE_URL=postgres://localhost/db name  // 错误
DATABASE_URL="postgres://localhost/db name"  // 正确

// 缺少协议
API_URL=example.com  // 错误
API_URL=https://example.com  // 正确

// 布尔值表示为字符串
DEBUG=true  // 可能被解释为字符串
DEBUG=1  // 更明确

4. 运行时验证必需变量

Node.js 示例:

const requiredEnvVars = [
  'DATABASE_URL',
  'API_KEY',
  'JWT_SECRET'
];

const missing = requiredEnvVars.filter(v => !process.env[v]);

if (missing.length > 0) {
  throw new Error(`缺少必需的环境变量: ${missing.join(', ')}`);
}

Python 示例:

import os

REQUIRED_ENV_VARS = [
    'DATABASE_URL',
    'SECRET_KEY',
    'ALLOWED_HOSTS'
]

missing = [var for var in REQUIRED_ENV_VARS if not os.getenv(var)]

if missing:
    raise EnvironmentError(f"缺少环境变量: {', '.join(missing)}")

5. 类型验证

验证类型:

const config = {
  port: parseInt(process.env.PORT || '3000', 10),
  debug: process.env.DEBUG === 'true',
  apiUrl: new URL(process.env.API_URL), // 无效时会抛出异常
  maxConnections: Number(process.env.MAX_CONNECTIONS),
};

// 验证
if (isNaN(config.port) || config.port < 1 || config.port > 65535) {
  throw new Error('PORT 必须是有效的端口号');
}

6. 生成 .env.example

从实际 .env 创建模板:

# 移除值,保留键名
sed 's/=.*/=/' .env > .env.example

或使用占位符:

DATABASE_URL=postgres://user:password@localhost:5432/dbname
API_KEY=your_api_key_here
SECRET_KEY=generate_random_secret
PORT=3000
NODE_ENV=development

7. 配置模式验证

定义模式(使用 Joi 示例):

const Joi = require('joi');

const envSchema = Joi.object({
  NODE_ENV: Joi.string()
    .valid('development', 'production', 'test')
    .required(),
  PORT: Joi.number()
    .port()
    .default(3000),
  DATABASE_URL: Joi.string()
    .uri()
    .required(),
  API_KEY: Joi.string()
    .min(32)
    .required(),
  DEBUG: Joi.boolean()
    .default(false),
}).unknown();

const { error, value } = envSchema.validate(process.env);

if (error) {
  throw new Error(`配置验证错误: ${error.message}`);
}

module.exports = value;

8. 安全检查

不要提交密钥:

# 检查 .env 是否被 .gitignore 忽略
if ! grep -q "^\.env$" .gitignore; then
  echo "警告:.env 未在 .gitignore 中"
fi

# 检查代码中硬编码的密钥
grep -r "api_key.*=.*['\"]" --exclude-dir=node_modules

常见安全问题:

  • 硬编码的密码/密钥
  • 生产环境中使用默认密钥
  • 暴露敏感配置
  • 未加密的密钥

9. 环境特定配置

按环境组织:

.env.development
.env.staging
.env.production
.env.test

正确加载:

require('dotenv').config({
  path: `.env.${process.env.NODE_ENV || 'development'}`
});

10. 记录所有变量

创建 CONFIG.md:

# 配置

## 环境变量

### 必需项

- `DATABASE_URL`:PostgreSQL 连接字符串
  - 格式:`postgres://user:pass@host:port/db`
  - 示例:`postgres://app:secret@localhost:5432/myapp`

- `API_KEY`:第三方 API 密钥
  - 获取地址:https://dashboard.example.com
  - 所需权限:读、写

### 可选项

- `PORT`:服务器端口(默认:3000)
- `DEBUG`:启用调试日志(默认:false)
- `MAX_CONNECTIONS`:数据库连接池大小(默认:10)

## 设置步骤

1. 将 `.env.example` 复制为 `.env`
2. 填写所有必需值
3. 运行 `npm run validate-config` 进行验证

11. 验证脚本

创建 scripts/validate-config.js:

const fs = require('fs');

function validateConfig() {
  const required = ['DATABASE_URL', 'API_KEY'];
  const missing = required.filter(v => !process.env[v]);

  if (missing.length > 0) {
    console.error(`❌ 缺失:${missing.join(', ')}`);
    process.exit(1);
  }

  console.log('✓ 所有必需配置变量均存在');
}

validateConfig();

12. 最佳实践

  • 切勿提交 .env:始终将其加入 .gitignore
  • 维护 .env.example:保持更新
  • 启动时验证:配置错误尽早失败
  • 使用合理的默认值:明智的回退方案
  • 全面记录:解释每个变量
  • 定期轮换密钥:定时更新密钥
  • 使用密钥管理工具:生产环境使用 Vault、AWS Secrets Manager 等
  • 类型检查:不仅检查存在性,还要验证类型

支持文件

  • templates/config-validator.js
  • templates/.env.example
  • scripts/generate-env-example.sh

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相关技能