load static method

SmartpubConfig load(
  1. String projectPath, {
  2. String? configPath,
})

Load config from file, fall back to defaults

Implementation

static SmartpubConfig load(String projectPath, {String? configPath}) {
  final File file = configPath != null
      ? File(configPath)
      : File('$projectPath/smartpub.yaml');

  if (!file.existsSync()) {
    if (configPath != null) {
      throw Exception('Config file not found at $configPath');
    }
    return const SmartpubConfig();
  }

  try {
    return checkedYamlDecode(
      file.readAsStringSync(),
      (m) => SmartpubConfig.fromJson(m!),
      sourceUrl: Uri.file(file.path),
    );
  } on ParsedYamlException catch (e) {
    stderr.writeln('❌ Config YAML parse error:\n${e.formattedMessage}');
    exit(ExitCodes.toolError); // Exit code 2 on bad config YAML format
  } catch (e) {
    stderr.writeln('❌ Failed to load config: $e');
    exit(ExitCodes.toolError);
  }
}