I'm developing on (yet another) PHP project and I'm trying to create a nice "Donate" section in my README.md. I would like to mention sub-projects and their donate link in this README. Something really super-basic, but semi-automated.
I noticed that I can run this in Composer:
composer fund
But it generates a list of entries like this, friendly for the terminal, but unfriendly for a Markdown:
doctrine
inflector, lexer
.html
inflector
lexer
guzzlehttp
uri-template
...
Example Desired Result
This is an example of "minimum-viable-product" of "something visible in Markdown", obtained by just prepending each line with an asterisk (*
) so at least the links can be visited, and the contents are not collapsed in a single line:
doctrine
- inflector, lexer
- .html
- inflector
- lexer
- inflector, lexer
guzzlehttp
- uri-template
- uri-template
Again, not amazing but still something OK for me.
At the moment I'm using Composer 2.5.5 and i noticed that the command funds
has limited formats. Documentation on-board:
$ composer fund
Description:
Discover how to help fund the maintenance of your dependencies
Usage:
fund [options]
Options:
-f, --format=FORMAT Format of the output: text or json [default: "text"]
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
--profile Display timing and memory usage information
--no-plugins Whether to disable plugins.
--no-scripts Skips the execution of all scripts defined in composer.json file.
-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
--no-cache Prevent use of the cache
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
I was able to find the source code of the Fund workflow upstream:
.php
I also tried to understand how the JSON format was introduced, trying to understand if there is an hook or something:
Anyway this is the JSON format:
{
"guzzlehttp": {
";: [
"uri-template"
],
";: [
"uri-template"
],
";: [
"uri-template"
]
},
"doctrine": {
".html": [
"inflector",
"lexer"
],
";: [
"inflector",
"lexer"
],
";: [
"inflector"
],
";: [
"lexer"
]
},
...
Question
How do you put the "composer fund" information in your README in an "acceptable way"? Do you have a "Composer fund JSON" wrapper?
Apologies if this is a super-simple problem, but I just come up with solutions that are a little "hacky" and surely Stack Overflow may have a better opinion, to give proper credits to software dependencies. Thanks for sharing!
I'm developing on (yet another) PHP project and I'm trying to create a nice "Donate" section in my README.md. I would like to mention sub-projects and their donate link in this README. Something really super-basic, but semi-automated.
I noticed that I can run this in Composer:
composer fund
But it generates a list of entries like this, friendly for the terminal, but unfriendly for a Markdown:
doctrine
inflector, lexer
https://www.doctrine-project.org/sponsorship.html
https://www.patreon.com/phpdoctrine
inflector
https://tidelift.com/funding/github/packagist/doctrine%2Finflector
lexer
https://tidelift.com/funding/github/packagist/doctrine%2Flexer
guzzlehttp
uri-template
https://github.com/sponsors/GrahamCampbell
https://github.com/sponsors/Nyholm
https://tidelift.com/funding/github/packagist/guzzlehttp/uri-template
...
Example Desired Result
This is an example of "minimum-viable-product" of "something visible in Markdown", obtained by just prepending each line with an asterisk (*
) so at least the links can be visited, and the contents are not collapsed in a single line:
doctrine
- inflector, lexer
- https://www.doctrine-project.org/sponsorship.html https://www.patreon.com/phpdoctrine
- inflector
- https://tidelift.com/funding/github/packagist/doctrine%2Finflector
- lexer
- https://tidelift.com/funding/github/packagist/doctrine%2Flexer
- inflector, lexer
guzzlehttp
- uri-template
- https://github.com/sponsors/GrahamCampbell https://github.com/sponsors/Nyholm https://tidelift.com/funding/github/packagist/guzzlehttp/uri-template
- uri-template
Again, not amazing but still something OK for me.
At the moment I'm using Composer 2.5.5 and i noticed that the command funds
has limited formats. Documentation on-board:
$ composer fund
Description:
Discover how to help fund the maintenance of your dependencies
Usage:
fund [options]
Options:
-f, --format=FORMAT Format of the output: text or json [default: "text"]
-h, --help Display help for the given command. When no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
--profile Display timing and memory usage information
--no-plugins Whether to disable plugins.
--no-scripts Skips the execution of all scripts defined in composer.json file.
-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
--no-cache Prevent use of the cache
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
I was able to find the source code of the Fund workflow upstream:
https://github.com/composer/composer/blob/main/src/Composer/Command/FundCommand.php
I also tried to understand how the JSON format was introduced, trying to understand if there is an hook or something:
https://github.com/composer/composer/commit/91b6ff27ac92a9b9e1b6c96949e9e8db50cddc78
Anyway this is the JSON format:
{
"guzzlehttp": {
"https://github.com/sponsors/GrahamCampbell": [
"uri-template"
],
"https://github.com/sponsors/Nyholm": [
"uri-template"
],
"https://tidelift.com/funding/github/packagist/guzzlehttp/uri-template": [
"uri-template"
]
},
"doctrine": {
"https://www.doctrine-project.org/sponsorship.html": [
"inflector",
"lexer"
],
"https://www.patreon.com/phpdoctrine": [
"inflector",
"lexer"
],
"https://tidelift.com/funding/github/packagist/doctrine%2Finflector": [
"inflector"
],
"https://tidelift.com/funding/github/packagist/doctrine%2Flexer": [
"lexer"
]
},
...
Question
How do you put the "composer fund" information in your README in an "acceptable way"? Do you have a "Composer fund JSON" wrapper?
Apologies if this is a super-simple problem, but I just come up with solutions that are a little "hacky" and surely Stack Overflow may have a better opinion, to give proper credits to software dependencies. Thanks for sharing!
Share Improve this question asked 5 hours ago Valerio BozzValerio Bozz 1,46622 silver badges36 bronze badges1 Answer
Reset to default 0You can generate your credits by creating this file somewhere on your computer:
generate-md-credits.php
:
<?php
// Take in input the "composer fund --format=json" and generate
// a simple list of donations link in Markdown.
$stdin = file_get_contents('php://stdin', 'r');
$entries = json_decode($stdin);
foreach ($entries as $entry => $links) {
foreach ($links as $link => $deps) {
foreach ($deps as $dep) {
echo "* [Donate to **$entry - $dep**]($link)\n";
}
}
}
Then using this command from your command line:
composer fund --format=json | php generate-md-credits.php
(If you are not in GNU/Linux or similar environments, please add a comment to share how you do this in one command...)
It generates something like this this (rendered in Markdown):
- Donate to doctrine - inflector
- Donate to doctrine - lexer
- Donate to doctrine - inflector
- Donate to doctrine - lexer
- Donate to doctrine - inflector
- Donate to doctrine - lexer
- Donate to guzzlehttp - uri-template
- Donate to guzzlehttp - uri-template
- Donate to guzzlehttp - uri-template
So the script easily generates some Markdown, and from time to time you can easily update your README. You can also automate this a bit more, but it's still something.
I'm glad to see more solutions thought. Thanks for sharing.