@akurasiudara/img2webp 1.0.0 → 1.2.0

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/INSTALL.md ADDED
@@ -0,0 +1,133 @@
1
+ # Installation Guide
2
+
3
+ This guide covers various ways to install and use `img2webp`.
4
+
5
+ ## Package Managers
6
+
7
+ ### npm (Node Package Manager)
8
+ ```bash
9
+ # Global installation
10
+ npm install -g @akurasiudara/img2webp
11
+
12
+ # Local installation in project
13
+ npm install @akurasiudara/img2webp
14
+
15
+ # One-time use without installation
16
+ npx @akurasiudara/img2webp photo.jpg 85
17
+ ```
18
+
19
+ ### yarn
20
+ ```bash
21
+ # Global installation
22
+ yarn global add @akurasiudara/img2webp
23
+
24
+ # Local installation in project
25
+ yarn add @akurasiudara/img2webp
26
+
27
+ # One-time use
28
+ yarn dlx @akurasiudara/img2webp photo.jpg 85
29
+ ```
30
+
31
+ ### pnpm (Performant npm)
32
+ ```bash
33
+ # Global installation
34
+ pnpm install -g @akurasiudara/img2webp
35
+
36
+ # Local installation
37
+ pnpm install @akurasiudara/img2webp
38
+
39
+ # One-time use
40
+ pnpm dlx @akurasiudara/img2webp photo.jpg 85
41
+ ```
42
+
43
+ ### bun (Fast all-in-one toolkit)
44
+ ```bash
45
+ # Global installation
46
+ bun install -g @akurasiudara/img2webp
47
+
48
+ # Local installation
49
+ bun install @akurasiudara/img2webp
50
+
51
+ # One-time use
52
+ bunx @akurasiudara/img2webp photo.jpg 85
53
+ ```
54
+
55
+ ## Direct Installation
56
+
57
+ ### From GitHub
58
+ ```bash
59
+ # npm
60
+ npm install -g github:akurasiudara/img2webp
61
+
62
+ # yarn
63
+ yarn global add github:akurasiudara/img2webp
64
+
65
+ # pnpm
66
+ pnpm install -g github:akurasiudara/img2webp
67
+
68
+ # bun
69
+ bun install -g github:akurasiudara/img2webp
70
+ ```
71
+
72
+ ### From tarball
73
+ ```bash
74
+ npm install -g https://github.com/akurasiudara/img2webp/archive/main.tar.gz
75
+ ```
76
+
77
+ ## Verification
78
+
79
+ After installation, verify it works:
80
+
81
+ ```bash
82
+ # Check version
83
+ img2webp --version
84
+
85
+ # Show help
86
+ img2webp --help
87
+
88
+ # Test conversion (if you have a test image)
89
+ img2webp test.jpg 85
90
+ ```
91
+
92
+ ## Troubleshooting
93
+
94
+ ### Command not found
95
+ If you get "command not found" error:
96
+
97
+ ```bash
98
+ # Check npm global bin directory
99
+ npm config get prefix
100
+
101
+ # Add to PATH (add to ~/.bashrc or ~/.zshrc)
102
+ export PATH="$(npm config get prefix)/bin:$PATH"
103
+ ```
104
+
105
+ ### Permission errors on Linux/macOS
106
+ ```bash
107
+ # Option 1: Use sudo (not recommended)
108
+ sudo npm install -g @akurasiudara/img2webp
109
+
110
+ # Option 2: Configure npm to use different directory
111
+ npm config set prefix ~/.local
112
+ export PATH="~/.local/bin:$PATH"
113
+ ```
114
+
115
+ ### Windows specific
116
+ - Use Git Bash, WSL, or PowerShell with bash available
117
+ - Consider using Windows Package Manager in the future
118
+
119
+ ## Uninstall
120
+
121
+ ```bash
122
+ # npm
123
+ npm uninstall -g @akurasiudara/img2webp
124
+
125
+ # yarn
126
+ yarn global remove @akurasiudara/img2webp
127
+
128
+ # pnpm
129
+ pnpm uninstall -g @akurasiudara/img2webp
130
+
131
+ # bun
132
+ bun remove -g @akurasiudara/img2webp
133
+ ```
package/README.md CHANGED
@@ -4,31 +4,80 @@ Simple command-line tool to convert images (JPG, JPEG, PNG) to WebP format.
4
4
 
