parseConfigFile function

Future<Map<String, dynamic>> parseConfigFile(
  1. String clientId
)

Parses the configuration file for a specific client ID.

This function reads the config.json file located in the ./clonify/clones/[clientId]/ directory, decodes its JSON content, and returns it as a map. It also logs some key configuration details.

clientId The ID of the client whose configuration file is to be parsed.

Throws a FileSystemException if the configuration file does not exist. Throws a FormatException if the file content is not valid JSON.

Returns a Future<Map<String, dynamic>> representing the parsed configuration.

Implementation

Future<Map<String, dynamic>> parseConfigFile(String clientId) async {
  final configFile = File('./clonify/clones/$clientId/config.json');

  if (!configFile.existsSync()) {
    throw FileSystemException(
      'Config file not found for $clientId',
      configFile.path,
    );
  }

  final content = await configFile.readAsString();
  final config = jsonDecode(content) as Map<String, dynamic>;

  logger.i('📄 Loaded configuration:');
  logger.i('App Name: ${config['appName']}');
  logger.i('Primary Color: ${config['primaryColor']}');
  // logger.i('Base URL: ${config['baseUrl']}');

  return config;
}