@@ -48,20 +48,46 @@ protected static function buildFileList($initialList) {
48
48
* Common init sequence
49
49
*/
50
50
protected static function init () {
51
-
51
+
52
52
// start the timer
53
53
Timer::start ();
54
-
54
+
55
55
// initialize the console to print out any issues
56
56
Console::init ();
57
-
57
+
58
58
// initialize the config for the pluginDir
59
59
$ baseDir = __DIR__ ."/../../../../../ " ;
60
60
Config::init ($ baseDir ,false );
61
-
61
+
62
+ // make sure the source dir is set-up
63
+ $ sourceDir = Config::getOption ("sourceDir " );
64
+ if (!is_dir ($ sourceDir )) {
65
+ mkdir ($ sourceDir );
66
+ }
67
+
62
68
Dispatcher::init ();
63
69
64
70
}
71
+
72
+ /**
73
+ * Include StarterKit in an array_filter
74
+ */
75
+ public static function includeStarterKit ($ var ) {
76
+
77
+ $ result = ($ var ["type " ] == "patternlab-starterkit " );
78
+ return $ result ;
79
+
80
+ }
81
+
82
+ /**
83
+ * Exclude StarterKit in an array_filter
84
+ */
85
+ public static function excludeStarterKit ($ var ) {
86
+
87
+ $ result = ($ var ["type " ] != "patternlab-starterkit " );
88
+ return $ result ;
89
+
90
+ }
65
91
66
92
/**
67
93
* Parse the component types to figure out what needs to be moved and added to the component JSON files
@@ -388,123 +414,29 @@ protected static function pathExists($packageName,$path) {
388
414
return false ;
389
415
390
416
}
391
-
417
+
392
418
/**
393
- * Run the PL tasks when a package is installed
419
+ * Run the PL tasks when Composer runs an install command
420
+ * @param {Array} collected package info
394
421
* @param {Object} a script event object from composer
395
422
*/
396
- public static function postPackageInstall ($ event ) {
397
-
398
- // run the console and config inits
399
- self ::init ();
400
-
401
- // run the tasks based on what's in the extra dir
402
- self ::runTasks ($ event ,"install " );
403
-
423
+ public static function postInstallCmd ($ installerInfo , $ event ) {
424
+
425
+ self ::runTasks ($ installerInfo );
426
+
404
427
}
405
-
428
+
406
429
/**
407
- * Run the PL tasks when a package is updated
430
+ * Run the PL tasks when Composer runs an update command
431
+ * @param {Array} collected package info
408
432
* @param {Object} a script event object from composer
409
433
*/
410
- public static function postPackageUpdate ($ event ) {
411
-
412
- // run the console and config inits
413
- self ::init ();
414
-
415
- self ::runTasks ($ event ,"update " );
416
-
434
+ public static function postUpdateCmd ($ installerInfo , $ event ) {
435
+
436
+ self ::runTasks ($ installerInfo );
437
+
417
438
}
418
-
419
- /**
420
- * Ask questions after the create package is done
421
- * @param {Object} a script event object from composer
422
- */
423
- public static function postCreateProjectCmd ($ event ) {
424
-
425
- // see if there is an extra component
426
- $ extra = $ event ->getComposer ()->getPackage ()->getExtra ();
427
-
428
- if (isset ($ extra ["patternlab " ])) {
429
-
430
- self ::init ();
431
- Console::writeLine ("" );
432
-
433
- // see if we have any starterkits to suggest
434
- if (isset ($ extra ["patternlab " ]["starterKitSuggestions " ]) && is_array ($ extra ["patternlab " ]["starterKitSuggestions " ])) {
435
-
436
- $ suggestions = $ extra ["patternlab " ]["starterKitSuggestions " ];
437
-
438
- // suggest starterkits
439
- Console::writeInfo ("suggested starterkits that work with this edition: " , false , true );
440
- foreach ($ suggestions as $ i => $ suggestion ) {
441
-
442
- // write each suggestion
443
- $ num = $ i + 1 ;
444
- Console::writeLine ($ num .": " .$ suggestion , true );
445
-
446
- }
447
-
448
- // prompt for input on the suggestions
449
- Console::writeLine ("" );
450
- $ prompt = "choose an option or hit return to skip: " ;
451
- $ options = "(ex. 1) " ;
452
- $ input = Console::promptInput ($ prompt ,$ options );
453
- $ result = (int )$ input - 1 ;
454
-
455
- if (isset ($ suggestions [$ result ])) {
456
-
457
- Console::writeLine ("" );
458
- $ f = new Fetch ();
459
- $ result = $ f ->fetchStarterKit ($ suggestions [$ result ]);
460
-
461
- if ($ result ) {
462
-
463
- Console::writeLine ("" );
464
- $ g = new Generator ();
465
- $ g ->generate (array ("foo " => "bar " ));
466
-
467
- Console::writeLine ("" );
468
- Console::writeInfo ("type <desc>php core/console --server</desc> to start the built-in server and see Pattern Lab... " , false , true );
469
-
470
- }
471
-
472
- } else {
473
-
474
- Console::writeWarning ("you will need to install a StarterKit before using Pattern Lab... " );
475
-
476
- }
477
-
478
- }
479
-
480
- }
481
-
482
- }
483
-
484
- /**
485
- * Make sure certain things are set-up before running the installation of a package
486
- * @param {Object} a script event object from composer
487
- */
488
- public static function preInstallCmd ($ event ) {
489
-
490
- // run the console and config inits
491
- self ::init ();
492
-
493
- // default vars
494
- $ sourceDir = Config::getOption ("sourceDir " );
495
- $ packagesDir = Config::getOption ("packagesDir " );
496
-
497
- // check directories
498
- if (!is_dir ($ sourceDir )) {
499
- mkdir ($ sourceDir );
500
- }
501
-
502
- if (!is_dir ($ packagesDir )) {
503
- mkdir ($ packagesDir );
504
- }
505
-
506
- }
507
-
439
+
508
440
/**
509
441
* Make sure pattern engines and listeners are removed on uninstall
510
442
* @param {Object} a script event object from composer
@@ -518,7 +450,7 @@ public static function prePackageUninstallCmd($event) {
518
450
$ package = $ event ->getOperation ()->getPackage ();
519
451
$ type = $ package ->getType ();
520
452
$ name = $ package ->getName ();
521
- $ pathBase = Config:: getOption ( " packagesDir " ). " / " . $ name ;
453
+ $ pathBase = $ package -> getTargetDir () ;
522
454
523
455
// see if the package has a listener and remove it
524
456
self ::scanForListener ($ pathBase ,true );
@@ -531,6 +463,50 @@ public static function prePackageUninstallCmd($event) {
531
463
// go over .json in patternlab-components/, remove references to packagename
532
464
533
465
}
466
+
467
+ /**
468
+ * Prompt the user to install a starterkit
469
+ * @param {Array} the starterkit suggestions
470
+ */
471
+ protected static function promptStarterKitInstall ($ starterKitSuggestions ) {
472
+
473
+ Console::writeLine ("" );
474
+
475
+ // suggest starterkits
476
+ Console::writeInfo ("suggested starterkits that work with this edition: " , false , true );
477
+ foreach ($ starterKitSuggestions as $ i => $ suggestion ) {
478
+ $ num = $ i + 1 ;
479
+ Console::writeLine ($ num .": " .$ suggestion , true );
480
+ }
481
+
482
+ // prompt for input on the suggestions
483
+ Console::writeLine ("" );
484
+
485
+ $ prompt = "choose an option or hit return to skip: " ;
486
+ $ options = "(ex. 1) " ;
487
+ $ input = Console::promptInput ($ prompt ,$ options );
488
+ $ result = (int )$ input - 1 ;
489
+
490
+ if (isset ($ starterKitSuggestions [$ result ])) {
491
+
492
+ Console::writeLine ("" );
493
+ $ f = new Fetch ();
494
+ $ result = $ f ->fetchStarterKit ($ suggestions [$ result ]);
495
+
496
+ if ($ result ) {
497
+
498
+ Console::writeLine ("" );
499
+ $ g = new Generator ();
500
+ $ g ->generate (array ("foo " => "bar " ));
501
+
502
+ Console::writeLine ("" );
503
+ Console::writeInfo ("type <desc>php core/console --server</desc> to start the built-in server and see Pattern Lab... " , false , true );
504
+
505
+ }
506
+
507
+ }
508
+
509
+ }
534
510
535
511
/**
536
512
* Remove dots from the path to make sure there is no file system traversal when looking for or writing files
@@ -550,30 +526,39 @@ protected static function removeDots($path) {
550
526
551
527
/**
552
528
* Handle some Pattern Lab specific tasks based on what's found in the package's composer.json file
553
- * @param {Object} a script event object from composer
554
- * @param {String} the type of event starting the runTasks command
529
+ * @param {Array} the info culled from installing various pattern lab-related packages
555
530
*/
556
- protected static function runTasks ($ event ,$ type ) {
557
-
558
- // get package info
559
- $ package = ($ type == "install " ) ? $ event ->getOperation ()->getPackage () : $ event ->getOperation ()->getTargetPackage ();
560
- $ extra = $ package ->getExtra ();
561
- $ type = $ package ->getType ();
562
- $ name = $ package ->getName ();
563
- $ pathBase = Config::getOption ("packagesDir " )."/ " .$ name ;
564
- $ pathDist = $ pathBase ."/dist/ " ;
565
-
566
- // make sure we're only evaluating pattern lab packages
567
- if (strpos ($ type ,"patternlab- " ) !== false ) {
568
-
531
+ protected static function runTasks ($ installerInfo ) {
532
+
533
+ // initialize a bunch of stuff like config and console
534
+ self ::init ();
535
+
536
+ // make sure user is prompted to install starterkit
537
+ if (!empty ($ installerInfo ["starterKitSuggestions " ])) {
538
+ self ::promptStarterKitInstall ($ installerInfo ["starterKitSuggestions " ]);
539
+ }
540
+
541
+ // reorder packages so the starterkit is first if it's being installed as a package
542
+ $ packages = $ installerInfo ["packages " ];
543
+ $ packages = array_merge (array_filter ($ packages , "self::includeStarterKit " ), array_filter ($ packages , "self::excludeStarterKit " ));
544
+
545
+ foreach ($ packages as $ package ) {
546
+
547
+ // set-up package info
548
+ $ extra = $ package ["extra " ];
549
+ $ type = $ package ["type " ];
550
+ $ name = $ package ["name " ];
551
+ $ pathBase = $ package ["pathBase " ];
552
+ $ pathDist = $ package ["pathDist " ];
553
+
569
554
// make sure that it has the name-spaced section of data to be parsed. if it exists parse it
570
- if (isset ($ extra[ " patternlab " ] )) {
571
- self ::parseComposerExtraList ($ extra[ " patternlab " ] , $ name , $ pathDist );
555
+ if (! empty ($ extra )) {
556
+ self ::parseComposerExtraList ($ extra , $ name , $ pathDist );
572
557
}
573
-
558
+
574
559
// see if the package has a listener
575
560
self ::scanForListener ($ pathBase );
576
-
561
+
577
562
// address other specific needs based on type
578
563
if ($ type == "patternlab-patternengine " ) {
579
564
self ::scanForPatternEngineRule ($ pathBase );
@@ -582,9 +567,9 @@ protected static function runTasks($event,$type) {
582
567
} else if (($ type == "patternlab-styleguidekit " ) && (strpos ($ name ,"-assets- " ) === false )) {
583
568
Config::updateConfigOption ("styleguideKit " ,$ name );
584
569
}
585
-
570
+
586
571
}
587
-
572
+
588
573
}
589
574
590
575
/**
@@ -594,7 +579,7 @@ protected static function runTasks($event,$type) {
594
579
protected static function scanForListener ($ pathPackage ,$ remove = false ) {
595
580
596
581
// get listener list path
597
- $ pathList = Config::getOption ("packagesDir " )."/listeners.json " ;
582
+ $ pathList = Config::getOption ("configDir " )."/listeners.json " ;
598
583
599
584
// make sure listeners.json exists. if not create it
600
585
if (!file_exists ($ pathList )) {
@@ -637,7 +622,7 @@ protected static function scanForListener($pathPackage,$remove = false) {
637
622
protected static function scanForPatternEngineRule ($ pathPackage ,$ remove = false ) {
638
623
639
624
// get listener list path
640
- $ pathList = Config::getOption ("packagesDir " )."/patternengines.json " ;
625
+ $ pathList = Config::getOption ("configDir " )."/patternengines.json " ;
641
626
642
627
// make sure patternengines.json exists. if not create it
643
628
if (!file_exists ($ pathList )) {
0 commit comments