respimagen 2.0.2 → 2.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.
@@ -14,20 +14,22 @@ jobs:
14
14
  - uses: actions/checkout@v4
15
15
  - uses: actions/setup-node@v4
16
16
  with:
17
- node-version: 20
17
+ node-version: 24
18
18
  - run: npm ci
19
19
  - run: npm test
20
20
 
21
21
  publish-npm:
22
22
  needs: build
23
23
  runs-on: ubuntu-latest
24
+ permissions:
25
+ id-token: write
26
+ contents: read
24
27
  steps:
25
28
  - uses: actions/checkout@v4
26
29
  - uses: actions/setup-node@v4
27
30
  with:
28
- node-version: 20
31
+ node-version: 24
29
32
  registry-url: https://registry.npmjs.org/
33
+ - run: npm -v
30
34
  - run: npm ci
31
35
  - run: npm publish
32
- env:
33
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
package/index.js CHANGED
@@ -46,12 +46,25 @@ const argv = yargs(process.argv.slice(2))
46
46
  const { input, outputdir } = argv;
47
47
  const sizes = [];
48
48
 
49
+ const parseSize = (value) => {
50
+ const str = String(value).trim();
51
+ const match = str.match(/^(\d+)(?:\s*[x×]\s*\d+)?$/i);
52
+ if (!match) return null;
53
+ const parsed = parseInt(match[1], 10);
54
+ return Number.isFinite(parsed) ? parsed : null;
55
+ };
56
+
49
57
  if (argv.sizes) {
50
58
  // yargs may parse a single numeric size as Number (e.g. -s 100),
51
59
  // so coerce to string before splitting to avoid calling .split on a Number.
52
60
  const sizesRaw =
53
61
  typeof argv.sizes === "string" ? argv.sizes : String(argv.sizes);
54
- sizes.push(...sizesRaw.split(",").map((s) => parseInt(s)));
62
+ sizes.push(
63
+ ...sizesRaw
64
+ .split(",")
65
+ .map((s) => parseSize(s))
66
+ .filter((s) => s !== null)
67
+ );
55
68
  }
56
69
 
57
70
  const options = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "respimagen",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -26,6 +26,6 @@
26
26
  },
27
27
  "repository": {
28
28
  "type": "git",
29
- "url": "git+https://github.com/devinekask/respimagen.git"
29
+ "url": "https://github.com/devinekask/respimagen"
30
30
  }
31
- }
31
+ }
package/readme.md CHANGED
@@ -4,11 +4,35 @@ This is a Node.js script and library that generates responsive images for your w
4
4
 
5
5
  Feel free to use it and modify it to your needs.
6
6
 
7
- ## CLI Usage
7
+ ## Installation
8
+
9
+ Use it via npx:
10
+
11
+ ```bash
12
+ npx respimagen
13
+ ```
14
+
15
+ or install it globally using npm:
8
16
 
9
17
  ```bash
10
- node index.js <input> -s [sizes] -t [filetypes] -o [outputdir] -c [clear]
18
+ npm install -g respimagen
19
+ ```
20
+
21
+ ### Show help
22
+
23
+ ```bash
24
+ respimagen --help
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```bash
30
+ respimagen <input> -s [sizes] -t [filetypes] -o [outputdir] -c [clear]
31
+ ```
32
+
33
+ ### Options
11
34
 
35
+ ``` bash
12
36
  Positional Arguments:
13
37
  input file or directory to process [required]
14
38
 
@@ -24,18 +48,32 @@ Options:
24
48
  -c clear the output directory before processing, default false
25
49
  [boolean] [default: false]
26
50
 
27
- Examples:
28
- node index.js beach.jpg -s 500,750 -t webp,avif
29
- Resize and convert beach.jpg to 500px and 750px in webp and avif format
51
+ ```
52
+
53
+ ## Examples
54
+
55
+ Resize and convert beach.jpg to 500px and 750px in webp and avif format.
56
+
57
+ ```bash
58
+ respimagen beach.jpg -s 500,750 -t webp,avif
59
+ ```
60
+
61
+ Convert all images to avif, keeping original dimensions
30
62
 
31
- node index.js ./photos
32
- Convert all images to avif, keeping original dimensions
63
+ ```bash
64
+ respimagen ./photos
65
+ ```
33
66
 
34
- node index.js ./photos -s 300,500,700
35
- Process all images with multiple sizes (avif format)
67
+ Process all images with multiple sizes (avif format)
36
68
 
37
- node index.js ./photos -s 300,500,700 -t webp,avif -o output -c
38
- Process all images with multiple sizes and formats, clearing output first
69
+ ```bash
70
+ respimagen ./photos -s 300,500,700
71
+ ```
72
+
73
+ Process all images with multiple sizes and formats, clearing output first
74
+
75
+ ```bash
76
+ respimagen ./photos -s 300,500,700 -t webp,avif -o output -c
39
77
  ```
40
78
 
41
79
  ## Programmatic Usage
@@ -64,3 +64,51 @@ test("integration CLI single file", async (t) => {
64
64
  await fs.rm(tmpDir, { recursive: true, force: true }).catch(() => {});
65
65
  await fs.rm(fixturesDir, { recursive: true, force: true }).catch(() => {});
66
66
  });
67
+
68
+ test("integration CLI accepts width×height sizes", async () => {
69
+ await ensureDir(tmpDir);
70
+ await ensureDir(fixturesDir);
71
+
72
+ const inputImage = path.join(fixturesDir, "test.png");
73
+ const outDir = path.join(tmpDir, "output");
74
+
75
+ // create a tiny 200x200 red PNG
76
+ await sharp({
77
+ create: {
78
+ width: 200,
79
+ height: 200,
80
+ channels: 3,
81
+ background: { r: 255, g: 0, b: 0 },
82
+ },
83
+ })
84
+ .png()
85
+ .toFile(inputImage);
86
+
87
+ const nodeBin = process.execPath;
88
+ const cliArgs = [
89
+ "index.js",
90
+ inputImage,
91
+ "-s",
92
+ "70×50, 40×20",
93
+ "-t",
94
+ "jpeg",
95
+ "-o",
96
+ outDir,
97
+ "-c",
98
+ ];
99
+
100
+ const { stdout } = await run(nodeBin, cliArgs);
101
+ assert.match(stdout, /Everything done/);
102
+
103
+ const expectedFiles = [
104
+ path.join(outDir, "test-70.jpeg"),
105
+ path.join(outDir, "test-40.jpeg"),
106
+ ];
107
+ for (const f of expectedFiles) {
108
+ const stat = await fs.stat(f);
109
+ assert.ok(stat.isFile());
110
+ }
111
+
112
+ await fs.rm(tmpDir, { recursive: true, force: true }).catch(() => {});
113
+ await fs.rm(fixturesDir, { recursive: true, force: true }).catch(() => {});
114
+ });