|
1 | 1 | import os from "os";
|
| 2 | +import fs from "fs"; |
| 3 | +import { execSync } from "child_process"; |
| 4 | + |
2 | 5 | const platform = os.platform();
|
| 6 | +const rel = os.release(); |
| 7 | + |
| 8 | +if (platform !== "linux") { |
| 9 | + console.log("Skipping playwright installation: non-Linux platform detected:", platform); |
| 10 | + process.exit(0); |
| 11 | +} |
| 12 | + |
| 13 | +function getDistroName() { |
| 14 | + try { |
| 15 | + const osReleaseContent = fs.readFileSync("/etc/os-release", "utf8"); |
| 16 | + const lines = osReleaseContent.split("\n"); |
| 17 | + const info = {}; |
| 18 | + for (const line of lines) { |
| 19 | + const [key, value] = line.split("="); |
| 20 | + if (key && value) { |
| 21 | + info[key.toLowerCase()] = value.replace(/"/g, "").toLowerCase().trim(); |
| 22 | + } |
| 23 | + } |
| 24 | + return info["id"] || info["id_like"] || null; |
| 25 | + } catch (err) { |
| 26 | + console.error("Error reading /etc/os-release:", err.message); |
| 27 | + } |
| 28 | + return null; |
| 29 | +} |
3 | 30 |
|
4 |
| -if ( |
5 |
| - platform === "linux" && |
6 |
| - !(os.release().includes("ubuntu") || os.release().includes("debian")) |
7 |
| -) { |
8 |
| - // DO NOT CHANGE THIS TO ELIZALOGGER, this file cannot depends on any workspace otherwise we can't build the workspace |
| 31 | +const distro = getDistroName(); |
| 32 | +console.log("Detected Linux distribution:", distro || "unknown"); |
| 33 | + |
| 34 | +const supportedDistros = [ |
| 35 | + "ubuntu", |
| 36 | + "debian", |
| 37 | + "pve", |
| 38 | + "raspbian", |
| 39 | + "pop", |
| 40 | + "zorin", |
| 41 | + "linuxmint", |
| 42 | + "elementary", |
| 43 | + "pureos", |
| 44 | + "kali" |
| 45 | +]; |
| 46 | + |
| 47 | +if (!distro || !supportedDistros.some((name) => distro.includes(name))) { |
9 | 48 | console.log(
|
10 | 49 | "Skipping playwright installation on unsupported platform:",
|
11 |
| - platform |
| 50 | + platform, |
| 51 | + rel, |
| 52 | + distro || "unknown distro" |
12 | 53 | );
|
13 |
| -} else { |
14 |
| - const { execSync } = await import("child_process"); |
| 54 | + process.exit(0); |
| 55 | +} |
| 56 | + |
| 57 | +try { |
15 | 58 | execSync("npx playwright install-deps && npx playwright install", {
|
16 |
| - stdio: "inherit", |
| 59 | + stdio: "inherit" |
17 | 60 | });
|
| 61 | +} catch (err) { |
| 62 | + console.error("Failed to install Playwright dependencies:", err.message); |
| 63 | + process.exit(1); |
18 | 64 | }
|
0 commit comments