-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_proto_files.ps1
More file actions
72 lines (66 loc) · 3.2 KB
/
generate_proto_files.ps1
File metadata and controls
72 lines (66 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# To exceute on windows, open powershell in your protogen folder and use the command
# `./generate_proto_files.ps1`
# Fetch all proto files frop the gen path and output them to the server location and game asset folder
$basePath = Split-Path $MyInvocation.MyCommand.Path
echo "Base path: $basePath"
$dir = Convert-Path "$basePath/Server/ProtosGen" # This is the path to your grpc_csharp_plugin.exe and protos file definitions
echo "Protos path: $dir"
echo "Creating Generated Input Path"
New-Item -ItemType Directory -Force -Path "$dir/GeneratedInput"
$inputPath = Convert-Path "$dir/GeneratedInput/"
echo "Creating Generated Output Path"
New-Item -ItemType Directory -Force -Path "$dir/GeneratedOutput"
$outputPath = Convert-Path "$dir/GeneratedOutput/"
echo "Output Path: $outputPath"
$serverProtosPath = Convert-Path "$basePath/Server/ActionRpg.Server.Grpc/Protos" # This is the ActionRpg server folder path
echo "Sever Protos Path: $serverProtosPath"
$gameProtosPath = Convert-Path "$basePath/Game/ActionRpg/Assets/ActionRpgAssets/Protos" # This is the Unity3D game for ActionRpg
echo "Game Protos Path: $gameProtosPath"
$gameClientProtosPath = Convert-Path "$basePath/Client/ActionRpg.Client.GameClient/Protos" # This is the test game client for ActionRpg
echo "Game Client Protos Path: $gameClientProtosPath"
# Create output locations
echo "Creating Server Protos Path: $serverProtosPath"
New-Item -ItemType Directory -Force -Path $serverProtosPath
echo "Creating Game Protos Path: $gameProtosPath"
New-Item -ItemType Directory -Force -Path $gameProtosPath
echo "Creating Game Client Protos Path: $gameClientProtosPath"
New-Item -ItemType Directory -Force -Path $gameClientProtosPath
# Delete existing items
Remove-Item "$inputPath*.*"
Remove-Item "$outputPath*.*"
Remove-Item "$serverProtosPath*.*"
Remove-Item "$gameProtosPath*.*"
Remove-Item "$gameClientProtosPath*.*"
# Fetch source files
echo "Consolidating input files"
$inputFiles = Get-ChildItem -Path $dir -Recurse -File '*.proto'
foreach ($file in $inputFiles) {
$filepath = $file.FullName
$fileName = $file.Name
echo "Copying to input path: $inputPath, file name: $fileName"
$copyInputPath = $inputPath + $fileName
Copy-Item -Path $filepath -Destination $copyInputPath
}
# Create the protoc files at output location
echo "Generating output files"
$files = Get-ChildItem -Path $inputPath -Recurse -File '*.proto' | Select-Object Name
foreach ($file in $files) {
# Write the new proto
$filePath = $file.FullName
$fileName = $file.Name
$protoGen = "$dir/protoc.exe -I $inputPath --csharp_out=$outputPath --grpc_out=$outputPath --plugin=protoc-gen-grpc=$dir/grpc_csharp_plugin.exe " + $file.Name
echo "Protoc output: $outputPath$fileName"
Invoke-Expression $protoGen
}
# Copy files to new locations
$outputFiles = Get-ChildItem -Path $outputPath -Recurse -File '*.cs'
foreach($file in $outputFiles) {
$filePath = $file.FullName
$fileName = $file.Name
echo "Exporting file to $serverProtosPath$fileName"
Copy-Item -Path $filepath -Destination $serverProtosPath
echo "Exporting file to $gameProtosPath$fileName"
Copy-Item -Path $filepath -Destination $gameProtosPath
echo "Exporting file to $gameClientProtosPath$fileName"
Copy-Item -Path $filepath -Destination $gameClientProtosPath
}