loadFromDirectory method
Loads a template from a directory containing a template.yaml file.
Implementation
Template loadFromDirectory(Directory directory) {
if (!directory.existsSync()) {
throw TemplateException(
'Template directory does not exist: ${directory.path}');
}
final yamlFile = File(p.join(directory.path, 'template.yaml'));
if (!yamlFile.existsSync()) {
throw TemplateException(
'Template configuration file not found at: ${yamlFile.path}');
}
try {
final content = yamlFile.readAsStringSync();
final config = TemplateConfig.fromYamlString(content);
return Template.fromConfig(config, path: directory.path);
} catch (e) {
if (e is CliException) rethrow;
throw TemplateException(
'Failed to load template at ${directory.path}: $e');
}
}