@akurasiudara/img2webp 1.0.0 → 1.1.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/README.md CHANGED
@@ -4,31 +4,15 @@ Simple command-line tool to convert images (JPG, JPEG, PNG) to WebP format.
4
4
 
5
5
  ## Installation
6
6
 
7
- ### Via npm (Global)
8
7
  ```bash
9
8
  npm install -g @akurasiudara/img2webp
10
9
  ```
11
10
 
12
- ### Prerequisites
13
- - **cwebp** must be installed on your system
14
- - **bash** (available on Linux/macOS, on Windows use WSL or Git Bash)
15
-
16
- #### Install cwebp:
17
-
18
- **Ubuntu/Debian:**
19
- ```bash
20
- sudo apt update
21
- sudo apt install webp
22
- ```
11
+ **That's it!** The package includes all necessary WebP conversion tools automatically.
23
12
 
24
- **macOS (Homebrew):**
25
- ```bash
26
- brew install webp
27
- ```
28
-
29
- **Windows:**
30
- - Download from [Google WebP](https://developers.google.com/speed/webp/download)
31
- - Or use [Chocolatey](https://chocolatey.org/): `choco install webp`
13
+ ### Requirements
14
+ - **Node.js** (v12 or higher)
15
+ - **bash** (available on Linux/macOS, on Windows use WSL or Git Bash)
32
16
 
33
17
  ## Usage
34
18
 
package/bin/img2webp CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  const { spawn } = require('child_process');
4
4
  const path = require('path');
@@ -13,13 +13,18 @@ if (!fs.existsSync(scriptPath)) {
13
13
  process.exit(1);
14
14
  }
15
15
 
16
+ // Set environment variable untuk cwebp-bin path
17
+ const cwebpPath = require('cwebp-bin');
18
+ process.env.CWEBP_PATH = cwebpPath;
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.1.0",
4
4
  "description": "Simple command-line tool to convert images to WebP format",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -21,7 +21,9 @@
21
21
  "README.md",
22
22
  "LICENSE"
23
23
  ],
24
- "dependencies": {},
24
+ "dependencies": {
25
+ "cwebp-bin": "^7.1.0"
26
+ },
25
27
  "repository": {
26
28
  "type": "git",
27
29
  "url": "git+https://github.com/akurasiudara/img2webp.git"
package/webp.sh CHANGED
@@ -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"