Skip to content

Commit

Permalink
upgraded libs - added catching error on file generation and logging them
Browse files Browse the repository at this point in the history
  • Loading branch information
AdaskoTheBeAsT committed Jan 14, 2024
1 parent 5177ce8 commit 2e7dd7c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 44 deletions.
10 changes: 5 additions & 5 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.8.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14" PrivateAssets="all" />
<PackageReference Include="Puma.Security.Rules.2022" Version="2.4.23" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="4.7.0" PrivateAssets="all" />
<PackageReference Include="Roslynator.CodeAnalysis.Analyzers" Version="4.7.0" PrivateAssets="all" />
<PackageReference Include="Roslynator.Formatting.Analyzers" Version="4.7.0" PrivateAssets="all" />
<PackageReference Include="Roslynator.Analyzers" Version="4.9.0" PrivateAssets="all" />
<PackageReference Include="Roslynator.CodeAnalysis.Analyzers" Version="4.9.0" PrivateAssets="all" />
<PackageReference Include="Roslynator.Formatting.Analyzers" Version="4.9.0" PrivateAssets="all" />
<!--<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.7" PrivateAssets="all" />-->
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.15.0.81779" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507" PrivateAssets="all" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.16.0.82469" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="all" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions src/Tests/Typewriter.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,23 @@
<Version>4.7.0</Version>
</PackageReference>
<PackageReference Include="xunit">
<Version>2.6.3</Version>
<Version>2.6.5</Version>
</PackageReference>
<PackageReference Include="xunit.core">
<Version>2.6.3</Version>
<Version>2.6.5</Version>
</PackageReference>
<PackageReference Include="xunit.runner.console">
<Version>2.6.3</Version>
<Version>2.6.5</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.runner.msbuild">
<Version>2.6.3</Version>
<Version>2.6.5</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio">
<Version>2.5.5</Version>
<Version>2.5.6</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
20 changes: 10 additions & 10 deletions src/Typewriter/CodeModel/Implementation/PropertyImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public sealed class PropertyImpl : Property
{
private readonly IPropertyMetadata _metadata;

private IAttributeCollection _attributes;

private DocComment _docComment;

private Type _type;

private PropertyImpl(IPropertyMetadata metadata, Item parent, Settings settings)
{
_metadata = metadata;
Expand Down Expand Up @@ -38,26 +44,20 @@ private PropertyImpl(IPropertyMetadata metadata, Item parent, Settings settings)

public override bool IsVirtual => _metadata.IsVirtual;

private IAttributeCollection _attributes;

public override IAttributeCollection Attributes => _attributes ?? (_attributes = AttributeImpl.FromMetadata(_metadata.Attributes, this, Settings));

private DocComment _docComment;

public override DocComment DocComment => _docComment ?? (_docComment = DocCommentImpl.FromXml(_metadata.DocComment, this));

private Type _type;

public override Type Type => _type ?? (_type = TypeImpl.FromMetadata(_metadata.Type, this, Settings));

public override string ToString()
public static IPropertyCollection FromMetadata(IEnumerable<IPropertyMetadata> metadata, Item parent, Settings settings)
{
return Name;
return new PropertyCollectionImpl(metadata.Select(p => new PropertyImpl(p, parent, settings)));
}

public static IPropertyCollection FromMetadata(IEnumerable<IPropertyMetadata> metadata, Item parent, Settings settings)
public override string ToString()
{
return new PropertyCollectionImpl(metadata.Select(p => new PropertyImpl(p, parent, settings)));
return Name;
}
}
}
37 changes: 22 additions & 15 deletions src/Typewriter/Generation/Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,25 +167,32 @@ public bool RenderFile(File[] files)

