-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.js
More file actions
141 lines (120 loc) · 5.08 KB
/
install.js
File metadata and controls
141 lines (120 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* @fileoverview Installation script for libwebp-static
*
* This script downloads and extracts precompiled WebP binaries for the current
* platform during package installation. It fetches official WebP releases
* from Google's storage and organizes them in a platform-specific directory structure.
*
* @author caed0
* @version 1.0.2
* @license GPL-3.0-or-later
*/
const path = require("path");
const fs = require("fs");
const { execSync } = require("child_process");
/**
* Version of libwebp binaries to download
* @constant {string}
*/
const LIBWEBP_VERSION = "1.5.0";
/**
* Base URL for official WebP releases
* @constant {string}
*/
const BASE_URL = `https://storage.googleapis.com/downloads.webmproject.org/releases/webp/`;
/**
* Mapping of platform-architecture combinations to their respective binary archives
*
* @constant {Object.<string, string>}
* @property {string} win32-x64 - Windows 64-bit archive
* @property {string} linux-x64 - Linux x86_64 archive
* @property {string} linux-arm64 - Linux ARM64 archive
* @property {string} darwin-x64 - macOS Intel archive
* @property {string} darwin-arm64 - macOS Apple Silicon archive
*/
const PRECOMPILED_BINARIES = {
"win32-x64": "windows-x64.zip",
"linux-x64": "linux-x86-64.tar.gz",
"linux-arm64": "linux-aarch64.tar.gz",
"darwin-x64": "mac-x86-64.tar.gz",
"darwin-arm64": "mac-arm64.tar.gz"
}
/**
* Create the binaries directory if it doesn't exist
*/
if (!fs.existsSync(path.join(__dirname, "binaries"))) {
fs.mkdirSync(path.join(__dirname, "binaries"));
console.log("Created binaries directory");
}
/**
* Download and extract binaries for each supported platform
*/
console.log(`Downloading libwebp ${LIBWEBP_VERSION} binaries...`);
for (const [key, value] of Object.entries(PRECOMPILED_BINARIES)) {
const [platform, arch] = key.split("-");
const file = `libwebp-${LIBWEBP_VERSION}-${value}`;
const binaryUrl = `${BASE_URL}${file}`;
console.log(`Processing ${platform}-${arch}...`);
try {
// Create platform directory structure
if (!fs.existsSync(`binaries/${platform}`)) {
fs.mkdirSync(`binaries/${platform}`, { recursive: true });
}
// Download the binary archive
console.log(` Downloading from: ${binaryUrl}`);
execSync(`curl -s -L ${binaryUrl} --output binaries/${file}`, { stdio: "inherit" });
// Extract the archive based on file type and platform
console.log(` Extracting ${file}...`);
if (process.platform !== "win32" && file.endsWith(".zip")) {
// Use unzip for ZIP files on non-Windows platforms
execSync(`unzip -qo binaries/${file} -d binaries/${platform}`, { stdio: "inherit" });
} else {
// Use tar for .tar.gz files and ZIP files on Windows
execSync(`tar -xzf binaries/${file} -C binaries/${platform}`, { stdio: "inherit" });
}
// Clean up the downloaded archive
if (fs.existsSync(`binaries/${file}`)) {
fs.unlinkSync(`binaries/${file}`);
}
// Rename extracted directory to match architecture name
const extractedDir = file.split(".").slice(0, 3).join(".");
const extractedPath = `binaries/${platform}/${extractedDir}`;
const targetPath = `binaries/${platform}/${arch}`;
if (fs.existsSync(extractedPath)) {
fs.renameSync(extractedPath, targetPath);
console.log(` ✓ Successfully extracted to ${targetPath}`);
}
} catch (error) {
// Clean up on error and exit
console.error(`✗ Failed to process ${platform}-${arch}:`, error.message);
if (fs.existsSync("binaries")) {
fs.rmSync("binaries", { recursive: true, force: true });
}
console.error("\nInstallation failed. Please check:");
console.error("1. Internet connection is available");
console.error("2. curl command is installed");
console.error("3. tar/unzip utilities are available");
console.error("4. Write permissions in the package directory");
process.exit(1);
}
}
console.log("✓ All binaries downloaded and extracted successfully!");
console.log(`✓ libwebp-static v${LIBWEBP_VERSION} installation complete`);
/**
* Verify installation by checking if binaries exist for the current platform
*/
const currentPlatform = process.platform;
const currentArch = process.arch;
const platformKey = `${currentPlatform}-${currentArch}`;
if (PRECOMPILED_BINARIES[platformKey]) {
const binaryPath = path.join(__dirname, "binaries", currentPlatform, currentArch, "bin");
if (fs.existsSync(binaryPath)) {
const binaries = fs.readdirSync(binaryPath);
console.log(`✓ Found ${binaries.length} tools for ${platformKey}: ${binaries.join(', ')}`);
} else {
console.warn(`⚠ Warning: Binary directory not found for current platform (${platformKey})`);
}
} else {
console.warn(`⚠ Warning: Current platform (${platformKey}) is not officially supported`);
console.warn("Available platforms:", Object.keys(PRECOMPILED_BINARIES).join(', '));
}