Skip to content

Commit

Permalink
Fixed StrawberryShake duplicate file name issue
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Aug 30, 2022
1 parent 7497c44 commit f713b53
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
Expand Up @@ -10,6 +10,7 @@
<GraphQLRequestHash>md5</GraphQLRequestHash>
<!--intermediate/project-->
<GraphQLOutput>intermediate</GraphQLOutput>
<GraphQLDebug>disable</GraphQLDebug>
</PropertyGroup>

<ItemDefinitionGroup>
Expand Down
Expand Up @@ -24,9 +24,6 @@
<GraphQLCodeGenerationRoot>$(MSBuildProjectDirectory)\$(IntermediateOutputPath)berry\</GraphQLCodeGenerationRoot>
</PropertyGroup>

<Message Text="GraphQLCodeGenerationRoot $(GraphQLCodeGenerationRoot)" Importance="High" />
<Message Text="MSBuildProjectDirectory $(MSBuildProjectDirectory)" Importance="High" />

<PropertyGroup>
<GenCommand>dotnet $(GenTool) generate "$(MSBuildProjectDirectory)"</GenCommand>
<GenCommand>$(GenCommand) -o "$(GraphQLCodeGenerationRoot)"</GenCommand>
Expand All @@ -37,9 +34,9 @@
<GenCommand Condition="'$(GraphQLRazorComponents)' == 'enable'">$(GenCommand) -r</GenCommand>
</PropertyGroup>

<Message Text="$(GenCommand)" Importance="High" />

<Exec Command="dotnet --version" WorkingDirectory="$(MSBuildThisFileDirectory)" />
<Message Text="MSBuildProjectDirectory: $(MSBuildProjectDirectory)" Importance="High" Condition="'$(GraphQLDebug)' == 'enable'" />
<Message Text="MSBuildThisFileDirectory: $(MSBuildThisFileDirectory)" Importance="High" Condition="'$(GraphQLDebug)' == 'enable'" />
<Message Text="$(GenCommand)" Importance="High" Condition="'$(GraphQLDebug)' == 'enable'" />
<Exec Command="$(GenCommand)" WorkingDirectory="$(MSBuildThisFileDirectory)" ConsoleToMsBuild="true" />

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/StrawberryShake/Tooling/.vscode/launch.json
Expand Up @@ -12,6 +12,12 @@
"args": [
"generate",
"/Users/michael/local/play/StrawberryBuildTests",
"-o /Users/michael/local/play/StrawberryBuildTests/obj/Debug/net7.0/berry/",
"-n StrawberryBuildTests",
"-a md5",
"-s",
"-t",
"-r"
],
"cwd": "${workspaceFolder}/src/dotnet-graphql",
"console": "internalConsole",
Expand Down
21 changes: 17 additions & 4 deletions src/StrawberryShake/Tooling/src/dotnet-graphql/GenerateCommand.cs
Expand Up @@ -107,9 +107,7 @@ public GenerateCommandHandler(IConsoleOutput output)
{
if (doc.Kind is SourceDocumentKind.CSharp or SourceDocumentKind.Razor)
{
var fileName = doc.Path is null
? Path.Combine(outputDir, doc.Name + ".cs")
: Path.Combine(outputDir, doc.Path, doc.Name + ".cs");
var fileName = CreateFileName(outputDir, doc.Path, doc.Name, doc.Kind);
var dir = Path.GetDirectoryName(fileName)!;

if (!Directory.Exists(dir))
Expand All @@ -131,11 +129,26 @@ public GenerateCommandHandler(IConsoleOutput output)
}
}
}

}

return statusCode;
}

private static string CreateFileName(
string outputDir,
string? path,
string name,
SourceDocumentKind kind)
{
var kindName =
kind is SourceDocumentKind.CSharp
? "Client"
: "Components";

return path is null
? Path.Combine(outputDir, $"{name}.{kindName}.cs")
: Path.Combine(outputDir, path, $"{name}.{kindName}.cs");
}
}

internal sealed class GenerateCommandArguments
Expand Down

0 comments on commit f713b53

Please sign in to comment.