Skip to content

Commit 31ccca1

Browse files
authored
Merge pull request #1606 from Cratis:fix/minor-things
Fix/minor-things
2 parents 6d3bac2 + 94422e9 commit 31ccca1

File tree

7 files changed

+143
-5
lines changed

7 files changed

+143
-5
lines changed

Source/DotNET/Cratis/Cratis.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<PackageReference Include="Cratis.Chronicle.AspNetCore" />
1919
</ItemGroup>
2020
<ItemGroup>
21-
<None Include="GlobalUsings.cs" Pack="true" PackagePath="contentFiles/cs/any;content" />
21+
<None Include="GlobalUsings.cs" Pack="true" PackagePath="contentFiles/cs/any" BuildAction="Compile" />
22+
<None Include="build/Cratis.props" Pack="true" PackagePath="build;buildTransitive" />
2223
</ItemGroup>
2324
</Project>

Source/DotNET/Cratis/GlobalUsings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
global using Cratis.Arc.Identity;
1212
global using Cratis.Arc.Queries;
1313
global using Cratis.Arc.Queries.ModelBound;
14+
global using Cratis.Arc.Swagger;
1415
global using Cratis.Arc.Validation;
1516
global using Cratis.Chronicle;
1617
global using Cratis.Chronicle.Events;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<ItemGroup>
3+
<Compile Include="$(MSBuildThisFileDirectory)\..\contentFiles\cs\any\GlobalUsings.cs" Link="GlobalUsings.Cratis.cs" Visible="false" />
4+
</ItemGroup>
5+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) Cratis. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Cratis.Arc.ProxyGenerator.for_FileMetadataScanner.when_finding_orphaned_files;
5+
6+
public class simulating_real_generation_flow : Specification
7+
{
8+
string _tempDir;
9+
Dictionary<string, GeneratedFileMetadata> _generatedFiles;
10+
IEnumerable<string> _orphanedFiles;
11+
12+
void Establish()
13+
{
14+
_tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
15+
Directory.CreateDirectory(_tempDir);
16+
17+
_generatedFiles = [];
18+
19+
var targetPath = _tempDir;
20+
const string path = "commands";
21+
const string fileName = "CreateOrder.ts";
22+
23+
var fullPath = Path.Join(targetPath, path, fileName);
24+
var normalizedFullPath = Path.GetFullPath(fullPath);
25+
var directory = Path.GetDirectoryName(normalizedFullPath)!;
26+
Directory.CreateDirectory(directory);
27+
28+
var metadata = new GeneratedFileMetadata("MyApp.Commands.CreateOrder", DateTime.UtcNow);
29+
var content = $"{metadata.ToCommentLine()}\nexport class CreateOrder {{}}";
30+
File.WriteAllText(normalizedFullPath, content);
31+
32+
_generatedFiles[normalizedFullPath] = metadata;
33+
}
34+
35+
void Because() => _orphanedFiles = FileMetadataScanner.FindOrphanedFiles(_tempDir, _generatedFiles);
36+
37+
[Fact] void should_not_find_any_orphaned_files() => _orphanedFiles.ShouldBeEmpty();
38+
39+
void Cleanup()
40+
{
41+
if (Directory.Exists(_tempDir))
42+
{
43+
Directory.Delete(_tempDir, true);
44+
}
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) Cratis. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Cratis.Arc.ProxyGenerator.for_FileMetadataScanner.when_finding_orphaned_files;
5+
6+
public class with_file_generated_using_path_join : Specification
7+
{
8+
string _tempDir;
9+
Dictionary<string, GeneratedFileMetadata> _generatedFiles;
10+
IEnumerable<string> _orphanedFiles;
11+
string _generatedFilePath;
12+
13+
void Establish()
14+
{
15+
_tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
16+
Directory.CreateDirectory(_tempDir);
17+
18+
const string subDir = "commands";
19+
_generatedFilePath = Path.Join(_tempDir, subDir, "CreateOrder.ts");
20+
var directory = Path.GetDirectoryName(_generatedFilePath)!;
21+
Directory.CreateDirectory(directory);
22+
23+
var metadata = new GeneratedFileMetadata("MyApp.Commands.CreateOrder", DateTime.UtcNow);
24+
File.WriteAllText(_generatedFilePath, $"{metadata.ToCommentLine()}\nexport class CreateOrder {{}}");
25+
26+
_generatedFiles = new Dictionary<string, GeneratedFileMetadata>
27+
{
28+
[_generatedFilePath] = metadata
29+
};
30+
}
31+
32+
void Because() => _orphanedFiles = FileMetadataScanner.FindOrphanedFiles(_tempDir, _generatedFiles);
33+
34+
[Fact] void should_not_find_the_just_generated_file_as_orphaned() => _orphanedFiles.ShouldNotContain(_generatedFilePath);
35+
[Fact] void should_not_find_any_orphaned_files() => _orphanedFiles.ShouldBeEmpty();
36+
37+
void Cleanup()
38+
{
39+
if (Directory.Exists(_tempDir))
40+
{
41+
Directory.Delete(_tempDir, true);
42+
}
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) Cratis. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Cratis.Arc.ProxyGenerator.for_FileMetadataScanner.when_finding_orphaned_files;
5+
6+
public class with_file_just_generated_in_same_run : Specification
7+
{
8+
string _tempDir;
9+
Dictionary<string, GeneratedFileMetadata> _generatedFiles;
10+
IEnumerable<string> _orphanedFiles;
11+
string _justGeneratedFilePath;
12+
13+
void Establish()
14+
{
15+
_tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
16+
Directory.CreateDirectory(_tempDir);
17+
18+
_justGeneratedFilePath = Path.Combine(_tempDir, "JustGenerated.ts");
19+
var metadata = new GeneratedFileMetadata("MyNamespace.MyCommand", DateTime.UtcNow);
20+
File.WriteAllText(_justGeneratedFilePath, $"{metadata.ToCommentLine()}\nexport class JustGenerated {{}}");
21+
22+
_generatedFiles = new Dictionary<string, GeneratedFileMetadata>
23+
{
24+
[_justGeneratedFilePath] = metadata
25+
};
26+
}
27+
28+
void Because() => _orphanedFiles = FileMetadataScanner.FindOrphanedFiles(_tempDir, _generatedFiles);
29+
30+
[Fact] void should_not_find_the_just_generated_file_as_orphaned() => _orphanedFiles.ShouldNotContain(_justGeneratedFilePath);
31+
[Fact] void should_not_find_any_orphaned_files() => _orphanedFiles.ShouldBeEmpty();
32+
33+
void Cleanup()
34+
{
35+
if (Directory.Exists(_tempDir))
36+
{
37+
Directory.Delete(_tempDir, true);
38+
}
39+
}
40+
}

Source/DotNET/Tools/ProxyGenerator/DescriptorExtensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public static async Task Write(
4545
{
4646
var path = descriptor.Type.ResolveTargetPath(segmentsToSkip);
4747
var fullPath = Path.Join(targetPath, path, $"{descriptor.Name}.ts");
48-
var directory = Path.GetDirectoryName(fullPath)!;
48+
var normalizedFullPath = Path.GetFullPath(fullPath);
49+
var directory = Path.GetDirectoryName(normalizedFullPath)!;
4950
if (!Directory.Exists(directory)) Directory.CreateDirectory(directory);
5051

5152
if (!directories.Contains(directory))
@@ -56,19 +57,19 @@ public static async Task Write(
5657
var proxyContent = template(descriptor);
5758
var metadata = new GeneratedFileMetadata(descriptor.Type.FullName!, generationTime);
5859
var contentWithMetadata = $"{metadata.ToCommentLine()}{Environment.NewLine}{proxyContent}";
59-
await File.WriteAllTextAsync(fullPath, contentWithMetadata);
60+
await File.WriteAllTextAsync(normalizedFullPath, contentWithMetadata);
6061

6162
// Track the generated file in the index
6263
if (fileIndex is not null)
6364
{
64-
var relativePath = Path.GetRelativePath(targetPath, fullPath);
65+
var relativePath = Path.GetRelativePath(targetPath, normalizedFullPath);
6566
fileIndex.AddFile(relativePath);
6667
}
6768

6869
// Track generated file metadata
6970
if (generatedFiles is not null)
7071
{
71-
generatedFiles[fullPath] = metadata;
72+
generatedFiles[normalizedFullPath] = metadata;
7273
}
7374
}
7475

0 commit comments

Comments
 (0)