Skip to content

Commit

Permalink
Allow adr template to be stored locally instead of using a Nuget Pack…
Browse files Browse the repository at this point in the history
…age (#217)

* Allow adr template to be stored locally instead of using a Nuget Package
* Update readme with instructions to store template file locally
  • Loading branch information
akselkvitberg authored Mar 21, 2024
1 parent 20a224c commit 1cde464
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 8 additions & 4 deletions Solutions/Endjin.Adr.Cli/Commands/New/NewAdrCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public override async Task<int> 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))
Expand Down Expand Up @@ -74,6 +75,8 @@ public override async Task<int> ExecuteAsync([NotNull] CommandContext context, [
{
rootConfigurationFileInfo.Directory.Create();
}

templatePath = config.TemplatePath;
}

if (string.IsNullOrEmpty(targetPath))
Expand All @@ -86,7 +89,7 @@ public override async Task<int> 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,
};
Expand Down Expand Up @@ -121,7 +124,7 @@ public override async Task<int> 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));

Expand All @@ -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();

Expand Down
2 changes: 2 additions & 0 deletions Solutions/Endjin.Adr.Cli/Configuration/AdrConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ namespace Endjin.Adr.Cli.Configuration;
public class AdrConfig
{
public string Path { get; set; }

public string TemplatePath { get; set; }
}

0 comments on commit 1cde464

Please sign in to comment.