5
5
  ## Installation
6
6
 
7
- ### Via npm (Global)
7
+ ### Via npm
8
8
  ```bash
9
9
  npm install -g @akurasiudara/img2webp
10
10
  ```
11
11
 
12
- ### Prerequisites
13
- - **cwebp** must be installed on your system
14
- - **bash** (available on Linux/macOS, on Windows use WSL or Git Bash)
12
+ ### Via yarn
13
+ ```bash
14
+ yarn global add @akurasiudara/img2webp
15
+ ```
16
+
17
+ ### Via pnpm
18
+ ```bash
19
+ pnpm install -g @akurasiudara/img2webp
20
+ ```
21
+
22
+ ### Via bun
23
+ ```bash
24
+ bun install -g @akurasiudara/img2webp
25
+ ```
26
+
27
+ ### Alternative Installation Methods
15
28
 
16
- #### Install cwebp:
29
+ #### Direct from GitHub
30
+ ```bash
31
+ # Via npm
32
+ npm install -g akurasiudara/img2webp
33
+
34
+ # Via bun
35
+ bun install -g github:akurasiudara/img2webp
36
+ ```
17
37
 
18
- **Ubuntu/Debian:**
38
+ #### Using npx (No Installation Required)
19
39
  ```bash
20
- sudo apt update
21
- sudo apt install webp
40
+ npx @akurasiudara/img2webp --help
41
+ npx @akurasiudara/img2webp photo.jpg 85
22
42
  ```
23
43
 
24
- **macOS (Homebrew):**
44
+ #### Using bunx (Bun equivalent of npx)
25
45
  ```bash
26
- brew install webp
46
+ bunx @akurasiudara/img2webp --help
47
+ bunx @akurasiudara/img2webp photo.jpg 85
27
48
  ```
28
49
 
