getVersionFromConfig function
Retrieves the version number from a client's configuration file.
This function reads the config.json file for the specified clientId.
If the 'version' field is missing, it prompts the user to enter a new
version and updates the configuration file.
clientId The ID of the client for which to retrieve the version.
Throws a FileSystemException if the config file for the client is not found. Throws a FormatException if the config file content is not valid JSON.
Returns a Future<String> representing the version number.
Implementation
Future<String> getVersionFromConfig(String clientId) async {
final configFilePath = './clonify/clones/$clientId/config.json';
try {
final configFile = File(configFilePath);
if (!configFile.existsSync()) {
logger.e('❌ Config file not found.');
return '';
}
final configJson = await parseConfigFile('config');
if (configJson['version'] == null) {
// If version is not found, update the version in config.json
logger.e('❌ Version not found in config.json.');
final newVersion = promptUser('Enter the version number:', '1.0.0+1');
configJson['version'] = newVersion;
configFile.writeAsStringSync(jsonEncode(configJson));
}
return configJson['version'] ?? '';
} catch (e) {
logger.e('❌ Failed to read or parse config.json: $e');
return '';
}
}