3
3
namespace Larapack \Hooks ;
4
4
5
5
use Carbon \Carbon ;
6
- use Illuminate \Database \Migrations \Migrator ;
7
6
use Illuminate \Filesystem \Filesystem ;
8
7
use Illuminate \Foundation \Application ;
9
8
use Symfony \Component \Console \Input \ArrayInput ;
@@ -910,7 +909,13 @@ protected function migrateHook(Hook $hook)
910
909
{
911
910
$ migrations = (array ) $ hook ->getComposerHookKey ('migrations ' , []);
912
911
913
- $ this ->migrator ->run ($ this ->realPath ($ migrations , $ hook ->getPath ().'/ ' )->all ());
912
+ foreach ($ migrations as $ path ) {
913
+ if ($ this ->filesystem ->isDirectory ($ hook ->getPath ().'/ ' .$ path )) {
914
+ $ this ->migrator ->run ($ this ->realPath ([$ path ], $ hook ->getPath ().'/ ' )->all ());
915
+ } else {
916
+ $ this ->migrator ->runFiles ($ this ->realPath ([$ path ], $ hook ->getPath ().'/ ' )->all ());
917
+ }
918
+ }
914
919
}
915
920
916
921
/**
@@ -922,7 +927,13 @@ protected function unmigrateHook(Hook $hook)
922
927
{
923
928
$ migrations = (array ) $ hook ->getComposerHookKey ('migrations ' , []);
924
929
925
- $ this ->migrator ->reset ($ this ->realPath ($ migrations , $ hook ->getPath ().'/ ' )->all ());
930
+ foreach ($ migrations as $ path ) {
931
+ if ($ this ->filesystem ->isDirectory ($ hook ->getPath ().'/ ' .$ path )) {
932
+ $ this ->migrator ->reset ($ this ->realPath ([$ path ], $ hook ->getPath ().'/ ' )->all ());
933
+ } else {
934
+ $ this ->migrator ->resetFiles ($ this ->realPath ([$ path ], $ hook ->getPath ().'/ ' )->all ());
935
+ }
936
+ }
926
937
}
927
938
928
939
/**
@@ -968,10 +979,17 @@ protected function publishHook(Hook $hook, $force = false)
968
979
continue ;
969
980
}
970
981
971
- $ allFiles = collect ( $ this -> filesystem ->allFiles ($ realLocation ))
972
- ->map (function ($ file ) use ($ realLocation ) {
982
+ if ( $ filesystem ->isDirectory ($ realLocation )) {
983
+ $ allFiles = collect ( $ filesystem -> allFiles ( $ realLocation )) ->map (function ($ file ) use ($ realLocation ) {
973
984
return substr ($ file ->getRealPath (), strlen ($ realLocation ) + 1 );
974
985
});
986
+ } else {
987
+ $ allFiles = collect ([new \Symfony \Component \Finder \SplFileInfo (
988
+ $ realLocation ,
989
+ '' ,
990
+ basename ($ realLocation )
991
+ )]);
992
+ }
975
993
976
994
$ newFiles = $ allFiles ->filter (function ($ filename ) use ($ publishPath , $ filesystem ) {
977
995
return !$ filesystem ->exists ($ publishPath .'/ ' .$ filename );
@@ -996,6 +1014,16 @@ protected function publishHook(Hook $hook, $force = false)
996
1014
997
1015
$ newFiles ->merge ($ updatedFiles )
998
1016
->each (function ($ filename ) use ($ realLocation , $ publishPath , $ filesystem ) {
1017
+ if (!$ filesystem ->isDirectory ($ realLocation )) {
1018
+ $ directory = substr ($ publishPath , 0 , -strlen (basename ($ publishPath )));
1019
+
1020
+ if (!$ filesystem ->isDirectory ($ directory )) {
1021
+ $ filesystem ->makeDirectory ($ directory , 0755 , true , true );
1022
+ }
1023
+
1024
+ return $ filesystem ->copy ($ realLocation , $ publishPath );
1025
+ }
1026
+
999
1027
$ directory = substr ($ publishPath .'/ ' .$ filename , 0 , -strlen (basename ($ filename )));
1000
1028
1001
1029
if (!$ filesystem ->isDirectory ($ directory )) {
@@ -1028,17 +1056,33 @@ protected function unpublishHook(Hook $hook)
1028
1056
continue ;
1029
1057
}
1030
1058
1031
- $ allFiles = collect ($ this ->filesystem ->allFiles ($ realLocation ))
1032
- ->map (function ($ file ) use ($ realLocation ) {
1033
- return substr ($ file ->getRealPath (), strlen ($ realLocation ) + 1 );
1034
- });
1059
+ if ($ filesystem ->isDirectory ($ realLocation )) {
1060
+ $ allFiles = collect ($ this ->filesystem ->allFiles ($ realLocation ))
1061
+ ->map (function ($ file ) use ($ realLocation ) {
1062
+ return substr ($ file ->getRealPath (), strlen ($ realLocation ) + 1 );
1063
+ });
1064
+ } else {
1065
+ $ allFiles = collect ([new \Symfony \Component \Finder \SplFileInfo (
1066
+ $ realLocation ,
1067
+ '' ,
1068
+ basename ($ realLocation )
1069
+ )]);
1070
+ }
1035
1071
1036
1072
$ existingFiles = $ allFiles ->filter (function ($ filename ) use ($ publishPath , $ filesystem ) {
1037
- return $ filesystem ->exists ($ publishPath .'/ ' .$ filename );
1073
+ if ($ filesystem ->isDirectory ($ publishPath )) {
1074
+ return $ filesystem ->exists ($ publishPath .'/ ' .$ filename );
1075
+ }
1076
+
1077
+ return $ filesystem ->exists ($ publishPath );
1038
1078
});
1039
1079
1040
1080
$ existingFiles ->each (function ($ filename ) use ($ publishPath , $ filesystem ) {
1041
- $ filesystem ->delete ($ publishPath .'/ ' .$ filename );
1081
+ if ($ filesystem ->isDirectory ($ publishPath )) {
1082
+ return $ filesystem ->delete ($ publishPath .'/ ' .$ filename );
1083
+ }
1084
+
1085
+ $ filesystem ->delete ($ publishPath );
1042
1086
});
1043
1087
}
1044
1088
}
@@ -1055,7 +1099,17 @@ protected function runSeeders($folders, $basePath)
1055
1099
1056
1100
$ this ->realPath ($ folders , $ basePath )
1057
1101
->each (function ($ folder ) use ($ filesystem ) {
1058
- collect ($ filesystem ->files ($ folder ))->filter (function ($ file ) {
1102
+ if ($ filesystem ->isDirectory ($ folder )) {
1103
+ $ files = $ filesystem ->files ($ folder );
1104
+ } else {
1105
+ $ files = [new \Symfony \Component \Finder \SplFileInfo (
1106
+ $ folder ,
1107
+ '' ,
1108
+ basename ($ folder )
1109
+ )];
1110
+ }
1111
+
1112
+ collect ($ files )->filter (function ($ file ) {
1059
1113
return $ file ->getExtension () == 'php ' ;
1060
1114
})->each (function ($ file ) {
1061
1115
$ class = substr ($ file ->getFilename (), 0 , -4 );
0 commit comments