Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Commit 02a05bc

Browse files
committed
updating for v2.0.0 release
1 parent 744a18b commit 02a05bc

File tree

2 files changed

+107
-37
lines changed

2 files changed

+107
-37
lines changed

composer.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,30 @@
2424
}
2525
},
2626
"minimum-stability": "dev",
27-
"prefer-stable": true,
2827
"require": {
2928
"php": ">=5.3.6",
3029
"pattern-lab/core": "dev-dev",
3130
"pattern-lab/patternengine-twig": "dev-dev",
3231
"pattern-lab/styleguidekit-twig-default": "dev-dev"
3332
},
3433
"scripts": {
35-
"post-create-project-cmd": [
36-
"PatternLab\\Installer::postCreateProjectCmd"
34+
"post-install-cmd": [
35+
"PatternLab\\Installer::postInstallCmd"
36+
],
37+
"post-update-cmd": [
38+
"PatternLab\\Installer::postUpdateCmd"
39+
],
40+
"post-root-package-install": [
41+
"PatternLab\\Installer::setProjectInstall",
42+
"PatternLab\\Installer::getSuggestedStarterKits",
43+
"PatternLab\\Installer::getConfigOverrides"
3744
],
3845
"post-package-install": [
3946
"PatternLab\\Installer::postPackageInstall"
4047
],
4148
"post-package-update": [
4249
"PatternLab\\Installer::postPackageUpdate"
4350
],
44-
"pre-install-cmd": [
45-
"PatternLab\\Installer::preInstallCmd"
46-
],
4751
"pre-package-uninstall": [
4852
"PatternLab\\Installer::prePackageUninstall"
4953
]

core/src/PatternLab/Installer.php

Lines changed: 97 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,79 +18,145 @@
1818

1919
class Installer {
2020

21+
protected static $installerInfo = array("projectInstall" => false, "packagesRemove" => false, "suggestedStarterKits" => array(), "configOverrides" => array(), "patternLabPackages" => array());
22+
2123
/**
22-
* Run the PL tasks when a package is installed
24+
* Get any config overrides that may exist for the edition
2325
* @param {Object} a script event object from composer
2426
*/
25-
public static function postCreateProjectCmd(Event $event) {
27+
public static function getConfigOverrides(Event $event) {
2628

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"];
3232
}
3333

3434
}
3535

3636
/**
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
3839
* @param {Object} a script event object from composer
3940
*/
40-
public static function postPackageInstall(PackageEvent $event) {
41+
public static function getPackageInfo($type, $event) {
4142

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();
4456

45-
InstallerUtil::postPackageInstall($event);
57+
self::$installerInfo["packages"][] = $packageInfo;
4658

4759
}
4860

4961
}
5062

5163
/**
52-
* Run the PL tasks when a package is updated
64+
* Get the suggested starter kits from the root package composer.json
5365
* @param {Object} a script event object from composer
5466
*/
55-
public static function postPackageUpdate(PackageEvent $event) {
67+
public static function getSuggestedStarterKits(Event $event) {
5668

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"];
6272
}
6373

6474
}
6575

6676
/**
67-
* Make sure certain things are set-up before running composer's install
77+
* Run the centralized postInstallCmd
6878
* @param {Object} a script event object from composer
6979
*/
70-
public static function preInstallCmd(Event $event) {
80+
public static function postInstallCmd(Event $event) {
7181

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);
7893

7994
}
8095

8196
/**
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
83118
* @param {Object} a script event object from composer
84119
*/
85120
public static function prePackageUninstall(PackageEvent $event) {
86121

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);
89136

90-
InstallerUtil::prePackageUninstallCmd($event);
137+
InstallerUtil::packageRemove($packageInfo);
91138

92139
}
93140

94141
}
95142

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+
96162
}

0 commit comments

Comments
 (0)