Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 10 additions & 12 deletions CompiledHandlebars.Cli2/CompiledHandlebars.Core.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,24 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Platforms>AnyCPU;x64</Platforms>
<StartupObject>CompiledHandlebars.Core.Cli.Program</StartupObject>
<LangVersion>default</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Buildalyzer" Version="5.0.0" />
<PackageReference Include="Buildalyzer.Logger" Version="5.0.0" />
<PackageReference Include="Buildalyzer.Workspaces" Version="5.0.0" />
<PackageReference Include="Microsoft.Build" Version="17.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PackageReference Include="Buildalyzer" Version="8.0.0" />
<PackageReference Include="Buildalyzer.Logger" Version="8.0.0" />
<PackageReference Include="Buildalyzer.Workspaces" Version="8.0.0" />
<PackageReference Include="Microsoft.Build" Version="18.0.2" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="18.0.2" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="5.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="4.14.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="System.Diagnostics.Debug" Version="4.3.0" />
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Compiler\CompiledHandlebars.Compiler.csproj" />
Expand Down
95 changes: 86 additions & 9 deletions CompiledHandlebars.Cli2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System.Linq;
using Buildalyzer.Workspaces;
using Buildalyzer;
using Buildalyzer.Environment;
using Microsoft.Extensions.Logging;

namespace CompiledHandlebars.Core.Cli
{
Expand Down Expand Up @@ -125,6 +127,16 @@ public static int Main(string[] args)
Console.WriteLine(outerEx);
return -1;
}

if (_ExitCode == 0)
Console.WriteLine("Compilation successful!");
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine($"Compilation failed");
Console.ResetColor();
}

Console.WriteLine($"Exit-Code: {_ExitCode}");
return _ExitCode;
}
Expand All @@ -149,6 +161,9 @@ private static void PrintUnknownExtension(string ext)
private static void CompileProject(CompilerOptions options)
{
Console.WriteLine($"Loading project '{options.ProjectFile}'...");
//string x = Console.ReadLine();
Stopwatch sw = new Stopwatch();
sw.Start();
var properties = new Dictionary<string, string>() {
{ "AdditionalFileItemNames", "none" }
};
Expand All @@ -158,18 +173,66 @@ private static void CompileProject(CompilerOptions options)
List<string> handlebarsFiles;
if (options.NetCoreProject)
{
StringWriter log = new StringWriter();
try
{
AnalyzerManager manager = new AnalyzerManager();
AnalyzerManagerOptions analyzerOptions = new AnalyzerManagerOptions
{
LogWriter = log
};
AnalyzerManager manager = new AnalyzerManager(analyzerOptions);

IProjectAnalyzer analyzer = manager.GetProject(options.ProjectFile);
workspace = analyzer.GetWorkspace();

//workspace = analyzer.GetWorkspace();
ILogger logger = manager.LoggerFactory?.CreateLogger<AdhocWorkspace>();
workspace = new AdhocWorkspace();
workspace.WorkspaceChanged += (sender, args) => logger?.LogDebug($"Workspace changed: {args.Kind.ToString()}{System.Environment.NewLine}");
workspace.WorkspaceFailed += (sender, args) => logger?.LogError($"Workspace failed: {args.Diagnostic}{System.Environment.NewLine}");
IAnalyzerResult ar = analyzer.Build(new EnvironmentOptions() { Restore = true }).FirstOrDefault();
ar.AddToWorkspace(workspace);
Console.WriteLine($"AR: {ar.References.Length}");
//foreach (string s in ar.References)
//{
// if (File.Exists(s))
// {
// PortableExecutableReference ss = MetadataReference.CreateFromFile(s);
// if (ss != null)
// {// Console.WriteLine($"MeRef: {ss.FilePath}");
// }
// else
// Console.WriteLine($"*no Ref: {s}");
// }
// else
// Console.WriteLine($"*not exist: {s}");
//}

project = workspace.CurrentSolution.Projects.ElementAt(0);
Console.WriteLine("Ok!");
sw.Stop();
Console.WriteLine($"Ok! {sw.Elapsed}");
//Console.WriteLine($"Log: {log}");
//Console.WriteLine($"Project document count: {project.DocumentIds.Count}");
//Console.WriteLine($"MetadataReferences count: {project.MetadataReferences.Count}");

////test stiwa
//Document d1 = project.Documents.FirstOrDefault(i => i.Name == "IPageModel.cs");
//Document d2 = project.Documents.FirstOrDefault(i => i.Name == "AdminController.cs");

//Console.WriteLine($"d1: {d1 != null}");
//Console.WriteLine($"d2: {d2 != null}");

//Compilation c1 = project.GetCompilationAsync().GetAwaiter().GetResult();
//INamedTypeSymbol symbol = c1.GetTypeByMetadataName("StiftungWarentest.Website.Models.Page.IPageModel");
//Console.WriteLine($"symbol: {symbol != null}");

//MetadataReference a = project.MetadataReferences.FirstOrDefault(m => m.Display.Contains("StiftungWarentest.Website.Models.dll"));
//Console.WriteLine($"MetadataReference: {a != null}");

handlebarsFiles = new DirectoryInfo(Path.GetDirectoryName(Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), options.ProjectFile)))).GetFiles("*.hbs", SearchOption.AllDirectories).Where(f => ShouldCompileFile(f.FullName, options)).Select(f => f.FullName).ToList();
}
catch (Exception ex)
{
Console.WriteLine($"Following errors occured: {Environment.NewLine}{ex}");
Console.WriteLine($"Following errors occured: {Environment.NewLine}{ex} - {log.ToString()}");
throw;
}
}
Expand Down Expand Up @@ -274,7 +337,7 @@ private static void CompileSolution(CompilerOptions options)
if (handlebarsFiles.Count > 0)
anyHbsFilesFound = true;
}

