From 1cde46407e92cb3f0dd051661455d94d55a06895 Mon Sep 17 00:00:00 2001 From: Aksel Kvitberg Date: Thu, 21 Mar 2024 12:31:08 +0100 Subject: [PATCH] Allow adr template to be stored locally instead of using a Nuget Package (#217) * Allow adr template to be stored locally instead of using a Nuget Package * Update readme with instructions to store template file locally --- README.md | 9 +++++++++ .../Endjin.Adr.Cli/Commands/New/NewAdrCommand.cs | 12 ++++++++---- Solutions/Endjin.Adr.Cli/Configuration/AdrConfig.cs | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ffeec25..08aca51 100644 --- a/README.md +++ b/README.md @@ -415,6 +415,15 @@ Then: `adr templates install` +#### Store template file locally +Optionally, store the template file file inside the repository, and specify the TemplatePath in the `adr.config.json` file. + +```json +{ + "templatePath": "./Docs/adr-template.md" +} +``` + ## Local System Details `adr` stores various configuration files and packages in an application profile folder created in: diff --git a/Solutions/Endjin.Adr.Cli/Commands/New/NewAdrCommand.cs b/Solutions/Endjin.Adr.Cli/Commands/New/NewAdrCommand.cs index 44e1ca4..3312a99 100644 --- a/Solutions/Endjin.Adr.Cli/Commands/New/NewAdrCommand.cs +++ b/Solutions/Endjin.Adr.Cli/Commands/New/NewAdrCommand.cs @@ -42,6 +42,7 @@ public override async Task ExecuteAsync([NotNull] CommandContext context, [ try { string targetPath = string.Empty; + string templatePath = null; // If the user hasn't specified the path to create the ADR if (!string.IsNullOrEmpty(settings.Path)) @@ -74,6 +75,8 @@ public override async Task ExecuteAsync([NotNull] CommandContext context, [ { rootConfigurationFileInfo.Directory.Create(); } + + templatePath = config.TemplatePath; } if (string.IsNullOrEmpty(targetPath)) @@ -86,7 +89,7 @@ public override async Task ExecuteAsync([NotNull] CommandContext context, [ Adr adr = new() { - Content = CreateNewDefaultTemplate(settings.Title, this.templateSettingsManager), + Content = CreateNewDefaultTemplate(settings.Title, this.templateSettingsManager, templatePath), RecordNumber = documents.Count == 0 ? 1 : documents.OrderBy(x => x.RecordNumber).Last().RecordNumber + 1, Title = settings.Title, }; @@ -121,7 +124,7 @@ public override async Task ExecuteAsync([NotNull] CommandContext context, [ return ReturnCodes.Ok; } - private static string CreateNewDefaultTemplate(string title, ITemplateSettingsManager templateSettingsManager) + private static string CreateNewDefaultTemplate(string title, ITemplateSettingsManager templateSettingsManager, string templatePath) { TemplateSettings templateSettings = templateSettingsManager.LoadSettings(nameof(TemplateSettings)); @@ -130,8 +133,9 @@ private static string CreateNewDefaultTemplate(string title, ITemplateSettingsMa throw new InvalidOperationException("Couldn't load the template settings. Environment may not be initialised"); } - TemplatePackageDetail template = templateSettings.MetaData.Details.Find(x => x.FullPath == templateSettings.DefaultTemplate); - string templateContents = File.ReadAllText(template.FullPath); + TemplatePackageDetail defaultTemplate = templateSettings.MetaData.Details.Find(x => x.FullPath == templateSettings.DefaultTemplate); + + string templateContents = File.ReadAllText(templatePath ?? defaultTemplate.FullPath); Regex yamlHeaderRegExp = YamlHeaderRegex(); diff --git a/Solutions/Endjin.Adr.Cli/Configuration/AdrConfig.cs b/Solutions/Endjin.Adr.Cli/Configuration/AdrConfig.cs index 10863e8..c083f4e 100644 --- a/Solutions/Endjin.Adr.Cli/Configuration/AdrConfig.cs +++ b/Solutions/Endjin.Adr.Cli/Configuration/AdrConfig.cs @@ -7,4 +7,6 @@ namespace Endjin.Adr.Cli.Configuration; public class AdrConfig { public string Path { get; set; } + + public string TemplatePath { get; set; } } \ No newline at end of file