getConfig function
Reads sg_cli.yaml from the current directory and parses it into an SgConfig.
Returns null if there's no pubspec.yaml (so this isn't a Flutter project),
if sg_cli.yaml is missing or incomplete, or if it can't be parsed.
Implementation
SgConfig? getConfig() {
final pubspecFile = File('pubspec.yaml');
if (!pubspecFile.existsSync()) {
ConsoleLogger.error("Sorry, This is not a flutter project");
return null;
}
final pubspec = File('sg_cli.yaml');
try {
if (pubspec.existsSync()) {
final lines = pubspec.readAsLinesSync();
final version = getSingleLineValueFromLines(lines: lines, key: 'version');
final routePaths = getMultilineValueFromLines(lines: lines, key: 'route_paths') ?? <String>[];
if (version != null && routePaths.isNotEmpty) {
final sgConfig = SgConfig(
version: version,
routePaths: routePaths,
);
return sgConfig;
}
}
} catch (e) {
return null;
}
return null;
}