@@ -24,16 +24,17 @@ const bootstrapCache = join(app.getPath('userData'), 'bootstrap', 'cache');
24
24
const argumentEnv = getArgumentEnv ( ) ;
25
25
const appPath = getAppPath ( ) ;
26
26
mkdirpSync ( bootstrapCache ) ;
27
- function runningProdVersion ( ) {
28
- return existsSync ( join ( appPath , 'build' , '__nativephp_app_bundle' ) ) ;
29
- }
30
27
function runningSecureBuild ( ) {
31
28
return existsSync ( join ( appPath , 'build' , '__nativephp_app_bundle' ) ) ;
32
29
}
33
30
function shouldMigrateDatabase ( store ) {
34
31
return store . get ( 'migrated_version' ) !== app . getVersion ( )
35
32
&& process . env . NODE_ENV !== 'development' ;
36
33
}
34
+ function shouldOptimize ( store ) {
35
+ return store . get ( 'optimized_version' ) !== app . getVersion ( )
36
+ && process . env . NODE_ENV !== 'development' ;
37
+ }
37
38
function getPhpPort ( ) {
38
39
return __awaiter ( this , void 0 , void 0 , function * ( ) {
39
40
return yield getPort ( {
@@ -175,11 +176,11 @@ function getDefaultEnvironmentVariables(secret, apiPort) {
175
176
NATIVEPHP_VIDEOS_PATH : getPath ( 'videos' ) ,
176
177
NATIVEPHP_RECENT_PATH : getPath ( 'recent' ) ,
177
178
} ;
178
- if ( runningProdVersion ( ) ) {
179
+ if ( runningSecureBuild ( ) ) {
179
180
variables . APP_SERVICES_CACHE = join ( bootstrapCache , 'services.php' ) ;
180
181
variables . APP_PACKAGES_CACHE = join ( bootstrapCache , 'packages.php' ) ;
181
182
variables . APP_CONFIG_CACHE = join ( bootstrapCache , 'config.php' ) ;
182
- variables . APP_ROUTES_CACHE = join ( bootstrapCache , 'routes.php' ) ;
183
+ variables . APP_ROUTES_CACHE = join ( bootstrapCache , 'routes-v7 .php' ) ;
183
184
variables . APP_EVENTS_CACHE = join ( bootstrapCache , 'events.php' ) ;
184
185
}
185
186
return variables ;
@@ -202,18 +203,31 @@ function serveApp(secret, apiPort, phpIniSettings) {
202
203
cwd : appPath ,
203
204
env
204
205
} ;
205
- const store = new Store ( ) ;
206
+ const store = new Store ( {
207
+ name : 'nativephp' ,
208
+ } ) ;
206
209
if ( ! runningSecureBuild ( ) ) {
207
210
callPhpSync ( [ 'artisan' , 'storage:link' , '--force' ] , phpOptions , phpIniSettings ) ;
208
211
}
209
- if ( runningProdVersion ( ) ) {
212
+ if ( shouldOptimize ( store ) ) {
210
213
console . log ( 'Caching view and routes...' ) ;
211
- callPhpSync ( [ 'artisan' , 'optimize' ] , phpOptions , phpIniSettings ) ;
214
+ let result = callPhpSync ( [ 'artisan' , 'optimize' ] , phpOptions , phpIniSettings ) ;
215
+ if ( result . status !== 0 ) {
216
+ console . error ( 'Failed to cache view and routes:' , result . stderr . toString ( ) ) ;
217
+ }
218
+ else {
219
+ store . set ( 'optimized_version' , app . getVersion ( ) ) ;
220
+ }
212
221
}
213
222
if ( shouldMigrateDatabase ( store ) ) {
214
223
console . log ( 'Migrating database...' ) ;
215
- callPhpSync ( [ 'artisan' , 'migrate' , '--force' ] , phpOptions , phpIniSettings ) ;
216
- store . set ( 'migrated_version' , app . getVersion ( ) ) ;
224
+ let result = callPhpSync ( [ 'artisan' , 'migrate' , '--force' ] , phpOptions , phpIniSettings ) ;
225
+ if ( result . status !== 0 ) {
226
+ console . error ( 'Failed to migrate database:' , result . stderr . toString ( ) ) ;
227
+ }
228
+ else {
229
+ store . set ( 'migrated_version' , app . getVersion ( ) ) ;
230
+ }
217
231
}
218
232
if ( process . env . NODE_ENV === 'development' ) {
219
233
console . log ( 'Skipping Database migration while in development.' ) ;
0 commit comments