@@ -430,6 +430,8 @@ public function disable($name)
430
430
*/
431
431
public function make ($ name )
432
432
{
433
+ $ studlyCase = studly_case ($ name );
434
+
433
435
// Check if already exists
434
436
if ($ this ->downloaded ($ name )) {
435
437
throw new Exceptions \HookAlreadyExistsException ("Hook [ {$ name }] already exists. " );
@@ -443,26 +445,51 @@ public function make($name)
443
445
}
444
446
445
447
// Create folder for the new hook
448
+ $ this ->filesystem ->deleteDirectory (base_path ("hooks/ {$ name }" ));
446
449
$ this ->filesystem ->makeDirectory (base_path ("hooks/ {$ name }" ));
447
450
448
451
// make stub files
449
- /*
450
- $this->filesystem->put(
451
- base_path("hooks/{$name}/hook.json"),
452
- json_encode($data)
453
- );
454
- */
452
+ $ this ->makeStubFiles ($ name );
455
453
456
- // Make composer.json
457
- $ composer = [
458
- 'name ' => $ name ,
454
+ event (new Events \MadeHook ($ name ));
455
+ }
456
+
457
+ protected function makeStubFiles ($ name )
458
+ {
459
+ $ replaces = [
460
+ 'kebab-case ' => $ name ,
461
+ 'snake_case ' => snake_case ($ name ),
462
+ 'camcelCase ' => camel_case ($ name ),
463
+ 'StudlyCase ' => studly_case ($ name ),
459
464
];
460
- $ this ->filesystem ->put (
461
- base_path ("hooks/ {$ name }/composer.json " ),
462
- json_encode ($ composer , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES )
463
- );
464
465
465
- event (new Events \MadeHook ($ name ));
466
+ $ files = $ this ->filesystem ->allFiles (__DIR__ .'/../stub ' );
467
+
468
+ foreach ($ files as $ file ) {
469
+ if ($ path = $ file ->getRelativePath ()) {
470
+ $ parts = explode ('/ ' , $ path );
471
+
472
+ $ location = base_path ("hooks/ {$ name }" );
473
+
474
+ foreach ($ parts as $ part ) {
475
+ $ location .= "/ {$ part }" ;
476
+
477
+ if (!$ this ->filesystem ->isDirectory ($ location )) {
478
+ $ this ->filesystem ->makeDirectory ($ location );
479
+ }
480
+ }
481
+ }
482
+
483
+ $ content = $ this ->replace ($ this ->filesystem ->get ($ file ->getRealPath ()), $ replaces );
484
+ $ filename = $ this ->replace ($ file ->getRelativePathname (), $ replaces );
485
+
486
+ $ this ->filesystem ->put (base_path ("hooks/ {$ name }/ {$ filename }" ), $ content );
487
+ }
488
+ }
489
+
490
+ protected function replace ($ content , array $ replaces )
491
+ {
492
+ return str_replace (array_keys ($ replaces ), array_values ($ replaces ), $ content );
466
493
}
467
494
468
495
/**
@@ -522,8 +549,12 @@ public function local($name)
522
549
*/
523
550
public function downloaded ($ name )
524
551
{
525
- return $ this ->filesystem ->isDirectory (base_path ("hooks/ {$ name }" ))
526
- || $ this ->filesystem ->isDirectory (base_path ("vendor/ {$ name }" ));
552
+ if ($ this ->local ($ name )) {
553
+ return $ this ->filesystem ->isDirectory (base_path ("hooks/ {$ name }" ))
554
+ && $ this ->filesystem ->exists (base_path ("hooks/ {$ name }/composer.json " ));
555
+ }
556
+
557
+ return $ this ->filesystem ->isDirectory (base_path ("vendor/ {$ name }" ));
527
558
}
528
559
529
560
/**
@@ -726,6 +757,10 @@ public function readLocalHooks()
726
757
$ hooks = [];
727
758
$ directories = array_except ($ this ->filesystem ->directories (base_path ('hooks ' )), ['. ' , '.. ' ]);
728
759
foreach ($ directories as $ directory ) {
760
+ if (!$ this ->filesystem ->exists ($ directory .'/composer.json ' )) {
761
+ continue ;
762
+ }
763
+
729
764
$ composer = json_decode ($ this ->filesystem ->get ($ directory .'/composer.json ' ), true );
730
765
731
766
if (!is_null ($ composer ) && isset ($ composer ['name ' ])) {
0 commit comments