From c7ecb9606a14c42dd3134a16d8826354d30accde Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 1 Mar 2023 17:46:10 -0400 Subject: [PATCH 1/4] Hypothetical skeleton. --- assets/IslandoraStarterSite.php | 15 +++++++++++++++ composer.json | 10 ++++++++++ 2 files changed, 25 insertions(+) create mode 100644 assets/IslandoraStarterSite.php diff --git a/assets/IslandoraStarterSite.php b/assets/IslandoraStarterSite.php new file mode 100644 index 000000000..668005140 --- /dev/null +++ b/assets/IslandoraStarterSite.php @@ -0,0 +1,15 @@ +getComposer()->getPackage()->getPrettyVersion(); + var_dump($pretty_version); + } + +} diff --git a/composer.json b/composer.json index 5b83e6874..c86bfc7a5 100644 --- a/composer.json +++ b/composer.json @@ -127,5 +127,15 @@ "drupal/config_inspector": "^2.1", "drupal/devel": "^5.0", "drupal/restui": "^1.21" + }, + "scripts": { + "post-root-package-install": [ + "Islandora\\StarterSite::rootPackageInstall" + ] + }, + "autoload": { + "classmap": [ + "assets/IslandoraStarterSite.php" + ] } } From b25c0d45ded03b1b85f65fd879a06b700c9ee807 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 8 Mar 2023 16:01:49 -0400 Subject: [PATCH 2/4] Slight updates, and attempt. --- assets/IslandoraStarterSite.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/assets/IslandoraStarterSite.php b/assets/IslandoraStarterSite.php index 668005140..414a26be2 100644 --- a/assets/IslandoraStarterSite.php +++ b/assets/IslandoraStarterSite.php @@ -2,14 +2,32 @@ namespace Islandora; +use Composer\Json\JsonFile use Composer\Script\Event; use Composer\Util\Platform; +/** + * Starter Site Composer helper. + */ class StarterSite { + /** + * Root package installation event callback. + * + * Expected to be triggered on the `post-root-package-install` event, to track + * the version of the project from which a project was derived. + * + * @see https://getcomposer.org/doc/articles/scripts.md#event-names + */ public static function rootPackageInstall(Event $event) { - $pretty_version = $event->getComposer()->getPackage()->getPrettyVersion(); - var_dump($pretty_version); + $composer = $event->getComposer(); + $package = $composer->getPackage(); + $version_file = new JsonFile('.starter_site_version'); + $version_file->write([ + 'pretty-version' => $package->getPrettyVersion(), + 'version' => $package->getVersion(), + 'release-date' => $package->getReleaseDate(), + ]); } } From 2792b4f782b70e49fe7e267dd8d8715df9a7742d Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 8 Mar 2023 16:06:32 -0400 Subject: [PATCH 3/4] Syntax gaff. --- assets/IslandoraStarterSite.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/IslandoraStarterSite.php b/assets/IslandoraStarterSite.php index 414a26be2..60052167d 100644 --- a/assets/IslandoraStarterSite.php +++ b/assets/IslandoraStarterSite.php @@ -2,7 +2,7 @@ namespace Islandora; -use Composer\Json\JsonFile +use Composer\Json\JsonFile; use Composer\Script\Event; use Composer\Util\Platform; From 850bf6458335b8e16d783b033ac788a8b72e5f70 Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Wed, 8 Mar 2023 16:14:28 -0400 Subject: [PATCH 4/4] Dump more info, in various formats. --- assets/IslandoraStarterSite.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/assets/IslandoraStarterSite.php b/assets/IslandoraStarterSite.php index 60052167d..512290fc5 100644 --- a/assets/IslandoraStarterSite.php +++ b/assets/IslandoraStarterSite.php @@ -24,7 +24,11 @@ public static function rootPackageInstall(Event $event) { $package = $composer->getPackage(); $version_file = new JsonFile('.starter_site_version'); $version_file->write([ + 'package' => "$package", + 'full-pretty-version' => $package->getFullPrettyVersion(), + 'pretty-string' => $package->getPrettyString(), 'pretty-version' => $package->getPrettyVersion(), + 'unique-name' => $package->getUniqueName(), 'version' => $package->getVersion(), 'release-date' => $package->getReleaseDate(), ]);