protected virtual void WriteFile(string outputPath, string outputContent)
{
var path = outputPath;
if (IsLongPathEnabled())
try
{
var normalizedPath = Path.GetFullPath(outputPath);
path = normalizedPath.StartsWith(@"\\", StringComparison.OrdinalIgnoreCase)
? $@"\\?\UNC\{normalizedPath.Substring(2, normalizedPath.Length - 2)}"
: $@"\\?\{normalizedPath}";
}
var path = outputPath;
if (IsLongPathEnabled())
{
var normalizedPath = Path.GetFullPath(outputPath);
path = normalizedPath.StartsWith(@"\\", StringComparison.OrdinalIgnoreCase)
? $@"\\?\UNC\{normalizedPath.Substring(2, normalizedPath.Length - 2)}"
: $@"\\?\{normalizedPath}";
}

var dir = Path.GetDirectoryName(path);
if (!Directory.Exists(dir) && dir != null)
{
Directory.CreateDirectory(dir);
}

var dir = Path.GetDirectoryName(path);
if (!Directory.Exists(dir) && dir != null)
System.IO.File.WriteAllText(
path,
outputContent,
new UTF8Encoding(encoderShouldEmitUTF8Identifier: Settings.Utf8BomGeneration));
}
catch (Exception exception)
{
Directory.CreateDirectory(dir);
Log.Error($"Unable to write file '{outputPath}'.{Environment.NewLine}{exception.Message}{Environment.NewLine}{exception.StackTrace}");
}

System.IO.File.WriteAllText(
path,
outputContent,
new UTF8Encoding(encoderShouldEmitUTF8Identifier: Settings.Utf8BomGeneration));
}

protected virtual void SaveFile(File file, string output, ref bool success)
Expand Down
16 changes: 8 additions & 8 deletions src/Typewriter/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="68E244F1-14E1-4681-A51C-5B902B9EE96C" Version="2.25.0" Language="en-US" Publisher="frhagn" />
<Identity Id="68E244F1-14E1-4681-A51C-5B902B9EE96C" Version="2.26.0" Language="en-US" Publisher="frhagn" />
<DisplayName>Typewriter64</DisplayName>
<Description xml:space="preserve">Typewriter generates TypeScript files from c# code files using TypeScript Templates. This allows you to create fully typed TypeScript representations of server side API that automatically updates when you make changes to your c# code.</Description>
<MoreInfo>http://frhagn.github.io/Typewriter/</MoreInfo>
Expand All @@ -13,30 +13,30 @@
<Tags>TypeScript, Code Generation, Templates, Web API, MVC, Typewriter</Tags>
</Metadata>
<Installation InstalledByMsi="false">
<InstallationTarget Version="[17.8.3,18.0)" Id="Microsoft.VisualStudio.Community">
<InstallationTarget Version="[17.8.4,18.0)" Id="Microsoft.VisualStudio.Community">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.8.3,18.0)" Id="Microsoft.VisualStudio.Pro">
<InstallationTarget Version="[17.8.4,18.0)" Id="Microsoft.VisualStudio.Pro">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.8.3,18.0)" Id="Microsoft.VisualStudio.Enterprise">
<InstallationTarget Version="[17.8.4,18.0)" Id="Microsoft.VisualStudio.Enterprise">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.8.3,18.0)" Id="Microsoft.VisualStudio.Community">
<InstallationTarget Version="[17.8.4,18.0)" Id="Microsoft.VisualStudio.Community">
<ProductArchitecture>arm64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.8.3,18.0)" Id="Microsoft.VisualStudio.Pro">
<InstallationTarget Version="[17.8.4,18.0)" Id="Microsoft.VisualStudio.Pro">
<ProductArchitecture>arm64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.8.3,18.0)" Id="Microsoft.VisualStudio.Enterprise">
<InstallationTarget Version="[17.8.4,18.0)" Id="Microsoft.VisualStudio.Enterprise">
<ProductArchitecture>arm64</ProductArchitecture>
</InstallationTarget>
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.7.2,)" />
</Dependencies>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.8.3,18.0)" DisplayName="Visual Studio core editor" />
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[17.8.4,18.0)" DisplayName="Visual Studio core editor" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
Expand Down

0 comments on commit 2e7dd7c

Please sign in to comment.