private function findThemeDirectory($themeConfig, $path = null)
    {
        // check if there are additional theme paths in the config
        $themeDirectoriesConfig = $this->config->get('theme-directories', 'api');
        if ($themeDirectoriesConfig) {
            if (\is_array($themeDirectoriesConfig)) {
                $themesDirectories = $themeDirectoriesConfig;
            } else {
                throw new InvalidArgumentException("Invalid value for theme config 'theme-directories'");
            }
        } else {
            $themesDirectories = [];
        }

        $themesDirectories[] = $this->templatesPath.'/Api/themes';
        $this->themesDirectories = $themesDirectories;

        // check if the path was set from the command
        if (!empty($path)) {
            if (file_exists($path) && is_dir($path)) {
                return $path;
            } else {
                throw new InvalidArgumentException(
                    sprintf(
                        "Invalid value for option 'theme-path': the theme '%s' was not found or is not a valid theme.",
                        $path
                    )
                );
            }
        }

        if (!isset($themeConfig['name']) || !$themeConfig['name']) {
            throw new ConfigException(
                'There is no theme neither in the the theme config nor as a command line argument'
            );
        }

        return $this->findThemePathByName($themeConfig['name']);
    }