Files

47 lines
1.8 KiB
PowerShell
Raw Permalink Normal View History

# Enables the OpenHarmony Flutter toolchain for the current PowerShell session.
# This script does not change the system or user PATH permanently.
$ErrorActionPreference = 'Stop'
$flutterBin = 'C:\Users\A200477427\Developments\flutter_flutter\bin'
$devecoHome = 'C:\Program Files\Huawei\DevEco Studio'
$devecoSdk = "$devecoHome\sdk"
$ohpmBin = "$devecoHome\tools\ohpm\bin"
$hvigorBin = "$devecoHome\tools\hvigor\bin"
$requiredDirectories = @($flutterBin, $devecoSdk, $ohpmBin, $hvigorBin)
$missingDirectories = $requiredDirectories | Where-Object {
-not (Test-Path -LiteralPath $_ -PathType Container)
}
if ($missingDirectories) {
throw "OpenHarmony tool directories were not found:`n$($missingDirectories -join "`n")"
}
# Set these only for this terminal. This also makes the script work in a terminal
# that was opened before the corresponding Windows environment variables existed.
$env:DEVECO_HOME = $devecoHome
$env:DEVECO_SDK_HOME = $devecoSdk
# Put the OpenHarmony-specific commands first for this terminal only. Remove
# duplicate entries so repeated execution of this script leaves PATH clean.
$pathDirectories = @($flutterBin, $ohpmBin, $hvigorBin)
$pathEntries = $env:Path -split ';' | Where-Object {
$_ -and $_ -notin $pathDirectories
}
$env:Path = ($pathDirectories + $pathEntries) -join ';'
$commands = @('flutter', 'ohpm', 'hvigorw')
$unavailableCommands = foreach ($command in $commands) {
if (-not (Get-Command $command -ErrorAction SilentlyContinue)) {
$command
}
}
if ($unavailableCommands) {
throw "The following commands could not be resolved from PATH: $($unavailableCommands -join ', ')"
}
Write-Host 'OpenHarmony Flutter environment is enabled for this PowerShell session.' -ForegroundColor Green
Get-Command $commands | Select-Object Name, Source, CommandType | Format-Table -AutoSize