用途:为指定项目($1,packages/<domain>/ 下的相对路径)统一凭据处理方式,避免 WiFi 密码、API Key 等敏感信息被提交到仓库。
主要能力:按项目类型套用标准模式。ESP-IDF 项目使用 credentials.h 配合 credentials.h.example,示例文件由 credentials.h.example 复制为 credentials.h 后填写;ESPHome 项目使用 secrets.yaml 配合 secrets.yaml.example,字段含 wifi_ssid、wifi_password、api_encryption_key、ota_password。
使用方式:先通过 CMakeLists.txt 与 .yaml 配置判断项目类型;扫描源码中的凭据引用(如 #include "credentials.h"、#include "secrets.h"、#include "wifi_config.h",以及 WIFI_SSID、WIFI_PASSWORD、API_KEY 等宏);检查是否已有 .example 文件、凭据文件是否被 gitignore、pre-commit 钩子是否提供保护。对不合规命名进行迁移:wifi_config.h、secrets.h、credentials.h.template 统一改名为 credentials.h,对应示例文件改为 credentials.h.example,并同步更新源码中的 #include 语句。最后确认 .gitignore 覆盖 credentials.h 与 secrets.yaml,根目录 .pre-commit-config.yaml 能拦截凭据文件。
输出:报告检测到的凭据模式、重命名或新建的文件、.gitignore 状态、pre-commit 保护状态,以及被更新的源文件。
限制:资料未提供具体安装命令、运行入口、计费方式或兼容平台范围,这些暂未提供;实际执行需结合项目现有结构。