Skip to content

Commit

Permalink
Added support for custom templates with the msbuild integration
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Nov 15, 2017
1 parent 268375a commit e7d5380
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
18 changes: 15 additions & 3 deletions src/Generator/Tasks/EventSourceGeneratorTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ protected EventSourceGeneratorTaskBase(IConsole console, TemplateStorage templat
/// <value>The name of the template.</value>
public string TemplateName { get; set; }

/// <summary>
/// Gets or sets a custom template file
/// that shall be used to generate event sources.
/// </summary>
public string TemplateFile { get; set; }

/// <summary>
/// Analyzes the given <paramref name="project"/> and
/// generates the event source into the same project.
Expand Down Expand Up @@ -124,11 +130,17 @@ protected void GenerateEventSources(Project source, Project target)
/// </returns>
protected Template GetTemplate()
{
if (string.IsNullOrEmpty(TemplateName))
if(!string.IsNullOrEmpty(TemplateFile))
{
return _templateStorage.GetTemplate(Language);
return Template.FromFile(TemplateFile);
}
return _templateStorage.GetCustomTemplate(TemplateName);

if (!string.IsNullOrEmpty(TemplateName))
{
return _templateStorage.GetCustomTemplate(TemplateName);
}

return _templateStorage.GetTemplate(Language);
}
}
}
10 changes: 8 additions & 2 deletions src/Generator/Tasks/GeneratorConsoleConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public GeneratorConsoleConfiguration()
.WithName("recursive", 'r')
.And()
.Argument(t => t.TemplateName)
.WithName("template");
.WithName("template")
.And()
.Argument(t => t.TemplateFile)
.WithName("template-file");

Bind<ProjectEventSourceGeneratorTask>()
.AsDefault()
Expand All @@ -39,7 +42,10 @@ public GeneratorConsoleConfiguration()
.Position(1)
.And()
.Argument(t => t.TemplateName)
.WithName("template");
.WithName("template")
.And()
.Argument(t => t.TemplateFile)
.WithName("template-file");

Bind<ExportTemplateTask>()
.WithName("templates", "export")
Expand Down
5 changes: 3 additions & 2 deletions src/Thor.Generator.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
</PropertyGroup>

<Target Name="TargetName" BeforeTargets="CoreCompile">
<Exec Command="$(ThorGen) project -s &quot;$(SourceProject)&quot; -t &quot;$(TargetProject)&quot;" Condition="'$(TemplateName)' == ''" />
<Exec Command="$(ThorGen) project -s &quot;$(SourceProject)&quot; -t &quot;$(TargetProject)&quot; --template $(TemplateName)" Condition="'$(TemplateName)' != ''" />
<Exec Command="$(ThorGen) project -s &quot;$(SourceProject)&quot; -t &quot;$(TargetProject)&quot;" Condition="'$(TemplateName)' == '' AND '$(TemplateFile)' == ''" />
<Exec Command="$(ThorGen) project -s &quot;$(SourceProject)&quot; -t &quot;$(TargetProject)&quot; --template $(TemplateName)" Condition="'$(TemplateName)' != '' AND '$(TemplateFile)' == ''" />
<Exec Command="$(ThorGen) project -s &quot;$(SourceProject)&quot; -t &quot;$(TargetProject)&quot; --template-file $(TemplateName)" Condition="'$(TemplateName)' == '' AND '$(TemplateFile)' != ''" />
</Target>
</Project>

0 comments on commit e7d5380

Please sign in to comment.