@@ -15,17 +15,17 @@ class CreateJSRoutesCommand extends Command
1515 protected $ signature = "route:tojs
1616 { --name=routes.js : Name of the output file. }
1717 { --p|path= : Path of the output file. }
18- { --w|whitelist = : List of comma separated route names to include (overrides ignore and methods). }
19- { --i|ignore=telescope : List of comma separated route names to ignore (overrides methods). }
20- { --m|methods=GET : List of comma separated methods accepted by filter. Empty for include all methods. }
18+ { --i|include = : List of comma separated route names to include (overrides exclude and methods). }
19+ { --e|exclude= : List of comma separated route names to exclude (overrides methods). }
20+ { --m|methods= : List of comma separated methods accepted by filter. Empty for include all methods. }
2121 { --f|force : Overwrite existing routes by default. } " ;
2222
2323 /**
2424 * The console command description.
2525 *
2626 * @var string
2727 */
28- protected $ description = "Create object with routes, and a function for its JS use " ;
28+ protected $ description = "Create object with routes, and a function for its JS use. Uses key from configuration file 'jsroutes'. " ;
2929
3030 /**
3131 * Create a new command instance.
@@ -50,7 +50,7 @@ public function handle()
5050 return $ this ->includeRoute ($ route , $ key );
5151 })->map (function ($ route ) {
5252 return [
53- " uri " => $ route ->uri
53+ ' uri ' => $ route ->uri
5454 ];
5555 });
5656
@@ -60,9 +60,9 @@ public function handle()
6060 $ content .= json_encode ($ routes , $ jsonFlags );
6161 $ content .= "; \n\n" ;
6262
63- $ content .= file_get_contents (__DIR__ . " /../assets/js/routeFunction.js " );
63+ $ content .= file_get_contents (__DIR__ . ' /../assets/js/routeFunction.js ' );
6464
65- $ fileName = $ this ->option (" name " );
65+ $ fileName = config ( ' jsroutes.name ' , $ this ->option (' name ' ) );
6666 if ($ this ->createFile ($ fileName , $ content )) {
6767 $ this ->info ($ fileName . " created " );
6868 }
@@ -72,14 +72,14 @@ public function createFile($fileName, $contents)
7272 {
7373 if (
7474 file_exists ($ file = $ this ->getJSPath ($ fileName )) &&
75- !$ this ->option (" force " )
75+ !$ this ->option (' force ' )
7676 ) {
7777 if (
7878 !$ this ->confirm (
79- " The [ " . $ fileName . " ] file already exists. Do you want to replace it? "
79+ ' The [ ' . $ fileName . ' ] file already exists. Do you want to replace it? '
8080 )
8181 ) {
82- $ this ->error (" Error " );
82+ $ this ->error (' Error ' );
8383 return false ;
8484 }
8585 }
@@ -90,21 +90,26 @@ public function createFile($fileName, $contents)
9090
9191 private function includeRoute ($ route , $ routeName )
9292 {
93- $ whitelist = explode (" , " , $ this ->option (" whitelist " ));
93+ $ include = config ( ' jsroutes.include ' , explode (' , ' , $ this ->option (' include ' ) ));
9494
95- if (in_array ($ routeName , $ whitelist )) {
95+ if (in_array ($ routeName , $ include )) {
9696 return true ;
9797 }
9898
99- $ ignore = explode (" , " , $ this ->option (" ignore " ));
99+ $ exclude = config ( ' jsroutes.exclude ' , explode (' , ' , $ this ->option (' exclude ' ) ));
100100
101- if (in_array ($ routeName , $ ignore )) {
101+ if (in_array ($ routeName , $ exclude )) {
102102 return false ;
103103 }
104104
105- $ methods = $ this ->option ("methods " );
105+ if (config ('jsroutes.methods ' ) !== null ) {
106+ $ methods = implode (', ' , config ('jsroutes.methods ' ));
107+ } else {
108+ $ methods = $ this ->option ('methods ' );
109+ }
110+
106111 $ valid = empty ($ methods );
107- foreach (explode (" , " , $ methods ) as $ method ) {
112+ foreach (explode (' , ' , $ methods ) as $ method ) {
108113 $ valid |= in_array ($ method , $ route ->methods );
109114 }
110115
@@ -113,7 +118,7 @@ private function includeRoute($route, $routeName)
113118
114119 public function getJSPath ($ fileName )
115120 {
116- $ path = $ this ->option (" path " ) ?? config ('js.path ' )[0 ] ?? resource_path ('js ' );
121+ $ path = config ( ' jsroutes.path ' , $ this ->option (' path ' ) ?? config ('js.path ' )[0 ] ?? resource_path ('js ' ) );
117122 return implode (DIRECTORY_SEPARATOR , [$ path , $ fileName ]);
118123 }
119124}
0 commit comments