#709 多行字符串   json     powershell     snippets     8 months ago (owner) Document
$cwd = (Get-Item .).FullName

$uproject_file = Get-ChildItem . -Filter "*.uproject" | Select-Object -First 1
if ($null -eq $uproject_file) {
    Write-Host "uproject file not found."
    Exit -1
}

$uproject = $uproject_file | Get-Content -Raw | ConvertFrom-Json
$project_name = $uproject_file.BaseName
Write-Host "Project name is $project_name"
$modules = @(
    @{
        "Name" = "$project_name"
        "Type" = "Runtime"
        "LoadingPhase" = "Default"
    }
)
#$modules是个数组,里面的元素是一个字典

if ($null -eq $uproject.Modules) {
    Write-Host "Modules field not exists."
    $uproject | Add-Member -Name "Modules" -Value $modules -MemberType NoteProperty
    Write-Host "Adding [Modules] field:",($uproject.Modules| ConvertTo-Json)
    <# save uproject file #>
    $uproject | ConvertTo-Json -Depth 3 | Out-File $uproject_file.FullName
}
else {
    <# Action when all if and elseif conditions are false #>
    $project_name = $uproject.Modules[0].Name
}