forked from pattern-lab/patternlab-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstaller.php
More file actions
162 lines (117 loc) · 4.94 KB
/
Installer.php
File metadata and controls
162 lines (117 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/*!
* Installer Class
*
* Copyright (c) 2016 Dave Olsen, http://dmolsen.com
* Licensed under the MIT license
*
* References the InstallerUtil class that is included in pattern-lab/core
*
*/
namespace PatternLab;
use \Composer\Script\Event;
use \Composer\Installer\PackageEvent;
use \PatternLab\InstallerUtil;
class Installer {
protected static $installerInfo = array("projectInstall" => false, "packagesRemove" => false, "suggestedStarterKits" => array(), "configOverrides" => array(), "patternLabPackages" => array());
/**
* Get any config overrides that may exist for the edition
* @param {Object} a script event object from composer
*/
public static function getConfigOverrides(Event $event) {
$extra = $event->getComposer()->getPackage()->getExtra();
if (isset($extra["patternlab"]) && isset($extra["patternlab"]["config"]) && is_array($extra["patternlab"]["config"])) {
self::$installerInfo["configOverrides"] = $extra["patternlab"]["config"];
}
}
/**
* Get the package info from each patternlab-* package's composer.json
* @param {String} the type of event fired during the composer install
* @param {Object} a script event object from composer
*/
public static function getPackageInfo($type, $event) {
$package = ($type == "update") ? $event->getOperation()->getTargetPackage() : $event->getOperation()->getPackage();
$packageType = $package->getType();
$packageExtra = $package->getExtra();
$packageInfo = array();
// make sure we're only evaluating pattern lab packages
if (strpos($packageType,"patternlab-") !== false) {
$packageInfo["name"] = $package->getName();
$packageInfo["type"] = $packageType;
$packageInfo["pathBase"] = $event->getComposer()->getInstallationManager()->getInstallPath($package);
$packageInfo["pathDist"] = $packageInfo["pathBase"].DIRECTORY_SEPARATOR."dist".DIRECTORY_SEPARATOR;
$packageInfo["extra"] = (isset($packageExtra["patternlab"])) ? $packageExtra["patternlab"] : array();
self::$installerInfo["packages"][] = $packageInfo;
}
}
/**
* Get the suggested starter kits from the root package composer.json
* @param {Object} a script event object from composer
*/
public static function getSuggestedStarterKits(Event $event) {
$extra = $event->getComposer()->getPackage()->getExtra();
if (isset($extra["patternlab"]) && isset($extra["patternlab"]["starterKitSuggestions"]) && is_array($extra["patternlab"]["starterKitSuggestions"])) {
self::$installerInfo["suggestedStarterKits"] = $extra["patternlab"]["starterKitSuggestions"];
}
}
/**
* Run the centralized postInstallCmd
* @param {Object} a script event object from composer
*/
public static function postInstallCmd(Event $event) {
InstallerUtil::postInstallCmd(self::$installerInfo, $event);
}
/**
* Run the centralized postUpdateCmd
* @param {Object} a script event object from composer
*/
public static function postUpdateCmd(Event $event) {
InstallerUtil::postUpdateCmd(self::$installerInfo, $event);
}
/**
* Clean-up when a package is removed
* @param {Object} a script event object from composer
*/
public static function postPackageInstall(PackageEvent $event) {
self::getPackageInfo("install", $event);
}
/**
* Clean-up when a package is removed
* @param {Object} a script event object from composer
*/
public static function postPackageUpdate(PackageEvent $event) {
self::getPackageInfo("update", $event);
}
/**
* Clean-up when a package is removed
* @param {Object} a script event object from composer
*/
public static function prePackageUninstall(PackageEvent $event) {
// make sure the postUpdateCmd doesnt actually do anything
self::setPackagesRemove();
// get the basic package info
$package = $event->getOperation()->getPackage();
$packageType = $package->getType();
$packageInfo = array();
// make sure we're only evaluating pattern lab packages. remove attributes related to them.
if (strpos($packageType,"patternlab-") !== false) {
$packageInfo["name"] = $package->getName();
$packageInfo["type"] = $packageType;
$packageInfo["pathBase"] = $event->getComposer()->getInstallationManager()->getInstallPath($package);
InstallerUtil::packageRemove($packageInfo);
}
}
/**
* Set the packages remove boolean to true
*/
public static function setPackagesRemove() {
self::$installerInfo["packagesRemove"] = true;
}
/**
* Set the project install boolean to true
* @param {Object} a script event object from composer
*/
public static function setProjectInstall(Event $event) {
self::$installerInfo["projectInstall"] = true;
}
}