if (handlebarsFiles.Any())
{
workspace = CompileHandlebarsFiles(project, workspace, handlebarsFiles, options);
Expand Down Expand Up @@ -410,7 +473,9 @@ private static Workspace CompileHandlebarsFiles(Project project, Workspace works
{
foreach (var err in partialErrors)
{
Console.Error.WriteLine(err);
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine($"*** {err}");
Console.ResetColor();
}
}
}
Expand All @@ -419,7 +484,9 @@ private static Workspace CompileHandlebarsFiles(Project project, Workspace works

private static void PrintError(HandlebarsException error)
{
Console.Error.WriteLine($"Compilation failed: {error.Message}");
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine($"*** Compilation failed: {error.Message}");
Console.ResetColor();
}

/// <summary>
Expand All @@ -440,8 +507,18 @@ private static Tuple<string, IEnumerable<HandlebarsException>> CompileHandlebars
}
else
{
Console.WriteLine($"Compiling '{name}' ({@namespace})");
return HbsCompiler.Compile(content, @namespace, name, containingProject);
Tuple<string, IEnumerable<HandlebarsException>> result = HbsCompiler.Compile(content, @namespace, name, containingProject);
bool hasError = !options.DryRun && (result?.Item2?.Any() ?? false);
if (hasError)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"*** Compiling '{name}' ({@namespace})");
Console.ResetColor();
}
else
Console.WriteLine($"Compiling '{name}' ({@namespace})");

return result;
}
}

Expand Down

This file was deleted.

