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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/mnenv/shells/power_shell.rb', line 17
def shim_content(executable_name)
<<~SHIM
# mnenv shim for PowerShell
$ErrorActionPreference = "Stop"
$MNENV_ROOT = if ($env:MNENV_ROOT) { $env:MNENV_ROOT } else { "$env:USERPROFILE\\.mnenv" }
# Resolve version and source using mnenv resolver
$versionFile = "$MNENV_ROOT\\version"
$sourceFile = "$MNENV_ROOT\\source"
# Check environment variables first
$VERSION = $env:METANORMA_VERSION
$SOURCE = $env:METANORMA_SOURCE
# Check local .metanorma-version file
if (-not $VERSION) {
$dir = (Get-Location).Path
$root = [System.IO.Path]::GetPathRoot($dir)
while ($dir -and $dir -ne $root) {
$localVersionFile = Join-Path $dir ".metanorma-version"
if (Test-Path $localVersionFile) {
$VERSION = Get-Content $localVersionFile -Raw
$VERSION = $VERSION.Trim()
break
}
$localSourceFile = Join-Path $dir ".metanorma-source"
if (-not $SOURCE -and (Test-Path $localSourceFile)) {
$SOURCE = Get-Content $localSourceFile -Raw
$SOURCE = $SOURCE.Trim()
}
$dir = Split-Path $dir -Parent
}
}
# Check global version file
if (-not $VERSION -and (Test-Path $versionFile)) {
$VERSION = Get-Content $versionFile -Raw
$VERSION = $VERSION.Trim()
}
if (-not $SOURCE -and (Test-Path $sourceFile)) {
$SOURCE = Get-Content $sourceFile -Raw
$SOURCE = $SOURCE.Trim()
}
# Default source
if (-not $SOURCE) {
$SOURCE = "gemfile"
}
if (-not $VERSION) {
Write-Error "mnenv: version not set or invalid"
Write-Error "Set a version with: mnenv global <version> or mnenv local <version>"
exit 1
}
# Determine executable path based on source
# Installed versions are in $MNENV_ROOT\\installed\\<version>-<source>\\
if ($SOURCE -eq "binary") {
$EXECUTABLE = "$MNENV_ROOT\\installed\\$VERSION-$SOURCE\\metanorma.exe"
} else {
# Bundler creates .cmd files on Windows, not .bat
$EXECUTABLE = "$MNENV_ROOT\\installed\\$VERSION-$SOURCE\\bin\\#{executable_name}.cmd"
}
if (-not (Test-Path $EXECUTABLE)) {
Write-Error "mnenv: #{executable_name} not installed for version $VERSION (source: $SOURCE)"
Write-Error "Install it with: mnenv install $VERSION --source $SOURCE"
exit 1
}
& $EXECUTABLE $args
SHIM
end
|