loadHooks static method
Loads the top-level hooks section from rekeens.yaml.
Supports two syntaxes for each hook entry:
Simple string (applies to all generators):
hooks:
before_generate:
- echo "about to generate"
after_generate:
- dart format lib/
Map with run and optional when/description:
hooks:
after_generate:
- run: dart format lib/
when: [model, entity]
description: Format after model/entity generation
Implementation
static HookSet loadHooks({
String? workingDirectory,
String? homeDirectory,
Logger? log,
}) {
final effectiveLog = log ?? logger;
final configFile = _findConfigFile(
workingDirectory: workingDirectory,
homeDirectory: homeDirectory,
);
if (configFile == null) return const HookSet();
try {
final content = File(configFile).readAsStringSync();
final yamlMap = loadYaml(content);
if (yamlMap is! Map) return const HookSet();
final hooksSection = yamlMap['hooks'];
if (hooksSection is! YamlMap) return const HookSet();
final before = _parseHookList(hooksSection['before_generate']);
final after = _parseHookList(hooksSection['after_generate']);
return HookSet(beforeGenerate: before, afterGenerate: after);
} catch (error) {
effectiveLog.warn(
'Failed to parse hooks in rekeens.yaml at "$configFile": '
'$error. Ignoring hooks.',
);
return const HookSet();
}
}