@@ -17,8 +17,10 @@ public static function install($command)
1717 static ::$ command = $ command ;
1818
1919 static ::updatePackages ();
20- static ::updateComposer (false );
2120 static ::updateBootstrapping ();
21+ static ::updateComposer (false );
22+ static ::publishServiceProvider ();
23+ static ::registerInertiaServiceProvider ();
2224 static ::updateWelcomePage ();
2325 static ::updateGitignore ();
2426 static ::scaffoldComponents ();
@@ -108,4 +110,43 @@ protected static function updateComposer($dev = true)
108110 json_encode ($ packages , JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ).PHP_EOL
109111 );
110112 }
113+
114+ public static function publishServiceProvider ()
115+ {
116+ copy (
117+ __DIR__ .'/inertiajs-stubs/providers/InertiaJsServiceProvider.stub ' ,
118+ app_path ('Providers/InertiaJsServiceProvider.php ' )
119+ );
120+ }
121+
122+ public static function registerInertiaServiceProvider ()
123+ {
124+ $ namespace = Str::replaceLast ('\\' , '' , Container::getInstance ()->getNamespace ());
125+
126+ $ appConfig = file_get_contents (config_path ('app.php ' ));
127+
128+ if (Str::contains ($ appConfig , $ namespace .'\\Providers \\InertiaJsServiceProvider::class ' )) {
129+ return ;
130+ }
131+
132+ $ lineEndingCount = [
133+ "\r\n" => substr_count ($ appConfig , "\r\n" ),
134+ "\r" => substr_count ($ appConfig , "\r" ),
135+ "\n" => substr_count ($ appConfig , "\n" ),
136+ ];
137+
138+ $ eol = array_keys ($ lineEndingCount , max ($ lineEndingCount ))[0 ];
139+
140+ file_put_contents (config_path ('app.php ' ), str_replace (
141+ "{$ namespace }\\Providers \\RouteServiceProvider::class, " .$ eol ,
142+ "{$ namespace }\\Providers \\RouteServiceProvider::class, " .$ eol ." {$ namespace }\Providers\InertiaJsServiceProvider::class, " .$ eol ,
143+ $ appConfig
144+ ));
145+
146+ file_put_contents (app_path ('Providers/InertiaJsServiceProvider.php ' ), str_replace (
147+ "namespace App\Providers; " ,
148+ "namespace {$ namespace }\Providers; " ,
149+ file_get_contents (app_path ('Providers/InertiaJsServiceProvider.php ' ))
150+ ));
151+ }
111152}
0 commit comments