hermes/dependencies
Hermes is a CLI dev tool that exports your project’s Composer and/or NPM dependencies to a markdown report. Run vendor/bin/hermes and use flags for composer, package, all, custom path, and configurable output location.
Installation:
composer require --dev hermes/dependencies
Ensure the package is added to require-dev in your composer.json.
First Run: Execute the CLI tool to generate a markdown file with dependencies:
vendor/bin/hermes -c
This generates a composer_dependencies.md file in the project root by default.
Quick Use Case: Generate a combined report for both Composer and NPM dependencies:
vendor/bin/hermes -a
Outputs dependencies.md with structured tables for both dependency types.
vendor/bin/hermes --help for available flags (-c, -p, -a, --path, --output).--path to target submodules or monorepo directories:
vendor/bin/hermes -c --path ./modules/api
post-install-cmd:
Add to your composer.json to generate dependency reports on install:
"scripts": {
"post-install-cmd": [
"@php vendor/bin/hermes -a --output=docs/dependencies.md"
]
}
docs/ folder and link it in your README.md:
## Dependencies
See [full dependency report](./docs/dependencies.md).
Dependency Audits:
vendor/bin/hermes -a before major releases to document dependencies.vendor/bin/hermes -a --output=docs/dependencies-v1.md
Monorepo Support:
vendor/bin/hermes -c --path ./packages/auth --output=packages/auth/dependencies.md
CI/CD Integration:
phpunit.xml or GitHub Actions to validate dependencies:
# .github/workflows/dependencies.yml
- name: Generate Dependencies Report
run: vendor/bin/hermes -a --output=docs/dependencies.md
Laravel Artisan Commands: Extend Hermes functionality by creating a custom Artisan command:
// app/Console/Commands/GenerateDependencies.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
class GenerateDependencies extends Command
{
protected $signature = 'dependencies:generate
{--type= : Type (composer|package|all)}
{--output= : Output path}';
public function handle()
{
$process = new Process(['vendor/bin/hermes', '-'.$this->option('type'), '--output='.$this->option('output')]);
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
$this->info('Dependencies report generated!');
}
}
Register in app/Console/Kernel.php:
protected $commands = [
Commands\GenerateDependencies::class,
];
Run with:
php artisan dependencies:generate --type=all --output=docs/report.md
Dynamic Documentation: Use Laravel’s Blade to embed dependency reports in admin panels:
// routes/web.php
Route::get('/admin/dependencies', function () {
return view('admin.dependencies', [
'composerDeps' => file_get_contents('docs/composer_dependencies.md'),
'npmDeps' => file_get_contents('docs/package_dependencies.md'),
]);
});
Dependency Version Tracking: Parse the markdown output in Laravel to track versions over time:
// app/Services/DependencyTracker.php
public function parseComposerDependencies(string $markdown): array
{
$dependencies = [];
preg_match_all('/\|([^\|]+)\|([^\|]+)\|([^\|]+)\|/', $markdown, $matches);
foreach ($matches[0] as $i => $row) {
$dependencies[$matches[1][$i]] = [
'version' => $matches[2][$i],
'license' => $matches[3][$i],
];
}
return $dependencies;
}
Missing package.json or composer.json:
- name: Generate Dependencies
run: |
if [ -f "composer.json" ]; then
vendor/bin/hermes -c --output=docs/composer.md
fi
if [ -f "package.json" ]; then
vendor/bin/hermes -p --output=docs/npm.md
fi
Output Overwrites:
composer_dependencies.md, package_dependencies.md) overwrite on each run. Use --output to avoid conflicts:
vendor/bin/hermes -a --output=docs/dependencies-$(date +%Y-%m-%d).md
NPM DevDependencies:
dependencies and devDependencies from package.json. Exclude dev dependencies by modifying the package’s logic or pre-processing package.json:
jq 'del(.devDependencies)' package.json > temp.json && vendor/bin/hermes -p --path=temp.json
Verbose Output:
error_log calls to the package’s src/Hermes.php.Path Issues:
--path fails, ensure the path is absolute or relative to the project root. Use pwd to verify:
cd /path/to/project && vendor/bin/hermes -c --path ./subdir
Permission Errors:
mkdir -p docs && chmod -R 777 docs
Custom Templates:
src/Templates/DependenciesTemplate.php). Fork the package or create a wrapper:
// app/Services/CustomHermes.php
use Hermes\Dependencies\Templates\DependenciesTemplate;
class CustomDependenciesTemplate extends DependenciesTemplate
{
public function renderComposer(array $dependencies): string
{
// Custom logic (e.g., add columns for security advisories)
return "```\n".implode("\n", $dependencies)."\n```";
}
}
Git Hooks:
pre-commit to track dependency changes:
# .git/hooks/pre-commit
#!/bin/sh
vendor/bin/hermes -a --output=docs/dependencies.md && git add docs/dependencies.md
Security Audits:
composer why-not or npm audit to flag vulnerable dependencies:
vendor/bin/hermes -c --output=docs/safe-deps.md && composer why-not --platform
Performance:
vendor/bin/hermes -a --output=docs/dependencies.md || true # Skip if fails
Local Development:
ln -s vendor/bin/hermes /usr/local/bin/hermes
hermes -c --path=/path/to/project
How can I help you explore Laravel packages today?