Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Kinetix.Tools.Core + T4 and parameters singleton removal + .NET Core #1

Merged
merged 8 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions Kinetix.SpaServiceGenerator/Kinetix.SpaServiceGenerator.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputType>Exe</OutputType>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net471</TargetFrameworks>
<OutputType>Exe</OutputType>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Buildalyzer.Workspaces" Version="0.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Kinetix.Tools.Common\Kinetix.Tools.Common.csproj" />
</ItemGroup>

</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Kinetix.Tools.Common\Kinetix.Tools.Common.csproj" />
</ItemGroup>
</Project>
28 changes: 25 additions & 3 deletions Kinetix.SpaServiceGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
#if NETCOREAPP2_1
using Buildalyzer;
using Buildalyzer.Workspaces;
#endif
using Kinetix.SpaServiceGenerator.Model;
using Kinetix.Tools.Common;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
#if NET471
using Microsoft.CodeAnalysis.MSBuild;
#endif

namespace Kinetix.SpaServiceGenerator
{
Expand Down Expand Up @@ -40,13 +45,21 @@ public static async Task Main(string[] args)
_projectName = args[2];
_kinetix = args[3];

var solution = new AnalyzerManager(_solutionPath).GetWorkspace().CurrentSolution;

Solution solution = null;
#if NET471
solution = await MSBuildWorkspace.Create().OpenSolutionAsync(_solutionPath);
#endif

#if NETCOREAPP2_1
solution = new AnalyzerManager(_solutionPath).GetWorkspace().CurrentSolution;

// Weirdly, I have a lot of duplicate project references after loading a solution, so this is a quick hack to fix that.
foreach (var project in solution.Projects)
{
solution = solution.WithProjectReferences(project.Id, project.ProjectReferences.Distinct());
}
#endif

// If path is not to services add "standard" path
var outputPath = _serviceRoot.EndsWith("services") ? _serviceRoot : $"{_serviceRoot}/app/services";
Expand All @@ -61,9 +74,18 @@ public static async Task Main(string[] args)
var syntaxTree = await controller.GetSyntaxTreeAsync();
var controllerClass = GetClassDeclaration(syntaxTree);

IReadOnlyList<string> folders = null;
#if NET471
folders = controller.Folders;
#endif
#if NETCOREAPP2_1
var parts = Path.GetRelativePath(controller.Project.FilePath, controller.FilePath).Split(@"\");
folders = parts.Skip(1).Take(parts.Length - 2).ToList();
#endif

var firstFolder = frontEnds.Count() > 1 ? $"/{controller.Project.Name.Split('.')[1].ToDashCase()}" : string.Empty;
var secondFolder = controller.Folders.Count > 1 ? $"/{string.Join("/", controller.Folders.Skip(1).Select(f => f.ToDashCase()))}" : string.Empty;
var folderCount = (frontEnds.Count() > 1 ? 1 : 0) + controller.Folders.Count;
var secondFolder = folders.Count > 1 ? $"/{string.Join("/", folders.Skip(1).Select(f => f.ToDashCase()))}" : string.Empty;
var folderCount = (frontEnds.Count() > 1 ? 1 : 0) + folders.Count - 1;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used to generate the JS imports in the service files, and I noticed a "-1" was missing (my Folders.Count was always 0 instead of always 1, so I didn't catch it).
I hope this works for your folder hierarchy


var controllerName = $"{firstFolder}{secondFolder}/{controllerClass.Identifier.ToString().Replace("Controller", string.Empty).ToDashCase()}.ts".Substring(1);

Expand Down