|
18 | 18 |
|
19 | 19 | class Installer {
|
20 | 20 |
|
| 21 | + protected static $installerInfo = array("projectInstall" => false, "packagesRemove" => false, "suggestedStarterKits" => array(), "configOverrides" => array(), "patternLabPackages" => array()); |
| 22 | + |
21 | 23 | /**
|
22 |
| - * Run the PL tasks when a package is installed |
| 24 | + * Get any config overrides that may exist for the edition |
23 | 25 | * @param {Object} a script event object from composer
|
24 | 26 | */
|
25 |
| - public static function postCreateProjectCmd(Event $event) { |
| 27 | + public static function getConfigOverrides(Event $event) { |
26 | 28 |
|
27 |
| - // make sure pattern lab has been loaded |
28 |
| - if (class_exists("\PatternLab\Config")) { |
29 |
| - |
30 |
| - InstallerUtil::postCreateProjectCmd($event); |
31 |
| - |
| 29 | + $extra = $event->getComposer()->getPackage()->getExtra(); |
| 30 | + if (isset($extra["patternlab"]) && isset($extra["patternlab"]["config"]) && is_array($extra["patternlab"]["config"])) { |
| 31 | + self::$installerInfo["configOverrides"] = $extra["patternlab"]["config"]; |
32 | 32 | }
|
33 | 33 |
|
34 | 34 | }
|
35 | 35 |
|
36 | 36 | /**
|
37 |
| - * Run the PL tasks when a package is installed |
| 37 | + * Get the package info from each patternlab-* package's composer.json |
| 38 | + * @param {String} the type of event fired during the composer install |
38 | 39 | * @param {Object} a script event object from composer
|
39 | 40 | */
|
40 |
| - public static function postPackageInstall(PackageEvent $event) { |
| 41 | + public static function getPackageInfo($type, $event) { |
41 | 42 |
|
42 |
| - // make sure pattern lab has been loaded |
43 |
| - if (class_exists("\PatternLab\Config")) { |
| 43 | + $package = ($type == "update") ? $event->getOperation()->getTargetPackage() : $event->getOperation()->getPackage(); |
| 44 | + $packageType = $package->getType(); |
| 45 | + $packageExtra = $package->getExtra(); |
| 46 | + $packageInfo = array(); |
| 47 | + |
| 48 | + // make sure we're only evaluating pattern lab packages |
| 49 | + if (strpos($packageType,"patternlab-") !== false) { |
| 50 | + |
| 51 | + $packageInfo["name"] = $package->getName(); |
| 52 | + $packageInfo["type"] = $packageType; |
| 53 | + $packageInfo["pathBase"] = $event->getComposer()->getInstallationManager()->getInstallPath($package); |
| 54 | + $packageInfo["pathDist"] = $packageInfo["pathBase"].DIRECTORY_SEPARATOR."dist".DIRECTORY_SEPARATOR; |
| 55 | + $packageInfo["extra"] = (isset($packageExtra["patternlab"])) ? $packageExtra["patternlab"] : array(); |
44 | 56 |
|
45 |
| - InstallerUtil::postPackageInstall($event); |
| 57 | + self::$installerInfo["packages"][] = $packageInfo; |
46 | 58 |
|
47 | 59 | }
|
48 | 60 |
|
49 | 61 | }
|
50 | 62 |
|
51 | 63 | /**
|
52 |
| - * Run the PL tasks when a package is updated |
| 64 | + * Get the suggested starter kits from the root package composer.json |
53 | 65 | * @param {Object} a script event object from composer
|
54 | 66 | */
|
55 |
| - public static function postPackageUpdate(PackageEvent $event) { |
| 67 | + public static function getSuggestedStarterKits(Event $event) { |
56 | 68 |
|
57 |
| - // make sure pattern lab has been loaded |
58 |
| - if (class_exists("\PatternLab\Config")) { |
59 |
| - |
60 |
| - InstallerUtil::postPackageUpdate($event); |
61 |
| - |
| 69 | + $extra = $event->getComposer()->getPackage()->getExtra(); |
| 70 | + if (isset($extra["patternlab"]) && isset($extra["patternlab"]["starterKitSuggestions"]) && is_array($extra["patternlab"]["starterKitSuggestions"])) { |
| 71 | + self::$installerInfo["suggestedStarterKits"] = $extra["patternlab"]["starterKitSuggestions"]; |
62 | 72 | }
|
63 | 73 |
|
64 | 74 | }
|
65 | 75 |
|
66 | 76 | /**
|
67 |
| - * Make sure certain things are set-up before running composer's install |
| 77 | + * Run the centralized postInstallCmd |
68 | 78 | * @param {Object} a script event object from composer
|
69 | 79 | */
|
70 |
| - public static function preInstallCmd(Event $event) { |
| 80 | + public static function postInstallCmd(Event $event) { |
71 | 81 |
|
72 |
| - // make sure pattern lab has been loaded |
73 |
| - if (class_exists("\PatternLab\Config")) { |
74 |
| - |
75 |
| - InstallerUtil::preInstallCmd($event); |
76 |
| - |
77 |
| - } |
| 82 | + InstallerUtil::postInstallCmd(self::$installerInfo, $event); |
| 83 | + |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Run the centralized postUpdateCmd |
| 88 | + * @param {Object} a script event object from composer |
| 89 | + */ |
| 90 | + public static function postUpdateCmd(Event $event) { |
| 91 | + |
| 92 | + InstallerUtil::postUpdateCmd(self::$installerInfo, $event); |
78 | 93 |
|
79 | 94 | }
|
80 | 95 |
|
81 | 96 | /**
|
82 |
| - * Run the PL tasks when a package is removed |
| 97 | + * Clean-up when a package is removed |
| 98 | + * @param {Object} a script event object from composer |
| 99 | + */ |
| 100 | + public static function postPackageInstall(PackageEvent $event) { |
| 101 | + |
| 102 | + self::getPackageInfo("install", $event); |
| 103 | + |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Clean-up when a package is removed |
| 108 | + * @param {Object} a script event object from composer |
| 109 | + */ |
| 110 | + public static function postPackageUpdate(PackageEvent $event) { |
| 111 | + |
| 112 | + self::getPackageInfo("update", $event); |
| 113 | + |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * Clean-up when a package is removed |
83 | 118 | * @param {Object} a script event object from composer
|
84 | 119 | */
|
85 | 120 | public static function prePackageUninstall(PackageEvent $event) {
|
86 | 121 |
|
87 |
| - // make sure pattern lab has been loaded |
88 |
| - if (class_exists("\PatternLab\Config")) { |
| 122 | + // make sure the postUpdateCmd doesnt actually do anything |
| 123 | + self::setPackagesRemove(); |
| 124 | + |
| 125 | + // get the basic package info |
| 126 | + $package = $event->getOperation()->getPackage(); |
| 127 | + $packageType = $package->getType(); |
| 128 | + $packageInfo = array(); |
| 129 | + |
| 130 | + // make sure we're only evaluating pattern lab packages. remove attributes related to them. |
| 131 | + if (strpos($packageType,"patternlab-") !== false) { |
| 132 | + |
| 133 | + $packageInfo["name"] = $package->getName(); |
| 134 | + $packageInfo["type"] = $packageType; |
| 135 | + $packageInfo["pathBase"] = $event->getComposer()->getInstallationManager()->getInstallPath($package); |
89 | 136 |
|
90 |
| - InstallerUtil::prePackageUninstallCmd($event); |
| 137 | + InstallerUtil::packageRemove($packageInfo); |
91 | 138 |
|
92 | 139 | }
|
93 | 140 |
|
94 | 141 | }
|
95 | 142 |
|
| 143 | + /** |
| 144 | + * Set the packages remove boolean to true |
| 145 | + */ |
| 146 | + public static function setPackagesRemove() { |
| 147 | + |
| 148 | + self::$installerInfo["packagesRemove"] = true; |
| 149 | + |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * Set the project install boolean to true |
| 154 | + * @param {Object} a script event object from composer |
| 155 | + */ |
| 156 | + public static function setProjectInstall(Event $event) { |
| 157 | + |
| 158 | + self::$installerInfo["projectInstall"] = true; |
| 159 | + |
| 160 | + } |
| 161 | + |
96 | 162 | }
|
0 commit comments