-- | During initialization we only know where the project is, nothing more.
initializeProject
    :: FilePath
    -- ^ Absolute path to YX executable.
    -> ProjectRoot
    -- ^ Absolute path to project root directory. Everthing initiation does is
    -- relative to this directory.
    -> IO ProjectConfig
initializeProject yxExe root = do
    possibleConfig <- detectYxConfig root
    cfgRef <- newIORef (Nothing :: Maybe ProjectConfig)
    doYxStuff cfgRef yxExe root defaultYxConfig $ (root </>) <$> possibleConfig
    readIORef cfgRef >>= \case
        Nothing -> readCachedYxConfig $ yxStuffFile root CachedStuff "config.bin"
        Just cfg -> pure cfg
  where
    defaultYxConfig = root </> NonEmpty.head yxConfigs
        -- First file is considered to be the default. See 'yxConfigs' for more
        -- details.
initializeProject
    :: FilePath
    -- ^ Absolute path to YX executable.
    -> ProjectRoot
    -- ^ Absolute path to project root directory. Everthing initiation does is
    -- relative to this directory.
    -> IO ProjectConfig
initializeProject yxExe root = do
    possibleConfig <- detectYxConfig root
    cfgRef <- newIORef (Nothing :: Maybe ProjectConfig)
    doYxStuff cfgRef yxExe root defaultYxConfig $ (root </>) <$> possibleConfig
    readIORef cfgRef >>= \case
        Nothing -> readCachedYxConfig $ yxStuffFile root CachedStuff "config.bin"
        Just cfg -> pure cfg
  where
    defaultYxConfig = root </> NonEmpty.head yxConfigs
        -- First file is considered to be the default. See 'yxConfigs' for more
        -- details.
initializeProject yxExe root = do
    possibleConfig <- detectYxConfig root
    cfgRef <- newIORef (Nothing :: Maybe ProjectConfig)
    doYxStuff cfgRef yxExe root defaultYxConfig $ (root </>) <$> possibleConfig
    readIORef cfgRef >>= \case
        Nothing -> readCachedYxConfig $ yxStuffFile root CachedStuff "config.bin"
        Just cfg -> pure cfg
  where
    defaultYxConfig = root </> NonEmpty.head yxConfigs
        -- First file is considered to be the default. See 'yxConfigs' for more
        -- details.