Skip to content

Instantly share code, notes, and snippets.

@nfreear
Created December 18, 2017 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nfreear/5f6873a852519499bf0712cd63dd9353 to your computer and use it in GitHub Desktop.
Save nfreear/5f6873a852519499bf0712cd63dd9353 to your computer and use it in GitHub Desktop.
Composer-to-README commandline script
#!/usr/bin/env php
<?php
/**
* Composer-to-README commandline script (CLI).
*
* @copyright © Nick Freear, 18-Dec-2017.
*/
define( 'PATH', $argv[ $argc - 1 ]);
define( 'COMPOSER_JSON', PATH . '/composer.json' );
define( 'HAS_TRAVIS', file_exists( PATH . '/.travis.yml' ));
if ( ! file_exists( COMPOSER_JSON ) ) {
fwrite( STDERR, "Error, can't find file: " . COMPOSER_JSON . "\n" );
exit( 1 );
}
$composer_data = json_decode(file_get_contents( COMPOSER_JSON ));
echo readme_markdown( $composer_data );
// -----------------------------------------------------------
// License registry: https://spdx.org/licenses/
function readme_markdown( $data ) {
$year = date( 'Y' );
return <<<EOT
[![Build status — Travis-CI][travis-icon]][travis]
# $data->name
$data->description
* <$data->homepage>
## Support
* Code: [{$data->name}][gh]
* Docs: <{$data->support->docs}>
* Email: <{$data->support->email}>
## Install .. Test
```sh
composer install && composer npm-install
composer test
```
## License
License: [$data->license][]
---
© $year [The Open University][ou]. ([Institute of Educational Technology][iet])
[gh]: {$data->support->source} "The code on GitHub"
[docs]: {$data->support->docs}
[travis]: https://travis-ci.org/$data->name "Build status – Travis-CI (PHP)"
[travis-icon]: https://travis-ci.org/{$data->name}.svg?branch=master
[iet]: https://iet.open.ac.uk/
[ou]: http://www.open.ac.uk/ "©The Open University."
[proprietary]: http://www.open.ac.uk/copyright "©The Open University. All rights reserved."
[prop-00]: http://www.open.ac.uk/about/main/management/policies-and-statements/copyright-ou-websites
[gpl-3.0]: https://gnu.org/licenses/gpl.html "GNU General Public License 3.0"
[mit]: https://iet-ou.mit-license.org/ "MIT License"
[End]: //.
EOT;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment