Logo GenPRES

AppPath Module

Resolves the application root directory once and returns the root path and the paths of the data, cache, zindex, logs and interactions directories. The root is the directory that holds the data directory, so the development server, a published binary, the Docker container and the test projects all use the same paths. The root is the first of: the directory named by the GENPRES_ROOT environment variable, when that directory exists; the directory of a .env file, searched upward from the current directory and then from the assembly location; the parent of a data/zindex directory, searched upward from the assembly location and then from the current directory; else the current directory, with a warning. The searches for the .env file and the data/zindex directory read the file system directly and do not need Env.loadDotEnv to have run, so test projects and F# scripts find the same root without setup.

Functions and values

Function or value Description

AppPath.GENPRES_ROOT

Full Usage: AppPath.GENPRES_ROOT

Returns: string

Name of the environment variable that, when set, forces the application root explicitly. It must point at the directory containing data/ (for example /app in the Docker container).

Returns: string

AppPath.cacheDir ()

Full Usage: AppPath.cacheDir ()

Parameters:
    () : unit

Returns: string

The data/cache/ directory.

() : unit
Returns: string

AppPath.dataDir ()

Full Usage: AppPath.dataDir ()

Parameters:
    () : unit

Returns: string

The data/ directory under the application root.

() : unit
Returns: string

AppPath.hasEnv dir

Full Usage: AppPath.hasEnv dir

Parameters:
    dir : string - The directory to test.

Returns: bool true if dir/.env exists.

True when dir directly contains a .env file.

dir : string

The directory to test.

Returns: bool

true if dir/.env exists.

AppPath.hasZindex dir

Full Usage: AppPath.hasZindex dir

Parameters:
    dir : string - The directory to test.

Returns: bool true if dir/data/zindex exists.

True when dir contains a data/zindex sub-directory.

dir : string

The directory to test.

Returns: bool

true if dir/data/zindex exists.

AppPath.interactionsDir ()

Full Usage: AppPath.interactionsDir ()

Parameters:
    () : unit

Returns: string

The data/cache/interactions/ directory.

() : unit
Returns: string

AppPath.logsDir ()

Full Usage: AppPath.logsDir ()

Parameters:
    () : unit

Returns: string

The data/logs/ directory.

() : unit
Returns: string

AppPath.resolveRoot ()

Full Usage: AppPath.resolveRoot ()

Parameters:
    () : unit

Returns: string

Resolve the application root from the live environment, current directory, and assembly location. Falls back to the current directory (emitting a warning) when no strategy succeeds.

() : unit
Returns: string

AppPath.root

Full Usage: AppPath.root

Returns: Lazy<string>

Lazily resolved, memoized application root. Resolution is deferred so that any Env.loadDotEnv() setting GENPRES_ROOT runs first.

Returns: Lazy<string>

AppPath.rootPath ()

Full Usage: AppPath.rootPath ()

Parameters:
    () : unit

Returns: string

The resolved application root directory (the directory containing data/).

() : unit
Returns: string

AppPath.tryGetRootInternal genpresRoot currentDir assemblyBaseDir

Full Usage: AppPath.tryGetRootInternal genpresRoot currentDir assemblyBaseDir

Parameters:
    genpresRoot : string option - The GENPRES_ROOT override value, if any.
    currentDir : string - The current working directory to search from.
    assemblyBaseDir : string - The assembly base directory to search from.

Returns: string option The resolved root directory, or None if no strategy succeeds.

Resolve the application root from the three sources given explicitly. Pure: takes the GENPRES_ROOT value, the current directory, and the assembly base directory, so it can be exercised deterministically in tests. Returns None when every strategy fails; the caller decides the final fallback.

genpresRoot : string option

The GENPRES_ROOT override value, if any.

currentDir : string

The current working directory to search from.

assemblyBaseDir : string

The assembly base directory to search from.

Returns: string option

The resolved root directory, or None if no strategy succeeds.

AppPath.zindexDir ()

Full Usage: AppPath.zindexDir ()

Parameters:
    () : unit

Returns: string

The data/zindex/ directory.

() : unit
Returns: string

Type something to start searching.