29
- **Windows:**
30
- - Download from [Google WebP](https://developers.google.com/speed/webp/download)
31
- - Or use [Chocolatey](https://chocolatey.org/): `choco install webp`
50
+ ### Package Manager Compatibility
51
+
52
+ | Package Manager | Command | Status |
53
+ |----------------|---------|---------|
54
+ | **npm** | `npm install -g @akurasiudara/img2webp` | ✅ Full support |
55
+ | **yarn** | `yarn global add @akurasiudara/img2webp` | ✅ Full support |
56
+ | **pnpm** | `pnpm install -g @akurasiudara/img2webp` | ✅ Full support |
57
+ | **bun** | `bun install -g @akurasiudara/img2webp` | ✅ Full support |
58
+ | **npx** | `npx @akurasiudara/img2webp` | ✅ No installation needed |
59
+ | **bunx** | `bunx @akurasiudara/img2webp` | ✅ No installation needed |
60
+
61
+ ### Requirements
62
+ - **Node.js** (v12 or higher) or **Bun runtime**
63
+ - **bash** (available on Linux/macOS, on Windows use WSL or Git Bash)
64
+
65
+ ## Platform Support
66
+
67
+ ### Operating Systems
68
+ - ✅ **Linux** (x64, arm64)
69
+ - ✅ **macOS** (Intel, Apple Silicon)
70
+ - ✅ **Windows** (x64) with WSL/Git Bash
71
+
72
+ ### JavaScript Runtimes
73
+ - ✅ **Node.js** v12+
74
+ - ✅ **Bun** v0.1+
75
+
76
+ ### Package Managers
77
+ - ✅ **npm** (Node Package Manager)
78
+ - ✅ **yarn** (Yet Another Resource Negotiator)
79
+ - ✅ **pnpm** (Performant npm)
80
+ - ✅ **bun** (Fast all-in-one toolkit)
32
81
 
33
82
  ## Usage
34
83
 
package/bin/img2webp CHANGED
@@ -13,13 +13,18 @@ if (!fs.existsSync(scriptPath)) {
13
13
  process.exit(1);
14
14
  }
15
15
 
16
+ // Set environment variable untuk libwebp-static path
17
+ const libwebpStatic = require('libwebp-static');
18
+ process.env.CWEBP_PATH = libwebpStatic.cwebp;
19
+
16
20
  // Ambil arguments dari command line
17
21
  const args = process.argv.slice(2);
18
22
 
19
23
  // Jalankan script bash dengan arguments
20
24
  const child = spawn('bash', [scriptPath, ...args], {
21
25
  stdio: 'inherit',
22
- cwd: process.cwd()
26
+ cwd: process.cwd(),
27
+ env: process.env
23
28
  });
24
29
 
25
30
  child.on('close', (code) => {
@@ -29,6 +34,7 @@ child.on('close', (code) => {
29
34
  child.on('error', (err) => {
30
35
  if (err.code === 'ENOENT') {
31
36
  console.error('Error: Bash not found. This tool requires bash to be installed.');
37
+ console.error('On Windows, you can use Git Bash or WSL.');
32
38
  } else {
33
39
  console.error('Error:', err.message);
34
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akurasiudara/img2webp",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Simple command-line tool to convert images to WebP format",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -9,19 +9,23 @@
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1"
11
11
  },
12
- "keywords": ["webp", "image", "converter", "cli", "img2webp"],
12
+ "keywords": ["webp", "image", "converter", "cli", "img2webp", "bun", "yarn", "pnpm", "cross-platform"],
13
13
  "author": "Ifan Irfansyah",
14
14
  "license": "MIT",
15
15
  "engines": {
16
- "node": ">=12.0.0"
16
+ "node": ">=12.0.0",
17
+ "bun": ">=0.1.0"
17
18
  },
18
19
  "files": [
19
20
  "bin/",
20
21
  "webp.sh",
21
22
  "README.md",
23
+ "INSTALL.md",
22
24
  "LICENSE"
23
25
  ],
24
- "dependencies": {},
26
+ "dependencies": {
27
+ "libwebp-static": "^1.0.4"
28
+ },
25
29
  "repository": {
26
30
  "type": "git",
27
31
  "url": "git+https://github.com/akurasiudara/img2webp.git"
package/webp.sh CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
3
  # Version and help
4
- VERSION="1.0.0"
4
+ VERSION="1.2.0"
5
5
  SCRIPT_NAME="img2webp"
6
6
 
7
7
  show_help() {
@@ -72,10 +72,16 @@ esac
72
72
  QUALITY=${2:-80}
73
73
  INPUT_FILE="$1"
74
74
 
75
- # Check if cwebp is installed
76
- if ! command -v cwebp >/dev/null 2>&1; then
77
- echo "Error: cwebp is not installed!"
78
- echo "Please install webp tools:"
75
+ # Check if cwebp is available
76
+ CWEBP_CMD="cwebp"
77
+
78
+ # Use bundled cwebp-bin if available (from Node.js wrapper)
79
+ if [[ -n "$CWEBP_PATH" && -f "$CWEBP_PATH" ]]; then
80
+ CWEBP_CMD="$CWEBP_PATH"
81
+ elif ! command -v cwebp >/dev/null 2>&1; then
82
+ echo "Error: cwebp is not available!"
83
+ echo "This package should include cwebp binary automatically."
84
+ echo "If this error persists, please install cwebp manually:"
79
85
  echo " Ubuntu/Debian: sudo apt install webp"
80
86
  echo " macOS: brew install webp"
81
87
  echo " Windows: choco install webp"
@@ -95,7 +101,7 @@ convert_file() {
95
101
  return
96
102
  fi
97
103
 
98
- if cwebp -q "$QUALITY" "$img" -o "$output" >/dev/null 2>&1; then
104
+ if $CWEBP_CMD -q "$QUALITY" "$img" -o "$output" >/dev/null 2>&1; then
99
105
  echo "Converted: $img -> $output (quality=$QUALITY)"
100
106
  else
101
107
  echo "Failed to convert: $img"