承接 ruudk/readme-examples-sync-hook 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ruudk/readme-examples-sync-hook

Composer 安装命令:

composer require --dev ruudk/readme-examples-sync-hook

包简介

Automatically sync PHP code examples with readme file

关键字:

README 文档

README

A PHP script that automatically syncs code examples in your README.md with actual source files. This ensures your documentation always shows up-to-date, working code examples.

Installation

composer require --dev ruudk/readme-examples-sync-hook

Usage

Run the script from your project root:

vendor/bin/readme-examples-sync

Git Hook Integration

The easiest way to automatically sync your README on commit is using Lefthook:

  1. Install Lefthook (if not already installed):

    # macOS
    brew install lefthook
  2. Create a lefthook.yml file in your project root:

    pre-commit:
      parallel: false
      commands:
        sync-readme-examples:
          glob:
            - "*.php"
            - "*.md"
          run: vendor/bin/readme-examples-sync
          stage_fixed: true
  3. Install the hooks:

    lefthook install

That's it! Now your README will automatically sync whenever you commit changes to PHP or Markdown files.

Alternative: Manual Git Hook

If you prefer not to use Lefthook, you can manually create a .git/hooks/pre-commit file:

#!/bin/bash
vendor/bin/readme-examples-sync

Don't forget to make the hook executable:

chmod +x .git/hooks/pre-commit

How It Works

This script scans your README.md file for special HTML comments that mark code examples:

  1. Source code sync: Updates code blocks marked with <!-- source: ... --> with the actual content from source files
  2. Output sync (optional): When you add <!-- output: ... --> comments, the script executes PHP files and captures their output to display results

The script automatically stages the updated README.md if changes are detected (when run in a git repository), ensuring your documentation stays in sync with your code.

Syncing Source Code

To sync a code example with a source file, add a comment before your code block. The language identifier (e.g., php, graphql, javascript) is automatically inferred from the file extension:

<!-- source: examples/demo.php -->
```php
// This code will be replaced with content from examples/demo.php
```

The hook supports a wide range of file extensions including .php, .graphql, .gql, .js, .ts, .json, .yml, .yaml, .sql, and many more.

Syncing Output (Optional)

To show the output of executing a PHP file, use:

<!-- output: examples/demo.php -->
```php
// This will be replaced with the output from executing examples/demo.php
```

Example

Here's how it looks in practice: ruudk/code-generator.

💖 Support This Project

Love this tool? Help me keep building awesome open source software!

Sponsor

Your sponsorship helps me dedicate more time to maintaining and improving this project. Every contribution, no matter the size, makes a difference!

🤝 Contributing

I welcome contributions! Whether it's a bug fix, new feature, or documentation improvement, I'd love to see your PRs.

📄 License

MIT License – Free to use in your projects! If you're using this and finding value, please consider sponsoring to support continued development.

ruudk/readme-examples-sync-hook 适用场景与选型建议

ruudk/readme-examples-sync-hook 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 761 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 08 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「dev」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ruudk/readme-examples-sync-hook 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ruudk/readme-examples-sync-hook 我们能提供哪些服务?
定制开发 / 二次开发

基于 ruudk/readme-examples-sync-hook 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 761
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 16
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-13