1- import { Command , FetchHttpClient , Path , Url } from '@effect/platform' ;
1+ import { Command , FetchHttpClient , FileSystem , Path , Url } from '@effect/platform' ;
22import * as NodeContext from '@effect/platform-node/NodeContext' ;
33import * as NodeRuntime from '@effect/platform-node/NodeRuntime' ;
44import { Config , Console , Effect , pipe , Runtime } from 'effect' ;
@@ -7,6 +7,7 @@ import { autoUpdater } from 'electron-updater';
77import child_process from 'node:child_process' ;
88import os from 'node:os' ;
99import { Agent } from 'undici' ;
10+ import packageJson from '../../package.json' ;
1011import { CustomUpdateProvider , UpdateOptions } from './update' ;
1112
1213// Workaround to allow unlimited concurrent HTTP/1.1 connections
@@ -256,22 +257,56 @@ const desktop = pipe(
256257) ;
257258
258259const args = process . argv . slice ( process . defaultApp ? 2 : 1 ) ;
259- const cli = pipe (
260- Effect . gen ( function * ( ) {
261- const path = yield * Path . Path ;
260+ const cli = Effect . gen ( function * ( ) {
261+ const path = yield * Path . Path ;
262262
263- const dist = yield * pipe (
264- import . meta. resolve ( '@the-dev-tools/cli' ) ,
265- Url . fromString ,
266- Effect . flatMap ( path . fromFileUrl ) ,
267- ) ;
263+ const dist = yield * pipe ( import . meta. resolve ( '@the-dev-tools/cli' ) , Url . fromString , Effect . flatMap ( path . fromFileUrl ) ) ;
268264
269- yield * execFile ( path . join ( dist , 'cli' ) , args ) ;
265+ yield * execFile ( path . join ( dist , 'cli' ) , args ) ;
270266
271- app . quit ( ) ;
272- } ) ,
273- ) ;
267+ app . quit ( ) ;
268+ } ) ;
274269
275- const main = args . length > 0 ? cli : desktop ;
270+ const logPath = Effect . fn ( function * ( title : string , path : string ) {
271+ const fs = yield * FileSystem . FileSystem ;
272+ const exists = yield * pipe ( fs . access ( path , { ok : true } ) , Effect . isSuccess ) ;
273+ yield * Effect . log ( `${ title } - ${ path } - [${ exists ? 'OK' : 'N/A' } ]` ) ;
274+ } ) ;
275+
276+ const diagnostics = Effect . gen ( function * ( ) {
277+ const path = yield * Path . Path ;
278+
279+ yield * Effect . log ( `version ${ packageJson . version } ` ) ;
280+
281+ yield * logPath ( '__dirname' , __dirname ) ;
282+
283+ yield * logPath ( 'cwd' , process . cwd ( ) ) ;
284+
285+ yield * logPath ( 'app.getAppPath()' , app . getAppPath ( ) ) ;
286+
287+ const root = path . join ( app . getAppPath ( ) , '../..' ) ;
288+ yield * logPath ( 'root' , root ) ;
289+
290+ yield * logPath ( 'import.meta.filename' , import . meta. filename ) ;
291+
292+ const resolvedPath = import . meta. resolve ( '.' ) ;
293+ yield * Effect . log ( `import.meta.resolve - ${ resolvedPath } ` ) ;
294+
295+ const serverPath = yield * pipe (
296+ import . meta. resolve ( '@the-dev-tools/server' ) ,
297+ Url . fromString ,
298+ Effect . flatMap ( path . fromFileUrl ) ,
299+ ) ;
300+ yield * logPath ( '@the-dev-tools/server' , serverPath ) ;
301+ yield * logPath ( '@the-dev-tools/server unpacked' , serverPath . replaceAll ( 'app.asar' , 'app.asar.unpacked' ) ) ;
302+
303+ app . quit ( ) ;
304+ } ) ;
305+
306+ const main = Effect . gen ( function * ( ) {
307+ if ( args [ 0 ] === 'diagnostics' ) return yield * diagnostics ;
308+ if ( args . length > 0 ) return yield * cli ;
309+ return yield * desktop ;
310+ } ) ;
276311
277312pipe ( main , Effect . provide ( NodeContext . layer ) , Effect . provide ( FetchHttpClient . layer ) , NodeRuntime . runMain ) ;
0 commit comments