diff --git a/composer.json b/composer.json index 356c195bfa..f5ee707263 100644 --- a/composer.json +++ b/composer.json @@ -65,7 +65,6 @@ "themes/custom/{$name}": ["type:drupal-custom-theme"] }, "drupal-core-project-message": { - "include-keys": ["homepage", "support"], "post-install-cmd-message": [ "drupal/drupal: This package is meant for core development,", " and not intended to be used for production sites.", diff --git a/composer/Plugin/ProjectMessage/Config.php b/composer/Plugin/ProjectMessage/Message.php similarity index 96% rename from composer/Plugin/ProjectMessage/Config.php rename to composer/Plugin/ProjectMessage/Message.php index 246f064d16..b0cea11b92 100644 --- a/composer/Plugin/ProjectMessage/Config.php +++ b/composer/Plugin/ProjectMessage/Message.php @@ -7,12 +7,12 @@ /** * Determine configuration. */ -class Config { +class Message { /** * The root package. * - * @var Composer\Package\RootPackageInterface + * @var \Composer\Package\RootPackageInterface */ protected $rootPackage; @@ -43,7 +43,7 @@ public function __construct(RootPackageInterface $root_package, $event_name) { $this->eventName = $event_name; } - public function getMessageText() { + public function getText() { if ($this->messageText) { return $this->messageText; } diff --git a/composer/Plugin/ProjectMessage/MessagePlugin.php b/composer/Plugin/ProjectMessage/MessagePlugin.php index 9eddeb41e7..5e4f6614a5 100644 --- a/composer/Plugin/ProjectMessage/MessagePlugin.php +++ b/composer/Plugin/ProjectMessage/MessagePlugin.php @@ -54,8 +54,8 @@ public static function getSubscribedEvents() { } public function displayPostCreateMessage(Event $event) { - $config = new Config($this->composer->getPackage(), $event->getName()); - if ($message = $config->getMessageText()) { + $message = new Message($this->composer->getPackage(), $event->getName()); + if ($message = $message->getText()) { $this->io->write($message); } } diff --git a/composer/Plugin/ProjectMessage/README.md b/composer/Plugin/ProjectMessage/README.md index 5ad8ec0b7a..cbfc4ca7cc 100644 --- a/composer/Plugin/ProjectMessage/README.md +++ b/composer/Plugin/ProjectMessage/README.md @@ -21,8 +21,9 @@ processes have finished. This is ideal for a 'next steps' type prompt to help get the user oriented. Currently only two Composer events are supported: -- post-create-project-cmd -- post-install-cmd +- post-create-project-cmd, when a `composer create-project` command has + finished. +- post-install-cmd, when a `composer install` command has finished. How do I set it up? ------------------- @@ -37,8 +38,8 @@ Require this Composer plugin in your project template composer.json file: There are three ways to configure this plugin to output information: - Using a text file. -- Embedding the information in the extra section of the composer.json file. - Using composer.json schema keys. +- Embedding the information in the extra section of the composer.json file. ### Using a text file @@ -62,11 +63,27 @@ composer.json file: } } +### Using composer.json schema keys + +You can tell the plugin to output the structured support information from the +composer.json file by telling it the keys you wish to display. + +Currently, only `name`, `description`, `homepage` and `support` are supported. + + "extra": { + "drupal-core-project-message": { + "include-keys": ["homepage", "support"], + } + } + +Then you can include this information in your composer.json file, which you +should probably be doing anyway. + ### Embedding the information in the extra section -In addition, you can specify text directly within the `extra` section by using -the `-message` key. This message should be an array for each line, so that -Composer can add the appropriate line ending character: +You can specify text directly within the `extra` section by using the +`[event-name]-message` key. This message should be an array, with one string for +each line: "extra": { "drupal-core-project-message": { @@ -77,16 +94,8 @@ Composer can add the appropriate line ending character: } } -The `-message` section will always override `-file` for a given event. - -### Using composer.json schema keys - -You can tell the plugin to output the structured support information from the composer.json file by telling it the keys you wish to display. - -Currently, only `homepage` and `support` are supported. +These strings should be plain text, with markup suitable for Symfony's +`OutputInterface::writeln()` method. See documentation here: +https://symfony.com/doc/3.4/console/coloring.html - "extra": { - "drupal-core-project-message": { - "include-keys": ["homepage", "support"], - } - } +The `-message` section will always override `-file` for a given event. diff --git a/core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php b/core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php index 3481fdfcdc..a9a8eff6f6 100644 --- a/core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php +++ b/core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php @@ -3,12 +3,12 @@ namespace Drupal\Tests\Composer\Plugin\ProjectMessage; use Composer\Package\RootPackageInterface; -use Drupal\Composer\Plugin\ProjectMessage\Config; +use Drupal\Composer\Plugin\ProjectMessage\Message; use PHPUnit\Framework\TestCase; use org\bovigo\vfs\vfsStream; /** - * @coversDefaultClass Drupal\Composer\Plugin\ProjectMessage\Config + * @coversDefaultClass Drupal\Composer\Plugin\ProjectMessage\Message * @group ProjectMessage */ class ConfigTest extends TestCase { @@ -55,7 +55,7 @@ public function provideGetMessageText() { /** * @dataProvider provideGetMessageText - * @covers ::getMessageText + * @covers ::getText */ public function testGetMessageText($expected, $config) { // Root package has our config. @@ -66,13 +66,13 @@ public function testGetMessageText($expected, $config) { ->method('getExtra') ->willReturn($config); - $config = new Config($root, 'event-name'); + $message = new Message($root, 'event-name'); - $this->assertSame($expected, $config->getMessageText()); + $this->assertSame($expected, $message->getText()); } /** - * @covers ::getMessageText + * @covers ::getText */ public function testDefaultFile() { // Root package has no extra field. @@ -85,16 +85,16 @@ public function testDefaultFile() { // The default is to try to read from event-name-message.txt, so we expect // config to try that. - $config = $this->getMockBuilder(Config::class) + $message = $this->getMockBuilder(Message::class) ->setConstructorArgs([$root, 'event-name']) ->setMethods(['getMessageFromFile']) ->getMock(); - $config->expects($this->once()) + $message->expects($this->once()) ->method('getMessageFromFile') ->with('event-name-message.txt') ->willReturn([]); - $this->assertSame([], $config->getMessageText()); + $this->assertSame([], $message->getText()); } }