feat(02-03): create ps-helpers.ts shared module

- Export CONFIG_DIR record mapping configPath to Windows paths
- Export buildRcloneInstallBlock for conditional rclone binary download
- machine-wide maps to C:\ProgramData\rclone
- user-profile maps to %APPDATA%\rclone
- Uses -UseBasicParsing for SYSTEM context safety
This commit is contained in:
2026-03-26 10:56:43 +01:00
parent e3615c446c
commit 6a7912daae
+35
View File
@@ -0,0 +1,35 @@
// src/generators/ps-helpers.ts
// Shared PowerShell snippet builders used by both intune-install.ts and intune-detection.ts.
// Keeping path constants and install block in one place guarantees the two scripts
// always reference the same Windows paths — a mismatch would cause detection to fail
// even when the app is correctly installed.
import type { WizardState } from '../store/types';
// Canonical Windows paths for each configPath option.
// Note: %APPDATA% under SYSTEM resolves to
// C:\Windows\system32\config\systemprofile\AppData\Roaming\
// Generated scripts include an inline comment warning about this.
export const CONFIG_DIR: Record<WizardState['deployment']['configPath'], string> = {
'machine-wide': 'C:\\ProgramData\\rclone',
'user-profile': '%APPDATA%\\rclone',
};
// Conditional rclone binary download block (idempotent).
// Returns the PowerShell snippet as a string.
// Caller decides whether to include it based on state.deployment.includeInstall.
export function buildRcloneInstallBlock(installPath: string): string {
return `
# Download rclone binary (idempotent — skips if already present)
$rclonePath = "${installPath}\\rclone.exe"
if (-not (Test-Path $rclonePath)) {
$zipPath = "$env:TEMP\\rclone.zip"
Invoke-WebRequest -Uri 'https://downloads.rclone.org/rclone-current-windows-amd64.zip' -OutFile $zipPath -UseBasicParsing
Add-Type -AssemblyName System.IO.Compression.FileSystem
$zip = [System.IO.Compression.ZipFile]::OpenRead($zipPath)
$entry = $zip.Entries | Where-Object { $_.Name -eq 'rclone.exe' }
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, $rclonePath, $true)
$zip.Dispose()
Remove-Item $zipPath -Force
}`;
}