@@ -15,17 +15,17 @@ class CreateJSRoutesCommand extends Command
15
15
protected $ signature = "route:tojs
16
16
{ --name=routes.js : Name of the output file. }
17
17
{ --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. }
21
21
{ --f|force : Overwrite existing routes by default. } " ;
22
22
23
23
/**
24
24
* The console command description.
25
25
*
26
26
* @var string
27
27
*/
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'. " ;
29
29
30
30
/**
31
31
* Create a new command instance.
@@ -50,7 +50,7 @@ public function handle()
50
50
return $ this ->includeRoute ($ route , $ key );
51
51
})->map (function ($ route ) {
52
52
return [
53
- " uri " => $ route ->uri
53
+ ' uri ' => $ route ->uri
54
54
];
55
55
});
56
56
@@ -60,9 +60,9 @@ public function handle()
60
60
$ content .= json_encode ($ routes , $ jsonFlags );
61
61
$ content .= "; \n\n" ;
62
62
63
- $ content .= file_get_contents (__DIR__ . " /../assets/js/routeFunction.js " );
63
+ $ content .= file_get_contents (__DIR__ . ' /../assets/js/routeFunction.js ' );
64
64
65
- $ fileName = $ this ->option (" name " );
65
+ $ fileName = config ( ' jsroutes.name ' , $ this ->option (' name ' ) );
66
66
if ($ this ->createFile ($ fileName , $ content )) {
67
67
$ this ->info ($ fileName . " created " );
68
68
}
@@ -72,14 +72,14 @@ public function createFile($fileName, $contents)
72
72
{
73
73
if (
74
74
file_exists ($ file = $ this ->getJSPath ($ fileName )) &&
75
- !$ this ->option (" force " )
75
+ !$ this ->option (' force ' )
76
76
) {
77
77
if (
78
78
!$ 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? '
80
80
)
81
81
) {
82
- $ this ->error (" Error " );
82
+ $ this ->error (' Error ' );
83
83
return false ;
84
84
}
85
85
}
@@ -90,21 +90,26 @@ public function createFile($fileName, $contents)
90
90
91
91
private function includeRoute ($ route , $ routeName )
92
92
{
93
- $ whitelist = explode (" , " , $ this ->option (" whitelist " ));
93
+ $ include = config ( ' jsroutes.include ' , explode (' , ' , $ this ->option (' include ' ) ));
94
94
95
- if (in_array ($ routeName , $ whitelist )) {
95
+ if (in_array ($ routeName , $ include )) {
96
96
return true ;
97
97
}
98
98
99
- $ ignore = explode (" , " , $ this ->option (" ignore " ));
99
+ $ exclude = config ( ' jsroutes.exclude ' , explode (' , ' , $ this ->option (' exclude ' ) ));
100
100
101
- if (in_array ($ routeName , $ ignore )) {
101
+ if (in_array ($ routeName , $ exclude )) {
102
102
return false ;
103
103
}
104
104
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
+
106
111
$ valid = empty ($ methods );
107
- foreach (explode (" , " , $ methods ) as $ method ) {
112
+ foreach (explode (' , ' , $ methods ) as $ method ) {
108
113
$ valid |= in_array ($ method , $ route ->methods );
109
114
}
110
115
@@ -113,7 +118,7 @@ private function includeRoute($route, $routeName)
113
118
114
119
public function getJSPath ($ fileName )
115
120
{
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 ' ) );
117
122
return implode (DIRECTORY_SEPARATOR , [$ path , $ fileName ]);
118
123
}
119
124
}
0 commit comments