44
55use Illuminate \Support \Arr ;
66use Native \Laravel \Commands \LoadStartupConfigurationCommand ;
7+ use Native \Laravel \Commands \MigrateCommand ;
78use Native \Laravel \Commands \MinifyApplicationCommand ;
89use Native \Laravel \Logging \LogWatcher ;
910use Spatie \LaravelPackageTools \Package ;
@@ -16,6 +17,7 @@ public function configurePackage(Package $package): void
1617 $ package
1718 ->name ('nativephp ' )
1819 ->hasCommands ([
20+ MigrateCommand::class,
1921 MinifyApplicationCommand::class,
2022 LoadStartupConfigurationCommand::class,
2123 ])
@@ -28,6 +30,10 @@ public function packageRegistered()
2830 {
2931 $ this ->mergeConfigFrom ($ this ->package ->basePath ('/../config/nativephp-internal.php ' ), 'nativephp-internal ' );
3032
33+ $ this ->app ->singleton (MigrateCommand::class, function ($ app ) {
34+ return new MigrateCommand ($ app ['migrator ' ], $ app ['events ' ]);
35+ });
36+
3137 if (config ('nativephp-internal.running ' )) {
3238 $ this ->configureApp ();
3339 }
@@ -39,6 +45,20 @@ protected function configureApp()
3945 app (LogWatcher::class)->register ();
4046 }
4147
48+ $ this ->rewriteStoragePath ();
49+
50+ $ this ->rewriteDatabase ();
51+
52+ config (['session.driver ' => 'file ' ]);
53+ config (['queue.default ' => 'database ' ]);
54+ }
55+
56+ protected function rewriteStoragePath ()
57+ {
58+ if (config ('app.debug ' )) {
59+ return ;
60+ }
61+
4262 $ oldStoragePath = $ this ->app ->storagePath ();
4363
4464 $ this ->app ->useStoragePath (config ('nativephp-internal.storage_path ' ));
@@ -52,18 +72,28 @@ protected function configureApp()
5272 config ([$ key => $ newValue ]);
5373 }
5474 }
75+ }
76+
77+ public function rewriteDatabase ()
78+ {
79+ $ databasePath = config ('nativephp-internal.database_path ' );
80+
81+ if (config ('app.debug ' )) {
82+ $ databasePath = database_path ('nativephp.sqlite ' );
83+
84+ if (! file_exists ($ databasePath )) {
85+ touch ($ databasePath );
86+ }
87+ }
5588
5689 config (['database.connections.nativephp ' => [
5790 'driver ' => 'sqlite ' ,
5891 'url ' => env ('DATABASE_URL ' ),
59- 'database ' => config ( ' nativephp-internal.database_path ' ) ,
92+ 'database ' => $ databasePath ,
6093 'prefix ' => '' ,
6194 'foreign_key_constraints ' => env ('DB_FOREIGN_KEYS ' , true ),
6295 ]]);
6396
6497 config (['database.default ' => 'nativephp ' ]);
65- config (['session.driver ' => 'file ' ]);
66-
67- config (['queue.default ' => 'database ' ]);
6898 }
6999}
0 commit comments