18 changes: 18 additions & 0 deletions CompiledHandlebars.Cli2/Properties/PublishProfiles/linux.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>x64</Platform>
<PublishDir>C:\D\hbc\linux</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
<!-- false: analyser lädt sonst nicht ;-( -->
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>
</Project>
19 changes: 19 additions & 0 deletions CompiledHandlebars.Cli2/Properties/PublishProfiles/windows.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>C:\D\hbc\windows</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net10.0</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
<!-- analyser lädt sonst nicht ;-( -->
<PublishReadyToRun>true</PublishReadyToRun>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>
</Project>
14 changes: 13 additions & 1 deletion CompiledHandlebars.Cli2/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@
"profiles": {
"CompiledHandlebars.Cli2": {
"commandName": "Project",
"commandLineArgs": "-c -d -f -eC:\\dev\\sw.git\\StiftungWarentest.Website\\node_modules -eC:\\dev\\sw.git\\StiftungWarentest.Website\\assets C:\\dev\\sw.git\\StiftungWarentest.Website\\StiftungWarentest.Website.csproj"
// "commandLineArgsOld": "-c -d -eC:\\dev\\Repos\\StiftungWarentest.Web\\StiftungWarentest.Website\\node_modules -eC:\\dev\\Repos\\StiftungWarentest.Web\\StiftungWarentest.Website\\assets C:\\dev\\Repos\\StiftungWarentest.Web\\StiftungWarentest.Website\\StiftungWarentest.Website.csproj",

// "commandLineArgs": "-c -d C:\\dev\\Repos\\Stiwa2\\website\\src\\StiftungWarentest.Website\\StiftungWarentest.Website.csproj"
"commandLineArgs": "-c -d C:\\dev\\Repos\\Stiwa3\\mono\\website\\src\\StiftungWarentest.Website\\StiftungWarentest.Website.csproj"
},
"WSL": {
"commandName": "WSL2",
"distributionName": "",
// "commandLineArgsOld": "CompiledHandlebars.Core.Cli.dll -c -d -e/mnt/c/dev/Repos/StiftungWarentest.Web/StiftungWarentest.Website/ViewsRelaunch -e/mnt/c/dev/Repos/StiftungWarentest.Web/StiftungWarentest.Website/Views/Module -e/mnt/c/dev/Repos/StiftungWarentest.Web/StiftungWarentest.Website/Views/Shared /mnt/c/dev/Repos/StiftungWarentest.Web/StiftungWarentest.Website/StiftungWarentest.Website.csproj",
// "commandLineArgsNew": "CompiledHandlebars.Core.Cli.dll -c -d -e/mnt/c/dev/Repos/Stiwa/Web/website/src/StiftungWarentest.Website/ViewsRelaunch -e/mnt/c/dev/Repos/Stiwa/Web/website/src/StiftungWarentest.Website/Views/Module -e/mnt/c/dev/Repos/Stiwa/Web/website/src/StiftungWarentest.Website/Views/Shared /mnt/c/dev/Repos/Stiwa/Web/website/src/StiftungWarentest.Website/StiftungWarentest.Website.csproj",
//"commandLineArgs": "CompiledHandlebars.Core.Cli.dll -c -d /mnt/c/dev/Repos/Stiwa2/website/src/StiftungWarentest.Website/StiftungWarentest.Website.csproj",
"commandLineArgs": "CompiledHandlebars.Core.Cli.dll -c -d /mnt/c/dev/Repos/Stiwa3/mono/website/src/StiftungWarentest.Website/StiftungWarentest.Website.csproj"
// "commandLineArgsAllOld": "CompiledHandlebars.Core.Cli.dll -c -d /mnt/c/dev/Repos/StiftungWarentest.Web/StiftungWarentest.Website/StiftungWarentest.Website.csproj"
}
}
}
16 changes: 8 additions & 8 deletions CompiledHandlebars.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30611.23
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompiledHandlebars.Compiler", "Compiler\CompiledHandlebars.Compiler.csproj", "{55E767E0-44F0-4297-9A00-7211B424BE03}"
EndProject
Expand All @@ -19,14 +19,14 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|Any CPU.Build.0 = Debug|Any CPU
{55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|Any CPU.ActiveCfg = Debug|x64
{55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|Any CPU.Build.0 = Debug|x64
{55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|x64.ActiveCfg = Debug|x64
{55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|x64.Build.0 = Debug|x64
{55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|x86.ActiveCfg = Debug|Any CPU
{55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|x86.Build.0 = Debug|Any CPU
{55E767E0-44F0-4297-9A00-7211B424BE03}.Release|Any CPU.ActiveCfg = Release|Any CPU
{55E767E0-44F0-4297-9A00-7211B424BE03}.Release|Any CPU.Build.0 = Release|Any CPU
{55E767E0-44F0-4297-9A00-7211B424BE03}.Release|Any CPU.ActiveCfg = Release|x64
{55E767E0-44F0-4297-9A00-7211B424BE03}.Release|Any CPU.Build.0 = Release|x64
{55E767E0-44F0-4297-9A00-7211B424BE03}.Release|x64.ActiveCfg = Release|x64
{55E767E0-44F0-4297-9A00-7211B424BE03}.Release|x64.Build.0 = Release|x64
{55E767E0-44F0-4297-9A00-7211B424BE03}.Release|x86.ActiveCfg = Release|Any CPU
Expand All @@ -39,8 +39,8 @@ Global
{A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Debug|x86.Build.0 = Debug|Any CPU
{A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|Any CPU.Build.0 = Release|Any CPU
{A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|x64.ActiveCfg = Release|Any CPU
{A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|x64.Build.0 = Release|Any CPU
{A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|x64.ActiveCfg = Release|x64
{A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|x64.Build.0 = Release|x64
{A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|x86.ActiveCfg = Release|Any CPU
{A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
14 changes: 10 additions & 4 deletions Compiler/CompiledHandlebars.Compiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,23 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<DebugType>portable</DebugType>
</PropertyGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PackageReference Include="Microsoft.CodeAnalysis" Version="5.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="4.14.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.0.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Pegasus" Version="4.1.0" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Introspection/RoslynIntrospector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private Compilation GetCompilationForProject(Project proj)
Compilation comp;
if (proj.TryGetCompilation(out comp))
return comp;
else return proj.GetCompilationAsync().Result;
else return proj.GetCompilationAsync().GetAwaiter().GetResult();
}

public INamedTypeSymbol GetTypeSymbol(string fullTypeName)
Expand Down
Loading