Skip to content

Commit 97a97c5

Browse files
committed
post update now splits based on a package being removed vs. added
1 parent 7e29f09 commit 97a97c5

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

src/PatternLab/InstallerUtil.php

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -504,44 +504,21 @@ protected static function pathExists($packageName,$path) {
504504
*/
505505
public static function postInstallCmd($installerInfo, $event) {
506506

507-
self::runTasks($installerInfo);
507+
self::packagesInstall($installerInfo);
508508

509509
}
510510

511511
/**
512-
* Run the PL tasks when Composer runs an update command
512+
* Run the PL tasks when Composer runs an update command. this also runs after a package is removed.
513513
* @param {Array} collected package info
514514
* @param {Object} a script event object from composer
515515
*/
516516
public static function postUpdateCmd($installerInfo, $event) {
517517

518-
self::runTasks($installerInfo);
519-
520-
}
521-
522-
/**
523-
* Make sure pattern engines and listeners are removed on uninstall
524-
* @param {String} the name of the package to be removed
525-
* @param {String} the type of the package to be removed
526-
* @param {String} the path of the package to be removed
527-
*/
528-
public static function prePackageUninstallCmd($name, $type, $pathBase) {
529-
530-
// run the console and config inits
531-
self::init();
532-
533-
// see if the package has a listener and remove it
534-
self::scanForListener($pathBase,true);
535-
536-
// see if the package is a pattern engine and remove the rule
537-
if ($type == "patternlab-patternengine") {
538-
self::scanForPatternEngineRule($pathBase,true);
539-
}
540-
541-
// remove the component package file if it exists
542-
$jsonFile = Config::getOption("componentDir")."/packages/".str_replace("/","-",$name).".json";
543-
if (file_exists($jsonFile)) {
544-
unlink($jsonFile);
518+
if ($installerInfo["packagesRemove"]) {
519+
self::packagesRemove($installerInfo);
520+
} else {
521+
self::packagesInstall($installerInfo);
545522
}
546523

547524
}
@@ -599,7 +576,7 @@ protected static function removeDots($path) {
599576
* Handle some Pattern Lab specific tasks based on what's found in the package's composer.json file
600577
* @param {Array} the info culled from installing various pattern lab-related packages
601578
*/
602-
protected static function runTasks($installerInfo) {
579+
protected static function packagesInstall($installerInfo) {
603580

604581
// initialize a bunch of stuff like config and console
605582
self::init();
@@ -659,6 +636,39 @@ protected static function runTasks($installerInfo) {
659636

660637
}
661638

639+
/**
640+
* Make sure pattern engines and listeners are removed on uninstall
641+
* @param {String} the name of the package to be removed
642+
* @param {String} the type of the package to be removed
643+
* @param {String} the path of the package to be removed
644+
*/
645+
public static function packagesRemove($name, $type, $pathBase) {
646+
647+
// run the console and config inits
648+
self::init();
649+
650+
$packages = $installerInfo["packages"];
651+
652+
foreach ($packages as $package) {
653+
654+
// see if the package has a listener and remove it
655+
self::scanForListener($pathBase,true);
656+
657+
// see if the package is a pattern engine and remove the rule
658+
if ($type == "patternlab-patternengine") {
659+
self::scanForPatternEngineRule($pathBase,true);
660+
}
661+
662+
// remove the component package file if it exists
663+
$jsonFile = Config::getOption("componentDir")."/packages/".str_replace("/","-",$name).".json";
664+
if (file_exists($jsonFile)) {
665+
unlink($jsonFile);
666+
}
667+
668+
}
669+
670+
}
671+
662672
/**
663673
* Scan the package for a listener
664674
* @param {String} the path for the package

0 commit comments

Comments
 (0)