关于 dev
dev 是面向 WordPress ActivityPub 插件的开发工作流技能,为开发者提供环境管理、测试、代码检查和构建的命令参考。它还涵盖调试、覆盖率及提交前流程。
主要功能
- 01WordPress 环境启动与停止
- 02PHP 与端到端测试命令
- 03PHP、JavaScript 和 CSS 检查
- 04资源构建与开发监听
- 05测试覆盖率和调试参考
- 06自动化提交钩子说明
适用场景
- 01启动本地 WordPress 开发环境
- 02运行指定测试或完整测试套件
- 03检查代码风格并构建资源
- 04排查失败测试并准备提交
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ automattic/ wordpress-activitypub --skill dev安装后在 Claude Code 中输入/dev确认已加载。
详细介绍
ActivityPub 开发周期
WordPress ActivityPub 插件常用开发工作流速查。
速查
环境管理
npm run env-start # Start WordPress at http://localhost:8888.
npm run env-stop # Stop WordPress environment.
测试命令
npm run env-test # Run all PHP tests.
npm run env-test -- --filter=pattern # Run tests matching pattern.
npm run env-test -- path/to/test.php # Run specific test file.
npm run env-test -- --group=name # Run tests with @group annotation.
npm run test:e2e # Run Playwright E2E tests.
npm run test:e2e:debug # Debug E2E tests.
代码质量
composer lint # Check PHP coding standards.
composer lint:fix # Auto-fix PHP issues.
npm run lint:js # Check JavaScript.
npm run lint:css # Check CSS styles.
npm run format # Format all code (wp-scripts).
构建资源
npm run build # Build for production (formatted and minified).
npm run dev # Start development watch mode.
代码覆盖率
npm run env-start -- --xdebug=coverage # Start with coverage support.
npm run env-test -- --coverage-text # Generate text coverage report.
npm run env-test -- --coverage-html ./coverage # Generate HTML report.
详细文档
请参阅 docs/development-environment.md,了解详细的设置说明。
请参阅 tests/README.md,了解全面的测试指南。
请参阅 docs/code-linting.md,了解代码检查配置和规范。
提交前钩子
该代码库使用自动化提交前钩子(.githooks/pre-commit),在执行 git commit 时自动运行:
- 整理 PHP 导入 - 自动整理 use 语句。
- 检查未使用的导入 - 防止出现未使用的 use 语句。
- 验证测试模式 - 阻止使用
remove_all_filters('pre_http_request')。 - 运行 PHPCS 自动修复 - 自动应用编码规范。
- 格式化 JavaScript - 运行 wp-scripts 格式化程序。
重要: 钩子会自动修改已暂存的文件。提交前务必检查更改。如果钩子进行了修改,必须重新暂存这些文件并再次提交。
设置: 钩子由 npm run prepare 安装(在 npm install 后自动运行)。
常见开发工作流
初始设置
git clone [email protected]:Automattic/wordpress-activitypub.git
cd wordpress-activitypub
npm install # Also runs 'npm run prepare' to install hooks.
composer install
npm run env-start # WordPress at http://localhost:8888.
更改工作流
# 1. Make code changes.
# 2. Run relevant tests.
npm run env-test -- --filter=FeatureName
# 3. Check code quality (optional - pre-commit hook does this).
composer lint
npm run lint:js
# 4. Commit (pre-commit hook runs automatically).
git add .
git commit -m "Description"
# Hook may modify files - review and stage again if needed.
当管理应用从某个 @wordpress/* 包导入内容,而构建过程将该包外部化为 wp.* 全局变量时,请根据插件最低支持的 WordPress 版本中实际提供的内容检查导出项(查看 wp-includes/js/dist/<package>.js,或在浏览器中检查 typeof wp.<package>.<name>),而不是检查 node_modules。较新的 npm 版本导出的名称可能并不存在于实际提供的全局变量中。
创建 PR 前
# Run full test suite.
npm run env-test
# Build assets.
npm run build
# Final lint check.
composer lint
npm run lint:js
调试失败的测试
# Run with verbose output.
npm run env-test -- --verbose --filter=test_name
# Run single test file to isolate issue.
npm run env-test -- tests/phpunit/tests/path/to/test.php
# Check test groups.
npm run env-test -- --list-groups
npm run env-test -- --group=specific_group
全新环境
npm run env-stop
npm run env-start
# wp-env automatically sets up WordPress with debug mode and test users.
关键文件
package.json- npm 脚本和依赖项。composer.json- PHP 依赖项和代码检查脚本。.wp-env.json- wp-env 配置。phpcs.xml- PHP 编码规范(自定义 WordPress 规则)。.githooks/pre-commit- 提交前自动化。
评论
支持 Markdown