| 176 | } |
| 177 | |
| 178 | function extractZipWindows(archivePath, destDir) { |
| 179 | const psOpts = ["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"]; |
| 180 | const psStdio = ["ignore", "inherit", "inherit"]; |
| 181 | const psEnv = { |
| 182 | ...process.env, |
| 183 | LARK_CLI_ARCHIVE: archivePath, |
| 184 | LARK_CLI_DEST: destDir, |
| 185 | }; |
| 186 | |
| 187 | try { |
| 188 | const dotnet = |
| 189 | "$ErrorActionPreference='Stop';" + |
| 190 | "Add-Type -AssemblyName System.IO.Compression.FileSystem;" + |
| 191 | "[System.IO.Compression.ZipFile]::ExtractToDirectory($env:LARK_CLI_ARCHIVE,$env:LARK_CLI_DEST)"; |
| 192 | execFileSync("powershell.exe", [...psOpts, dotnet], { stdio: psStdio, env: psEnv }); |
| 193 | } catch (primaryErr) { |
| 194 | try { |
| 195 | const cmdlet = |
| 196 | "$ErrorActionPreference='Stop';" + |
| 197 | "Expand-Archive -LiteralPath $env:LARK_CLI_ARCHIVE -DestinationPath $env:LARK_CLI_DEST -Force"; |
| 198 | execFileSync("powershell.exe", [...psOpts, cmdlet], { stdio: psStdio, env: psEnv }); |
| 199 | } catch (secondErr) { |
| 200 | try { |
| 201 | execFileSync("tar", ["-xf", archivePath, "-C", destDir], { stdio: psStdio }); |
| 202 | } catch (fallbackErr) { |
| 203 | throw new Error( |
| 204 | `Failed to extract ${archivePath}. ` + |
| 205 | `.NET ZipFile attempt: ${primaryErr.message}. ` + |
| 206 | `Expand-Archive fallback: ${secondErr.message}. ` + |
| 207 | `tar fallback: ${fallbackErr.message}` |
| 208 | ); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | function install() { |
| 215 | const mirrorUrls = getMirrorUrls(process.env); |