@fredlackey/devutils 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/package.json +1 -1
- package/src/commands/install.js +374 -36
- package/src/installs/adobe-creative-cloud.js +527 -25
- package/src/installs/adobe-creative-cloud.md +605 -0
- package/src/installs/appcleaner.js +303 -26
- package/src/installs/appcleaner.md +699 -0
- package/src/installs/apt-transport-https.js +390 -0
- package/src/installs/apt-transport-https.md +678 -0
- package/src/installs/atomicparsley.js +624 -26
- package/src/installs/atomicparsley.md +795 -0
- package/src/installs/aws-cli.js +779 -26
- package/src/installs/aws-cli.md +727 -0
- package/src/installs/balena-etcher.js +688 -26
- package/src/installs/balena-etcher.md +761 -0
- package/src/installs/bambu-studio.js +912 -26
- package/src/installs/bambu-studio.md +780 -0
- package/src/installs/bash-completion.js +554 -23
- package/src/installs/bash-completion.md +833 -0
- package/src/installs/bash.js +399 -26
- package/src/installs/bash.md +993 -0
- package/src/installs/beyond-compare.js +585 -26
- package/src/installs/beyond-compare.md +813 -0
- package/src/installs/build-essential.js +511 -26
- package/src/installs/build-essential.md +977 -0
- package/src/installs/ca-certificates.js +618 -0
- package/src/installs/ca-certificates.md +937 -0
- package/src/installs/caffeine.js +490 -26
- package/src/installs/caffeine.md +839 -0
- package/src/installs/camtasia.js +577 -25
- package/src/installs/camtasia.md +762 -0
- package/src/installs/chatgpt.js +458 -26
- package/src/installs/chatgpt.md +814 -0
- package/src/installs/chocolatey.js +447 -0
- package/src/installs/chocolatey.md +661 -0
- package/src/installs/chrome-canary.js +472 -26
- package/src/installs/chrome-canary.md +641 -0
- package/src/installs/chromium.js +645 -26
- package/src/installs/chromium.md +838 -0
- package/src/installs/claude-code.js +558 -26
- package/src/installs/claude-code.md +1173 -0
- package/src/installs/curl.js +361 -26
- package/src/installs/curl.md +714 -0
- package/src/installs/cursor.js +561 -26
- package/src/installs/cursor.md +970 -0
- package/src/installs/dbschema.js +674 -26
- package/src/installs/dbschema.md +925 -0
- package/src/installs/dependencies.md +435 -0
- package/src/installs/development-tools.js +600 -0
- package/src/installs/development-tools.md +977 -0
- package/src/installs/docker.js +1010 -25
- package/src/installs/docker.md +1109 -0
- package/src/installs/drawio.js +1001 -26
- package/src/installs/drawio.md +795 -0
- package/src/installs/elmedia-player.js +328 -25
- package/src/installs/elmedia-player.md +556 -0
- package/src/installs/ffmpeg.js +870 -25
- package/src/installs/ffmpeg.md +852 -0
- package/src/installs/file.js +464 -0
- package/src/installs/file.md +987 -0
- package/src/installs/gemini-cli.js +793 -26
- package/src/installs/gemini-cli.md +1153 -0
- package/src/installs/git.js +382 -26
- package/src/installs/git.md +907 -0
- package/src/installs/gitego.js +931 -26
- package/src/installs/gitego.md +1172 -0
- package/src/installs/go.js +913 -26
- package/src/installs/go.md +958 -0
- package/src/installs/google-chrome.js +801 -25
- package/src/installs/google-chrome.md +862 -0
- package/src/installs/gpg.js +412 -73
- package/src/installs/gpg.md +1056 -0
- package/src/installs/homebrew.js +1015 -26
- package/src/installs/homebrew.md +988 -0
- package/src/installs/imageoptim.js +950 -26
- package/src/installs/imageoptim.md +1119 -0
- package/src/installs/installers.json +2297 -0
- package/src/installs/jq.js +382 -26
- package/src/installs/jq.md +809 -0
- package/src/installs/keyboard-maestro.js +701 -26
- package/src/installs/keyboard-maestro.md +825 -0
- package/src/installs/latex.js +771 -26
- package/src/installs/latex.md +1095 -0
- package/src/installs/lftp.js +338 -26
- package/src/installs/lftp.md +907 -0
- package/src/installs/lsb-release.js +346 -0
- package/src/installs/lsb-release.md +814 -0
- package/src/installs/messenger.js +829 -26
- package/src/installs/messenger.md +900 -0
- package/src/installs/microsoft-office.js +550 -26
- package/src/installs/microsoft-office.md +760 -0
- package/src/installs/microsoft-teams.js +782 -25
- package/src/installs/microsoft-teams.md +886 -0
- package/src/installs/node.js +886 -26
- package/src/installs/node.md +1153 -0
- package/src/installs/nordpass.js +698 -26
- package/src/installs/nordpass.md +921 -0
- package/src/installs/nvm.js +977 -26
- package/src/installs/nvm.md +1057 -0
- package/src/installs/openssh.js +734 -64
- package/src/installs/openssh.md +1056 -0
- package/src/installs/pandoc.js +644 -26
- package/src/installs/pandoc.md +1036 -0
- package/src/installs/pinentry.js +492 -26
- package/src/installs/pinentry.md +1142 -0
- package/src/installs/pngyu.js +851 -26
- package/src/installs/pngyu.md +896 -0
- package/src/installs/postman.js +781 -26
- package/src/installs/postman.md +940 -0
- package/src/installs/procps.js +425 -0
- package/src/installs/procps.md +851 -0
- package/src/installs/safari-tech-preview.js +355 -25
- package/src/installs/safari-tech-preview.md +533 -0
- package/src/installs/sfnt2woff.js +640 -26
- package/src/installs/sfnt2woff.md +795 -0
- package/src/installs/shellcheck.js +463 -26
- package/src/installs/shellcheck.md +1005 -0
- package/src/installs/slack.js +722 -25
- package/src/installs/slack.md +865 -0
- package/src/installs/snagit.js +566 -25
- package/src/installs/snagit.md +844 -0
- package/src/installs/software-properties-common.js +372 -0
- package/src/installs/software-properties-common.md +805 -0
- package/src/installs/spotify.js +858 -25
- package/src/installs/spotify.md +901 -0
- package/src/installs/studio-3t.js +803 -26
- package/src/installs/studio-3t.md +918 -0
- package/src/installs/sublime-text.js +780 -25
- package/src/installs/sublime-text.md +914 -0
- package/src/installs/superwhisper.js +687 -25
- package/src/installs/superwhisper.md +630 -0
- package/src/installs/tailscale.js +727 -26
- package/src/installs/tailscale.md +1100 -0
- package/src/installs/tar.js +389 -0
- package/src/installs/tar.md +946 -0
- package/src/installs/termius.js +780 -26
- package/src/installs/termius.md +844 -0
- package/src/installs/terraform.js +761 -26
- package/src/installs/terraform.md +899 -0
- package/src/installs/tidal.js +752 -25
- package/src/installs/tidal.md +864 -0
- package/src/installs/tmux.js +328 -26
- package/src/installs/tmux.md +1030 -0
- package/src/installs/tree.js +393 -26
- package/src/installs/tree.md +833 -0
- package/src/installs/unzip.js +460 -0
- package/src/installs/unzip.md +879 -0
- package/src/installs/vim.js +403 -26
- package/src/installs/vim.md +1040 -0
- package/src/installs/vlc.js +803 -26
- package/src/installs/vlc.md +927 -0
- package/src/installs/vscode.js +825 -26
- package/src/installs/vscode.md +1002 -0
- package/src/installs/wget.js +415 -0
- package/src/installs/wget.md +791 -0
- package/src/installs/whatsapp.js +710 -25
- package/src/installs/whatsapp.md +854 -0
- package/src/installs/winpty.js +352 -0
- package/src/installs/winpty.md +620 -0
- package/src/installs/woff2.js +535 -26
- package/src/installs/woff2.md +977 -0
- package/src/installs/wsl.js +572 -0
- package/src/installs/wsl.md +699 -0
- package/src/installs/xcode-clt.js +520 -0
- package/src/installs/xcode-clt.md +351 -0
- package/src/installs/xcode.js +542 -26
- package/src/installs/xcode.md +573 -0
- package/src/installs/yarn.js +806 -26
- package/src/installs/yarn.md +1074 -0
- package/src/installs/yq.js +636 -26
- package/src/installs/yq.md +944 -0
- package/src/installs/yt-dlp.js +683 -26
- package/src/installs/yt-dlp.md +946 -0
- package/src/installs/yum-utils.js +297 -0
- package/src/installs/yum-utils.md +648 -0
- package/src/installs/zoom.js +740 -25
- package/src/installs/zoom.md +884 -0
- package/src/scripts/README.md +567 -45
- package/src/scripts/STATUS.md +208 -0
- package/src/scripts/afk.js +395 -7
- package/src/scripts/backup-all.js +731 -9
- package/src/scripts/backup-source.js +711 -8
- package/src/scripts/brewd.js +373 -7
- package/src/scripts/brewi.js +505 -9
- package/src/scripts/brewr.js +512 -9
- package/src/scripts/brews.js +462 -9
- package/src/scripts/brewu.js +488 -7
- package/src/scripts/c.js +185 -7
- package/src/scripts/ccurl.js +325 -8
- package/src/scripts/certbot-crontab-init.js +488 -8
- package/src/scripts/certbot-init.js +641 -9
- package/src/scripts/ch.js +339 -7
- package/src/scripts/claude-danger.js +253 -8
- package/src/scripts/clean-dev.js +419 -8
- package/src/scripts/clear-dns-cache.js +525 -7
- package/src/scripts/clone.js +417 -7
- package/src/scripts/code-all.js +420 -7
- package/src/scripts/count-files.js +195 -8
- package/src/scripts/count-folders.js +195 -8
- package/src/scripts/count.js +248 -8
- package/src/scripts/d.js +203 -7
- package/src/scripts/datauri.js +373 -8
- package/src/scripts/delete-files.js +363 -7
- package/src/scripts/docker-clean.js +410 -8
- package/src/scripts/dp.js +426 -7
- package/src/scripts/e.js +375 -9
- package/src/scripts/empty-trash.js +497 -7
- package/src/scripts/evm.js +428 -9
- package/src/scripts/fetch-github-repos.js +441 -10
- package/src/scripts/get-channel.js +329 -8
- package/src/scripts/get-course.js +384 -11
- package/src/scripts/get-dependencies.js +290 -9
- package/src/scripts/get-folder.js +783 -10
- package/src/scripts/get-tunes.js +411 -10
- package/src/scripts/get-video.js +352 -9
- package/src/scripts/git-backup.js +561 -9
- package/src/scripts/git-clone.js +477 -9
- package/src/scripts/git-pup.js +303 -7
- package/src/scripts/git-push.js +380 -8
- package/src/scripts/h.js +607 -9
- package/src/scripts/hide-desktop-icons.js +483 -7
- package/src/scripts/hide-hidden-files.js +522 -7
- package/src/scripts/install-dependencies-from.js +440 -9
- package/src/scripts/ips.js +647 -10
- package/src/scripts/iso.js +354 -8
- package/src/scripts/killni.js +561 -7
- package/src/scripts/ll.js +451 -8
- package/src/scripts/local-ip.js +310 -8
- package/src/scripts/m.js +508 -8
- package/src/scripts/map.js +293 -8
- package/src/scripts/mkd.js +287 -7
- package/src/scripts/ncu-update-all.js +441 -8
- package/src/scripts/nginx-init.js +702 -12
- package/src/scripts/npmi.js +366 -7
- package/src/scripts/o.js +495 -8
- package/src/scripts/org-by-date.js +321 -7
- package/src/scripts/p.js +208 -7
- package/src/scripts/packages.js +313 -8
- package/src/scripts/path.js +209 -7
- package/src/scripts/ports.js +582 -8
- package/src/scripts/q.js +290 -8
- package/src/scripts/refresh-files.js +378 -10
- package/src/scripts/remove-smaller-files.js +500 -8
- package/src/scripts/rename-files-with-date.js +517 -9
- package/src/scripts/resize-image.js +523 -9
- package/src/scripts/rm-safe.js +653 -8
- package/src/scripts/s.js +525 -9
- package/src/scripts/set-git-public.js +349 -7
- package/src/scripts/show-desktop-icons.js +459 -7
- package/src/scripts/show-hidden-files.js +456 -7
- package/src/scripts/tpa.js +265 -8
- package/src/scripts/tpo.js +264 -7
- package/src/scripts/u.js +489 -7
- package/src/scripts/vpush.js +422 -8
- package/src/scripts/y.js +267 -7
- package/src/utils/common/os.js +94 -2
- package/src/utils/ubuntu/apt.js +13 -7
- package/src/utils/windows/choco.js +82 -26
- package/src/utils/windows/winget.js +89 -27
package/src/installs/pngyu.js
CHANGED
|
@@ -1,44 +1,869 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @fileoverview Install Pngyu.
|
|
4
|
+
* @fileoverview Install Pngyu - a simple PNG image compression tool with a GUI.
|
|
5
|
+
*
|
|
6
|
+
* Pngyu is a cross-platform PNG image file compression tool that wraps pngquant,
|
|
7
|
+
* providing a drag-and-drop graphical interface for batch PNG compression. It
|
|
8
|
+
* achieves significant file size reduction (often 60-80%) by converting 24-bit
|
|
9
|
+
* or 32-bit full-color PNGs to 8-bit indexed color using an excellent color
|
|
10
|
+
* reduction algorithm.
|
|
11
|
+
*
|
|
12
|
+
* IMPORTANT PLATFORM NOTES:
|
|
13
|
+
* - macOS: Pngyu GUI available via Homebrew Cask (macOS 14 and earlier only).
|
|
14
|
+
* For macOS 15 Sequoia and later, pngquant CLI is installed instead.
|
|
15
|
+
* - Windows: Pngyu GUI available via Chocolatey.
|
|
16
|
+
* - Ubuntu/Debian: Pngyu is not available. Installs pngquant CLI instead.
|
|
17
|
+
* - Raspberry Pi OS: Pngyu is not available. Installs pngquant CLI instead.
|
|
18
|
+
* - Amazon Linux: Pngyu is not available. Installs pngquant from EPEL or source.
|
|
19
|
+
* - WSL: Pngyu is not available. Installs pngquant CLI within WSL.
|
|
20
|
+
* - Git Bash: Pngyu is not available. Downloads pngquant Windows binary.
|
|
21
|
+
*
|
|
22
|
+
* NOTE: PNG compression with pngquant is a lossy process involving color
|
|
23
|
+
* reduction. The original image cannot be restored after compression.
|
|
24
|
+
* Always backup important files before compressing.
|
|
25
|
+
*
|
|
5
26
|
* @module installs/pngyu
|
|
6
27
|
*/
|
|
7
28
|
|
|
8
29
|
const os = require('../utils/common/os');
|
|
30
|
+
const shell = require('../utils/common/shell');
|
|
31
|
+
const brew = require('../utils/macos/brew');
|
|
32
|
+
const apt = require('../utils/ubuntu/apt');
|
|
33
|
+
const choco = require('../utils/windows/choco');
|
|
34
|
+
const fs = require('fs');
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Whether this installer requires a desktop environment to function.
|
|
38
|
+
* Pngyu is a GUI PNG compression application.
|
|
39
|
+
*/
|
|
40
|
+
const REQUIRES_DESKTOP = true;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The Homebrew cask name for Pngyu GUI application.
|
|
44
|
+
*/
|
|
45
|
+
const HOMEBREW_CASK_NAME = 'pngyu';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The Homebrew formula name for pngquant CLI tool.
|
|
49
|
+
*/
|
|
50
|
+
const HOMEBREW_PNGQUANT_FORMULA = 'pngquant';
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The APT package name for pngquant on Debian-based systems.
|
|
54
|
+
*/
|
|
55
|
+
const APT_PACKAGE_NAME = 'pngquant';
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The Chocolatey package name for Pngyu GUI on Windows.
|
|
59
|
+
*/
|
|
60
|
+
const CHOCO_PACKAGE_NAME = 'pngyu';
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The Chocolatey package name for pngquant CLI on Windows.
|
|
64
|
+
*/
|
|
65
|
+
const CHOCO_PNGQUANT_PACKAGE = 'pngquant';
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Check if pngquant CLI is available on the system.
|
|
69
|
+
*
|
|
70
|
+
* pngquant is the underlying compression engine used by Pngyu. This function
|
|
71
|
+
* checks if the command-line tool is accessible in the system PATH.
|
|
72
|
+
*
|
|
73
|
+
* @returns {boolean} True if pngquant command is available, false otherwise
|
|
74
|
+
*/
|
|
75
|
+
function isPngquantCommandAvailable() {
|
|
76
|
+
return shell.commandExists('pngquant');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get the installed version of pngquant.
|
|
81
|
+
*
|
|
82
|
+
* Executes 'pngquant --version' and parses the output to extract the version
|
|
83
|
+
* number. The output format is typically "3.0.3 (January 2024)".
|
|
84
|
+
*
|
|
85
|
+
* @returns {Promise<string|null>} The pngquant version string, or null if not installed
|
|
86
|
+
*/
|
|
87
|
+
async function getPngquantVersion() {
|
|
88
|
+
// First check if the command exists to avoid unnecessary process spawning
|
|
89
|
+
if (!isPngquantCommandAvailable()) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Execute pngquant --version to get version information
|
|
94
|
+
const result = await shell.exec('pngquant --version');
|
|
95
|
+
if (result.code === 0 && result.stdout) {
|
|
96
|
+
// Output format: "3.0.3 (January 2024)" or just "3.0.3"
|
|
97
|
+
const version = result.stdout.trim().split(' ')[0];
|
|
98
|
+
return version || result.stdout.trim();
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Check if Pngyu GUI application is installed on macOS.
|
|
105
|
+
*
|
|
106
|
+
* Pngyu is installed as a standard macOS application in /Applications.
|
|
107
|
+
* This function checks for the presence of the .app bundle.
|
|
108
|
+
*
|
|
109
|
+
* @returns {boolean} True if Pngyu.app exists in /Applications, false otherwise
|
|
110
|
+
*/
|
|
111
|
+
function isPngyuInstalledMacOS() {
|
|
112
|
+
try {
|
|
113
|
+
return fs.existsSync('/Applications/Pngyu.app');
|
|
114
|
+
} catch (err) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Get the macOS version number for compatibility checking.
|
|
121
|
+
*
|
|
122
|
+
* Pngyu is not compatible with macOS 15 (Sequoia) and later. This function
|
|
123
|
+
* extracts the major version number from the system to determine compatibility.
|
|
124
|
+
*
|
|
125
|
+
* @returns {Promise<number|null>} The major macOS version number, or null if detection fails
|
|
126
|
+
*/
|
|
127
|
+
async function getMacOSMajorVersion() {
|
|
128
|
+
const result = await shell.exec('sw_vers -productVersion');
|
|
129
|
+
if (result.code === 0 && result.stdout) {
|
|
130
|
+
// Output format: "14.5" or "15.0.1"
|
|
131
|
+
const versionParts = result.stdout.trim().split('.');
|
|
132
|
+
const majorVersion = parseInt(versionParts[0], 10);
|
|
133
|
+
return isNaN(majorVersion) ? null : majorVersion;
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Install Pngyu on macOS using Homebrew.
|
|
140
|
+
*
|
|
141
|
+
* This function handles the complex macOS installation scenario:
|
|
142
|
+
* - On macOS 14 (Sonoma) and earlier: Installs Pngyu GUI via Homebrew Cask
|
|
143
|
+
* - On macOS 15 (Sequoia) and later: Installs pngquant CLI instead (Pngyu incompatible)
|
|
144
|
+
*
|
|
145
|
+
* For Apple Silicon Macs, Rosetta 2 is required for Pngyu since it is an Intel-only
|
|
146
|
+
* application. The function checks for Rosetta 2 availability but does not install it.
|
|
147
|
+
*
|
|
148
|
+
* @returns {Promise<void>}
|
|
149
|
+
*/
|
|
150
|
+
async function install_macos() {
|
|
151
|
+
// Verify Homebrew is available - required for installation
|
|
152
|
+
if (!brew.isInstalled()) {
|
|
153
|
+
console.log('Homebrew is not installed. Please install Homebrew first.');
|
|
154
|
+
console.log('Run: dev install homebrew');
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Detect macOS version to determine installation strategy
|
|
159
|
+
const macOSVersion = await getMacOSMajorVersion();
|
|
160
|
+
console.log(`Detected macOS version: ${macOSVersion || 'unknown'}`);
|
|
161
|
+
|
|
162
|
+
// macOS 15 (Sequoia) and later are incompatible with Pngyu
|
|
163
|
+
// Install pngquant CLI instead as the documented alternative
|
|
164
|
+
if (macOSVersion !== null && macOSVersion >= 15) {
|
|
165
|
+
console.log('');
|
|
166
|
+
console.log('NOTE: Pngyu is not compatible with macOS 15 (Sequoia) and later.');
|
|
167
|
+
console.log('Installing pngquant CLI tool instead...');
|
|
168
|
+
console.log('');
|
|
169
|
+
|
|
170
|
+
await installPngquantMacOS();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// For macOS 14 and earlier, attempt to install Pngyu GUI
|
|
175
|
+
console.log('Checking if Pngyu is already installed...');
|
|
176
|
+
|
|
177
|
+
// Check if Pngyu.app already exists
|
|
178
|
+
if (isPngyuInstalledMacOS()) {
|
|
179
|
+
console.log('Pngyu is already installed, skipping...');
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Also check if Pngyu cask is installed via Homebrew
|
|
184
|
+
const caskInstalled = await brew.isCaskInstalled(HOMEBREW_CASK_NAME);
|
|
185
|
+
if (caskInstalled) {
|
|
186
|
+
console.log('Pngyu is already installed via Homebrew, skipping...');
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Attempt to install Pngyu via Homebrew Cask
|
|
191
|
+
console.log('Installing Pngyu via Homebrew Cask...');
|
|
192
|
+
const result = await shell.exec(`brew install --cask --quiet ${HOMEBREW_CASK_NAME}`);
|
|
193
|
+
|
|
194
|
+
// Handle the case where Pngyu cask has been disabled in Homebrew
|
|
195
|
+
// This can happen if the cask is discontinued upstream
|
|
196
|
+
if (result.code !== 0) {
|
|
197
|
+
const isDiscontinued = result.stderr &&
|
|
198
|
+
(result.stderr.includes('discontinued') || result.stderr.includes('unavailable'));
|
|
199
|
+
|
|
200
|
+
if (isDiscontinued) {
|
|
201
|
+
console.log('');
|
|
202
|
+
console.log('NOTE: Pngyu has been discontinued in Homebrew.');
|
|
203
|
+
console.log('Installing pngquant CLI tool as the alternative...');
|
|
204
|
+
console.log('');
|
|
205
|
+
|
|
206
|
+
await installPngquantMacOS();
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// For other errors, log the failure
|
|
211
|
+
console.log('Failed to install Pngyu via Homebrew Cask.');
|
|
212
|
+
console.log(result.stderr || result.stdout);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Verify installation succeeded
|
|
217
|
+
if (!isPngyuInstalledMacOS()) {
|
|
218
|
+
console.log('Installation may have failed: Pngyu.app not found in /Applications.');
|
|
219
|
+
console.log('');
|
|
220
|
+
console.log('If you encounter Gatekeeper issues, try:');
|
|
221
|
+
console.log(' xattr -d com.apple.quarantine /Applications/Pngyu.app');
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
console.log('Pngyu installed successfully.');
|
|
226
|
+
console.log('');
|
|
227
|
+
console.log('You can find Pngyu in your Applications folder.');
|
|
228
|
+
console.log('');
|
|
229
|
+
console.log('NOTE: On Apple Silicon Macs, Pngyu runs through Rosetta 2.');
|
|
230
|
+
console.log('For better performance, consider using pngquant CLI:');
|
|
231
|
+
console.log(' brew install pngquant');
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Install pngquant CLI on macOS via Homebrew.
|
|
236
|
+
*
|
|
237
|
+
* This is a helper function used when Pngyu GUI is not available or not
|
|
238
|
+
* compatible (e.g., on macOS 15+). pngquant provides identical compression
|
|
239
|
+
* capabilities through the command line.
|
|
240
|
+
*
|
|
241
|
+
* @returns {Promise<void>}
|
|
242
|
+
*/
|
|
243
|
+
async function installPngquantMacOS() {
|
|
244
|
+
// Check if pngquant is already installed
|
|
245
|
+
const existingVersion = await getPngquantVersion();
|
|
246
|
+
if (existingVersion) {
|
|
247
|
+
console.log(`pngquant ${existingVersion} is already installed, skipping...`);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Also check if formula is installed but not in PATH
|
|
252
|
+
const formulaInstalled = await brew.isFormulaInstalled(HOMEBREW_PNGQUANT_FORMULA);
|
|
253
|
+
if (formulaInstalled) {
|
|
254
|
+
console.log('pngquant is already installed via Homebrew, skipping...');
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Install pngquant via Homebrew
|
|
259
|
+
console.log('Installing pngquant via Homebrew...');
|
|
260
|
+
const result = await brew.install(HOMEBREW_PNGQUANT_FORMULA);
|
|
261
|
+
|
|
262
|
+
if (!result.success) {
|
|
263
|
+
console.log('Failed to install pngquant via Homebrew.');
|
|
264
|
+
console.log(result.output);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Verify installation succeeded
|
|
269
|
+
const version = await getPngquantVersion();
|
|
270
|
+
if (!version) {
|
|
271
|
+
console.log('Installation may have failed: pngquant command not found.');
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
console.log(`pngquant ${version} installed successfully.`);
|
|
276
|
+
console.log('');
|
|
277
|
+
console.log('Usage examples:');
|
|
278
|
+
console.log(' pngquant --quality=80-90 image.png');
|
|
279
|
+
console.log(' pngquant --quality=80-90 --output compressed.png image.png');
|
|
280
|
+
console.log('');
|
|
281
|
+
console.log('For batch compression:');
|
|
282
|
+
console.log(' find . -name "*.png" -exec pngquant --quality=80-90 --force --ext .png {} \\;');
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Install pngquant on Ubuntu/Debian using APT.
|
|
287
|
+
*
|
|
288
|
+
* Pngyu GUI is not available for Linux. This function installs pngquant,
|
|
289
|
+
* the underlying command-line tool that provides identical compression
|
|
290
|
+
* capabilities through the terminal.
|
|
291
|
+
*
|
|
292
|
+
* pngquant is available in the default Ubuntu and Debian repositories,
|
|
293
|
+
* so no additional PPAs or repositories are required.
|
|
294
|
+
*
|
|
295
|
+
* @returns {Promise<void>}
|
|
296
|
+
*/
|
|
297
|
+
async function install_ubuntu() {
|
|
298
|
+
console.log('NOTE: Pngyu GUI is not available for Linux.');
|
|
299
|
+
console.log('Installing pngquant CLI tool instead...');
|
|
300
|
+
console.log('');
|
|
301
|
+
|
|
302
|
+
// Check if pngquant is already installed
|
|
303
|
+
const existingVersion = await getPngquantVersion();
|
|
304
|
+
if (existingVersion) {
|
|
305
|
+
console.log(`pngquant ${existingVersion} is already installed, skipping...`);
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Update package index before installing
|
|
310
|
+
console.log('Updating package lists...');
|
|
311
|
+
const updateResult = await apt.update();
|
|
312
|
+
if (!updateResult.success) {
|
|
313
|
+
console.log('Warning: Failed to update package lists. Continuing with installation...');
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Install pngquant via APT
|
|
317
|
+
// The apt.install function handles DEBIAN_FRONTEND=noninteractive and -y flag
|
|
318
|
+
console.log('Installing pngquant via APT...');
|
|
319
|
+
const result = await apt.install(APT_PACKAGE_NAME);
|
|
320
|
+
|
|
321
|
+
if (!result.success) {
|
|
322
|
+
console.log('Failed to install pngquant via APT.');
|
|
323
|
+
console.log(result.output);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Verify installation succeeded
|
|
328
|
+
const version = await getPngquantVersion();
|
|
329
|
+
if (!version) {
|
|
330
|
+
console.log('Installation may have failed: pngquant command not found after install.');
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
console.log(`pngquant ${version} installed successfully.`);
|
|
335
|
+
console.log('');
|
|
336
|
+
console.log('Usage examples:');
|
|
337
|
+
console.log(' pngquant --quality=80-90 image.png');
|
|
338
|
+
console.log(' pngquant --quality=80-90 --output compressed.png image.png');
|
|
339
|
+
console.log('');
|
|
340
|
+
console.log('For batch compression:');
|
|
341
|
+
console.log(' find . -name "*.png" -exec pngquant --quality=80-90 --force --ext .png {} \\;');
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Install pngquant on Ubuntu running in WSL.
|
|
346
|
+
*
|
|
347
|
+
* WSL (Windows Subsystem for Linux) provides a full Ubuntu environment,
|
|
348
|
+
* so the installation process is identical to native Ubuntu using APT.
|
|
349
|
+
*
|
|
350
|
+
* Note that Pngyu GUI cannot run within WSL as it requires a native Windows
|
|
351
|
+
* or macOS environment.
|
|
352
|
+
*
|
|
353
|
+
* @returns {Promise<void>}
|
|
354
|
+
*/
|
|
355
|
+
async function install_ubuntu_wsl() {
|
|
356
|
+
console.log('Detected Ubuntu running in WSL (Windows Subsystem for Linux).');
|
|
357
|
+
console.log('');
|
|
358
|
+
|
|
359
|
+
// Delegate to the standard Ubuntu installer since WSL uses the same APT system
|
|
360
|
+
await install_ubuntu();
|
|
361
|
+
|
|
362
|
+
// Add WSL-specific usage tips
|
|
363
|
+
console.log('');
|
|
364
|
+
console.log('WSL TIPS:');
|
|
365
|
+
console.log(' - Access Windows files through /mnt/c/, /mnt/d/, etc.');
|
|
366
|
+
console.log(' - Example: pngquant --quality=80-90 /mnt/c/Users/You/Pictures/image.png');
|
|
367
|
+
console.log(' - For better I/O performance, copy files to Linux filesystem first.');
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Install pngquant on Raspberry Pi OS using APT.
|
|
372
|
+
*
|
|
373
|
+
* Raspberry Pi OS is Debian-based, so pngquant installation follows the same
|
|
374
|
+
* process as Ubuntu/Debian. The pngquant package is available pre-compiled
|
|
375
|
+
* for both 32-bit (armv7l) and 64-bit (aarch64) ARM architectures.
|
|
376
|
+
*
|
|
377
|
+
* Pngyu GUI is not available for Raspberry Pi.
|
|
378
|
+
*
|
|
379
|
+
* @returns {Promise<void>}
|
|
380
|
+
*/
|
|
381
|
+
async function install_raspbian() {
|
|
382
|
+
console.log('NOTE: Pngyu GUI is not available for Raspberry Pi OS.');
|
|
383
|
+
console.log('Installing pngquant CLI tool instead...');
|
|
384
|
+
console.log('');
|
|
385
|
+
|
|
386
|
+
// Check if pngquant is already installed
|
|
387
|
+
const existingVersion = await getPngquantVersion();
|
|
388
|
+
if (existingVersion) {
|
|
389
|
+
console.log(`pngquant ${existingVersion} is already installed, skipping...`);
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// Update package index before installing
|
|
394
|
+
console.log('Updating package lists...');
|
|
395
|
+
const updateResult = await apt.update();
|
|
396
|
+
if (!updateResult.success) {
|
|
397
|
+
console.log('Warning: Failed to update package lists. Continuing with installation...');
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// Install pngquant via APT
|
|
401
|
+
console.log('Installing pngquant via APT...');
|
|
402
|
+
const result = await apt.install(APT_PACKAGE_NAME);
|
|
403
|
+
|
|
404
|
+
if (!result.success) {
|
|
405
|
+
console.log('Failed to install pngquant via APT.');
|
|
406
|
+
console.log(result.output);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// Verify installation succeeded
|
|
411
|
+
const version = await getPngquantVersion();
|
|
412
|
+
if (!version) {
|
|
413
|
+
console.log('Installation may have failed: pngquant command not found after install.');
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
console.log(`pngquant ${version} installed successfully.`);
|
|
418
|
+
console.log('');
|
|
419
|
+
console.log('Usage examples:');
|
|
420
|
+
console.log(' pngquant --quality=80-90 image.png');
|
|
421
|
+
console.log(' pngquant --quality=80-90 --output compressed.png image.png');
|
|
422
|
+
console.log('');
|
|
423
|
+
console.log('RASPBERRY PI TIP:');
|
|
424
|
+
console.log(' For faster compression on Raspberry Pi, use higher speed settings:');
|
|
425
|
+
console.log(' pngquant --speed 10 --quality=80-90 image.png');
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Install pngquant on Amazon Linux using EPEL or from source.
|
|
430
|
+
*
|
|
431
|
+
* pngquant is not available in the standard Amazon Linux repositories.
|
|
432
|
+
* - On Amazon Linux 2: Available through EPEL (Extra Packages for Enterprise Linux)
|
|
433
|
+
* - On Amazon Linux 2023: EPEL is not fully supported, so this function compiles
|
|
434
|
+
* pngquant from source using Rust/Cargo.
|
|
435
|
+
*
|
|
436
|
+
* Pngyu GUI is not available for Amazon Linux.
|
|
437
|
+
*
|
|
438
|
+
* @returns {Promise<void>}
|
|
439
|
+
*/
|
|
440
|
+
async function install_amazon_linux() {
|
|
441
|
+
console.log('NOTE: Pngyu GUI is not available for Amazon Linux.');
|
|
442
|
+
console.log('Installing pngquant CLI tool instead...');
|
|
443
|
+
console.log('');
|
|
444
|
+
|
|
445
|
+
// Check if pngquant is already installed
|
|
446
|
+
const existingVersion = await getPngquantVersion();
|
|
447
|
+
if (existingVersion) {
|
|
448
|
+
console.log(`pngquant ${existingVersion} is already installed, skipping...`);
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// Detect which package manager is available (dnf for AL2023, yum for AL2)
|
|
453
|
+
const platform = os.detect();
|
|
454
|
+
const packageManager = platform.packageManager;
|
|
455
|
+
|
|
456
|
+
// Try EPEL-based installation first (works on Amazon Linux 2)
|
|
457
|
+
if (packageManager === 'yum') {
|
|
458
|
+
console.log('Attempting to install pngquant via EPEL...');
|
|
459
|
+
|
|
460
|
+
// Enable EPEL repository
|
|
461
|
+
const enableEpel = await shell.exec('sudo amazon-linux-extras install epel -y');
|
|
462
|
+
if (enableEpel.code === 0) {
|
|
463
|
+
// Try to install pngquant from EPEL
|
|
464
|
+
const installResult = await shell.exec('sudo yum install -y pngquant');
|
|
465
|
+
if (installResult.code === 0) {
|
|
466
|
+
const version = await getPngquantVersion();
|
|
467
|
+
if (version) {
|
|
468
|
+
console.log(`pngquant ${version} installed successfully via EPEL.`);
|
|
469
|
+
printPngquantUsage();
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
console.log('EPEL installation failed. Falling back to source compilation...');
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// For Amazon Linux 2023 or when EPEL fails, compile from source
|
|
479
|
+
await installPngquantFromSource();
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Compile and install pngquant from source.
|
|
484
|
+
*
|
|
485
|
+
* This helper function is used when pngquant is not available from package
|
|
486
|
+
* repositories (e.g., Amazon Linux 2023). It installs the necessary build
|
|
487
|
+
* dependencies, Rust toolchain, and compiles pngquant from the official
|
|
488
|
+
* GitHub repository.
|
|
489
|
+
*
|
|
490
|
+
* @returns {Promise<void>}
|
|
491
|
+
*/
|
|
492
|
+
async function installPngquantFromSource() {
|
|
493
|
+
console.log('Installing pngquant from source...');
|
|
494
|
+
console.log('This may take several minutes...');
|
|
495
|
+
console.log('');
|
|
496
|
+
|
|
497
|
+
// Detect package manager
|
|
498
|
+
const platform = os.detect();
|
|
499
|
+
const packageManager = platform.packageManager;
|
|
500
|
+
|
|
501
|
+
// Install build dependencies
|
|
502
|
+
console.log('Installing build dependencies...');
|
|
503
|
+
let depsResult;
|
|
504
|
+
if (packageManager === 'dnf') {
|
|
505
|
+
depsResult = await shell.exec('sudo dnf groupinstall -y "Development Tools" && sudo dnf install -y libpng-devel cmake git');
|
|
506
|
+
} else {
|
|
507
|
+
depsResult = await shell.exec('sudo yum groupinstall -y "Development Tools" && sudo yum install -y libpng-devel cmake git');
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
if (depsResult.code !== 0) {
|
|
511
|
+
console.log('Failed to install build dependencies.');
|
|
512
|
+
console.log(depsResult.stderr || depsResult.stdout);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// Check if Rust is installed, install if needed
|
|
517
|
+
const rustInstalled = shell.commandExists('cargo');
|
|
518
|
+
if (!rustInstalled) {
|
|
519
|
+
console.log('Installing Rust toolchain...');
|
|
520
|
+
const rustResult = await shell.exec('curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y');
|
|
521
|
+
if (rustResult.code !== 0) {
|
|
522
|
+
console.log('Failed to install Rust toolchain.');
|
|
523
|
+
console.log(rustResult.stderr || rustResult.stdout);
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
// Source the Rust environment for this session
|
|
528
|
+
process.env.PATH = `${process.env.HOME}/.cargo/bin:${process.env.PATH}`;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// Clone and build pngquant
|
|
532
|
+
console.log('Cloning pngquant repository...');
|
|
533
|
+
const cloneResult = await shell.exec('cd /tmp && rm -rf pngquant && git clone --recursive https://github.com/kornelski/pngquant.git');
|
|
534
|
+
if (cloneResult.code !== 0) {
|
|
535
|
+
console.log('Failed to clone pngquant repository.');
|
|
536
|
+
console.log(cloneResult.stderr || cloneResult.stdout);
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
console.log('Building pngquant (this may take a few minutes)...');
|
|
541
|
+
const cargoPath = `${process.env.HOME}/.cargo/bin/cargo`;
|
|
542
|
+
const buildResult = await shell.exec(`cd /tmp/pngquant && ${cargoPath} build --release`);
|
|
543
|
+
if (buildResult.code !== 0) {
|
|
544
|
+
console.log('Failed to build pngquant.');
|
|
545
|
+
console.log(buildResult.stderr || buildResult.stdout);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// Install the binary to /usr/local/bin
|
|
550
|
+
console.log('Installing pngquant to /usr/local/bin...');
|
|
551
|
+
const installResult = await shell.exec('sudo cp /tmp/pngquant/target/release/pngquant /usr/local/bin/');
|
|
552
|
+
if (installResult.code !== 0) {
|
|
553
|
+
console.log('Failed to install pngquant binary.');
|
|
554
|
+
console.log(installResult.stderr || installResult.stdout);
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// Clean up
|
|
559
|
+
console.log('Cleaning up build files...');
|
|
560
|
+
await shell.exec('cd /tmp && rm -rf pngquant');
|
|
561
|
+
|
|
562
|
+
// Verify installation
|
|
563
|
+
const version = await getPngquantVersion();
|
|
564
|
+
if (!version) {
|
|
565
|
+
console.log('Installation may have failed: pngquant command not found.');
|
|
566
|
+
console.log('');
|
|
567
|
+
console.log('Ensure /usr/local/bin is in your PATH:');
|
|
568
|
+
console.log(' echo \'export PATH="/usr/local/bin:$PATH"\' >> ~/.bashrc');
|
|
569
|
+
console.log(' source ~/.bashrc');
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
console.log(`pngquant ${version} installed successfully.`);
|
|
574
|
+
printPngquantUsage();
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Print common pngquant usage examples.
|
|
579
|
+
*
|
|
580
|
+
* Helper function to display consistent usage information across platforms.
|
|
581
|
+
*
|
|
582
|
+
* @returns {void}
|
|
583
|
+
*/
|
|
584
|
+
function printPngquantUsage() {
|
|
585
|
+
console.log('');
|
|
586
|
+
console.log('Usage examples:');
|
|
587
|
+
console.log(' pngquant --quality=80-90 image.png');
|
|
588
|
+
console.log(' pngquant --quality=80-90 --output compressed.png image.png');
|
|
589
|
+
console.log('');
|
|
590
|
+
console.log('For batch compression:');
|
|
591
|
+
console.log(' find . -name "*.png" -exec pngquant --quality=80-90 --force --ext .png {} \\;');
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Install Pngyu on Windows using Chocolatey.
|
|
596
|
+
*
|
|
597
|
+
* This function installs the Pngyu GUI application via Chocolatey. Pngyu
|
|
598
|
+
* provides a graphical interface for batch PNG compression with drag-and-drop
|
|
599
|
+
* support on Windows.
|
|
600
|
+
*
|
|
601
|
+
* @returns {Promise<void>}
|
|
602
|
+
*/
|
|
603
|
+
async function install_windows() {
|
|
604
|
+
// Verify Chocolatey is available
|
|
605
|
+
if (!choco.isInstalled()) {
|
|
606
|
+
console.log('Chocolatey is not installed. Please install Chocolatey first.');
|
|
607
|
+
console.log('Run: dev install chocolatey');
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// Check if Pngyu is already installed via Chocolatey
|
|
612
|
+
const isChocoInstalled = await choco.isPackageInstalled(CHOCO_PACKAGE_NAME);
|
|
613
|
+
if (isChocoInstalled) {
|
|
614
|
+
console.log('Pngyu is already installed via Chocolatey, skipping...');
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// Install Pngyu using Chocolatey
|
|
619
|
+
console.log('Installing Pngyu via Chocolatey...');
|
|
620
|
+
const result = await choco.install(CHOCO_PACKAGE_NAME);
|
|
621
|
+
|
|
622
|
+
if (!result.success) {
|
|
623
|
+
console.log('Failed to install Pngyu via Chocolatey.');
|
|
624
|
+
console.log(result.output);
|
|
625
|
+
console.log('');
|
|
626
|
+
console.log('As an alternative, you can install pngquant CLI:');
|
|
627
|
+
console.log(' choco install pngquant -y');
|
|
628
|
+
return;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// Verify installation
|
|
632
|
+
const verified = await choco.isPackageInstalled(CHOCO_PACKAGE_NAME);
|
|
633
|
+
if (!verified) {
|
|
634
|
+
console.log('Installation may have failed: Pngyu package not found after install.');
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
console.log('Pngyu installed successfully.');
|
|
639
|
+
console.log('');
|
|
640
|
+
console.log('You can find Pngyu in your Start menu.');
|
|
641
|
+
console.log('');
|
|
642
|
+
console.log('For command-line usage, also install pngquant:');
|
|
643
|
+
console.log(' choco install pngquant -y');
|
|
644
|
+
}
|
|
9
645
|
|
|
10
646
|
/**
|
|
11
|
-
* Install
|
|
647
|
+
* Install pngquant in Git Bash on Windows using portable binaries.
|
|
648
|
+
*
|
|
649
|
+
* Git Bash runs in a MinGW environment on Windows. This function downloads
|
|
650
|
+
* the official pngquant Windows binary from pngquant.org and places it in
|
|
651
|
+
* ~/bin, which is then added to PATH.
|
|
652
|
+
*
|
|
653
|
+
* Pngyu GUI is not usable from Git Bash as it requires a native Windows
|
|
654
|
+
* graphical environment.
|
|
655
|
+
*
|
|
656
|
+
* @returns {Promise<void>}
|
|
657
|
+
*/
|
|
658
|
+
async function install_gitbash() {
|
|
659
|
+
console.log('Detected Git Bash on Windows.');
|
|
660
|
+
console.log('NOTE: Pngyu GUI requires a native Windows environment.');
|
|
661
|
+
console.log('Installing pngquant CLI tool instead...');
|
|
662
|
+
console.log('');
|
|
663
|
+
|
|
664
|
+
// Check if pngquant is already available
|
|
665
|
+
const existingVersion = await getPngquantVersion();
|
|
666
|
+
if (existingVersion) {
|
|
667
|
+
console.log(`pngquant ${existingVersion} is already installed, skipping...`);
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// Create ~/bin directory if it doesn't exist
|
|
672
|
+
console.log('Creating ~/bin directory...');
|
|
673
|
+
const mkdirResult = await shell.exec('mkdir -p ~/bin');
|
|
674
|
+
if (mkdirResult.code !== 0) {
|
|
675
|
+
console.log('Failed to create ~/bin directory.');
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// Download pngquant Windows binary from official source
|
|
680
|
+
console.log('Downloading pngquant from pngquant.org...');
|
|
681
|
+
const downloadUrl = 'https://pngquant.org/pngquant-windows.zip';
|
|
682
|
+
const downloadResult = await shell.exec(`cd /tmp && curl -L -o pngquant.zip "${downloadUrl}"`);
|
|
683
|
+
|
|
684
|
+
if (downloadResult.code !== 0) {
|
|
685
|
+
console.log('Failed to download pngquant.');
|
|
686
|
+
console.log(downloadResult.stderr || downloadResult.stdout);
|
|
687
|
+
console.log('');
|
|
688
|
+
console.log('If you encounter certificate errors, try:');
|
|
689
|
+
console.log(` curl -L -k -o /tmp/pngquant.zip "${downloadUrl}"`);
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
// Extract the binary
|
|
694
|
+
console.log('Extracting pngquant...');
|
|
695
|
+
const extractResult = await shell.exec('cd /tmp && unzip -q pngquant.zip -d /tmp/pngquant-extract 2>/dev/null || powershell -command "Expand-Archive -Path \'/tmp/pngquant.zip\' -DestinationPath \'/tmp/pngquant-extract\'"');
|
|
696
|
+
|
|
697
|
+
if (extractResult.code !== 0) {
|
|
698
|
+
console.log('Failed to extract pngquant archive.');
|
|
699
|
+
console.log(extractResult.stderr || extractResult.stdout);
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// Move the executable to ~/bin
|
|
704
|
+
console.log('Installing pngquant to ~/bin...');
|
|
705
|
+
const moveResult = await shell.exec('mv /tmp/pngquant-extract/pngquant.exe ~/bin/');
|
|
706
|
+
|
|
707
|
+
if (moveResult.code !== 0) {
|
|
708
|
+
console.log('Failed to install pngquant binary.');
|
|
709
|
+
console.log(moveResult.stderr || moveResult.stdout);
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// Clean up
|
|
714
|
+
await shell.exec('rm -rf /tmp/pngquant.zip /tmp/pngquant-extract');
|
|
715
|
+
|
|
716
|
+
// Check if ~/bin is in PATH and add it if needed
|
|
717
|
+
const pathCheck = await shell.exec('echo $PATH | grep -q "$HOME/bin"');
|
|
718
|
+
if (pathCheck.code !== 0) {
|
|
719
|
+
console.log('Adding ~/bin to PATH in ~/.bashrc...');
|
|
720
|
+
await shell.exec('echo \'export PATH="$HOME/bin:$PATH"\' >> ~/.bashrc');
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
// Verify installation using the full path
|
|
724
|
+
const verifyResult = await shell.exec('~/bin/pngquant.exe --version');
|
|
725
|
+
if (verifyResult.code !== 0) {
|
|
726
|
+
console.log('Installation may have failed: pngquant verification failed.');
|
|
727
|
+
console.log('');
|
|
728
|
+
console.log('Try running:');
|
|
729
|
+
console.log(' source ~/.bashrc');
|
|
730
|
+
console.log(' pngquant --version');
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
// Parse version from output
|
|
735
|
+
const versionMatch = verifyResult.stdout.trim().split(' ')[0];
|
|
736
|
+
const version = versionMatch || verifyResult.stdout.trim();
|
|
737
|
+
|
|
738
|
+
console.log(`pngquant ${version} installed successfully.`);
|
|
739
|
+
console.log('');
|
|
740
|
+
console.log('Restart Git Bash or run: source ~/.bashrc');
|
|
741
|
+
console.log('');
|
|
742
|
+
console.log('Usage examples:');
|
|
743
|
+
console.log(' pngquant --quality=80-90 image.png');
|
|
744
|
+
console.log(' pngquant --quality=80-90 --output compressed.png image.png');
|
|
745
|
+
console.log('');
|
|
746
|
+
console.log('GIT BASH TIP:');
|
|
747
|
+
console.log(' For Windows paths, use: MSYS_NO_PATHCONV=1 pngquant /c/Users/Me/image.png');
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* Check if Pngyu (or pngquant) is already installed on the system.
|
|
752
|
+
*
|
|
753
|
+
* This function checks for Pngyu/pngquant installation using platform-appropriate methods:
|
|
754
|
+
* - macOS: Checks if Pngyu cask is installed OR pngquant formula is installed
|
|
755
|
+
* - Windows: Checks if Chocolatey package 'pngyu' is installed
|
|
756
|
+
* - Linux/Git Bash: Checks if 'pngquant' command exists in PATH
|
|
757
|
+
*
|
|
758
|
+
* @returns {Promise<boolean>} True if Pngyu or pngquant is installed, false otherwise
|
|
759
|
+
*/
|
|
760
|
+
async function isInstalled() {
|
|
761
|
+
const platform = os.detect();
|
|
762
|
+
|
|
763
|
+
if (platform.type === 'macos') {
|
|
764
|
+
// Check for Pngyu app or pngquant CLI
|
|
765
|
+
const caskInstalled = await brew.isCaskInstalled(HOMEBREW_CASK_NAME);
|
|
766
|
+
if (caskInstalled) return true;
|
|
767
|
+
const formulaInstalled = await brew.isFormulaInstalled(HOMEBREW_PNGQUANT_FORMULA);
|
|
768
|
+
if (formulaInstalled) return true;
|
|
769
|
+
return isPngyuInstalledMacOS();
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
if (platform.type === 'windows') {
|
|
773
|
+
return choco.isPackageInstalled(CHOCO_PACKAGE_NAME);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// Linux and Git Bash: Check if pngquant command exists
|
|
777
|
+
return shell.commandExists('pngquant');
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* Check if this installer is supported on the current platform.
|
|
782
|
+
* Pngyu (or pngquant CLI) is supported on all major platforms.
|
|
783
|
+
* @returns {boolean} True if installation is supported on this platform
|
|
784
|
+
*/
|
|
785
|
+
function isEligible() {
|
|
786
|
+
const platform = os.detect();
|
|
787
|
+
const supportedPlatforms = ['macos', 'ubuntu', 'debian', 'wsl', 'raspbian', 'amazon_linux', 'rhel', 'fedora', 'windows', 'gitbash'];
|
|
788
|
+
if (!supportedPlatforms.includes(platform.type)) {
|
|
789
|
+
return false;
|
|
790
|
+
}
|
|
791
|
+
if (REQUIRES_DESKTOP && !os.isDesktopAvailable()) {
|
|
792
|
+
return false;
|
|
793
|
+
}
|
|
794
|
+
return true;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Main installation entry point - detects platform and runs appropriate installer.
|
|
799
|
+
*
|
|
800
|
+
* This function detects the current operating system and dispatches to the
|
|
801
|
+
* appropriate platform-specific installer function. It handles the complexity
|
|
802
|
+
* of installing either the Pngyu GUI (where available) or the pngquant CLI
|
|
803
|
+
* (on platforms where Pngyu is not supported).
|
|
804
|
+
*
|
|
805
|
+
* Supported platforms:
|
|
806
|
+
* - macOS: Pngyu GUI (macOS 14 and earlier) or pngquant CLI (macOS 15+)
|
|
807
|
+
* - Windows: Pngyu GUI via Chocolatey
|
|
808
|
+
* - Ubuntu/Debian: pngquant CLI via APT
|
|
809
|
+
* - Ubuntu on WSL: pngquant CLI via APT
|
|
810
|
+
* - Raspberry Pi OS: pngquant CLI via APT
|
|
811
|
+
* - Amazon Linux/RHEL: pngquant CLI via EPEL or source
|
|
812
|
+
* - Git Bash: pngquant CLI portable binary
|
|
12
813
|
*
|
|
13
814
|
* @returns {Promise<void>}
|
|
14
815
|
*/
|
|
15
816
|
async function install() {
|
|
16
817
|
const platform = os.detect();
|
|
17
818
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
819
|
+
// Map platform types to their corresponding installer functions
|
|
820
|
+
// Multiple platform types can map to the same installer (e.g., debian and ubuntu)
|
|
821
|
+
const installers = {
|
|
822
|
+
'macos': install_macos,
|
|
823
|
+
'ubuntu': install_ubuntu,
|
|
824
|
+
'debian': install_ubuntu,
|
|
825
|
+
'wsl': install_ubuntu_wsl,
|
|
826
|
+
'raspbian': install_raspbian,
|
|
827
|
+
'amazon_linux': install_amazon_linux,
|
|
828
|
+
'rhel': install_amazon_linux,
|
|
829
|
+
'fedora': install_amazon_linux,
|
|
830
|
+
'windows': install_windows,
|
|
831
|
+
'gitbash': install_gitbash,
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
// Look up the installer for the detected platform
|
|
835
|
+
const installer = installers[platform.type];
|
|
836
|
+
|
|
837
|
+
// If no installer exists for this platform, inform the user gracefully
|
|
838
|
+
// Do not throw an error - just log a message and return
|
|
839
|
+
if (!installer) {
|
|
840
|
+
console.log(`Pngyu is not available for ${platform.type}.`);
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// Run the platform-specific installer
|
|
845
|
+
await installer();
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// Export all functions for use as a module and for testing
|
|
849
|
+
module.exports = {
|
|
850
|
+
REQUIRES_DESKTOP,
|
|
851
|
+
install,
|
|
852
|
+
isInstalled,
|
|
853
|
+
isEligible,
|
|
854
|
+
install_macos,
|
|
855
|
+
install_ubuntu,
|
|
856
|
+
install_ubuntu_wsl,
|
|
857
|
+
install_raspbian,
|
|
858
|
+
install_amazon_linux,
|
|
859
|
+
install_windows,
|
|
860
|
+
install_gitbash,
|
|
861
|
+
};
|
|
41
862
|
|
|
863
|
+
// Allow direct execution: node pngyu.js
|
|
42
864
|
if (require.main === module) {
|
|
43
|
-
install()
|
|
865
|
+
install().catch(err => {
|
|
866
|
+
console.error(err.message);
|
|
867
|
+
process.exit(1);
|
|
868
|
+
});
|
|
44
869
|
}
|