@lesjoursfr/gifsicle-wrapper 6.0.0 → 6.0.1
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/package.json +17 -23
- package/src/core/color.ts +0 -28
- package/src/core/input.ts +0 -14
- package/src/core/optimize.ts +0 -49
- package/src/core/output.ts +0 -63
- package/src/core/resize.ts +0 -178
- package/src/gifsicle.ts +0 -33
- package/src/index.ts +0 -13
- package/src/install.ts +0 -51
- package/src/toolbox/is-gif.ts +0 -9
- package/src/wrapper.ts +0 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lesjoursfr/gifsicle-wrapper",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Wrapper for Gifsicle",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -17,14 +17,19 @@
|
|
|
17
17
|
"engines": {
|
|
18
18
|
"node": "22.x || 24.x"
|
|
19
19
|
},
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
20
|
+
"keywords": [
|
|
21
|
+
"gif",
|
|
22
|
+
"gifsicle",
|
|
23
|
+
"image",
|
|
24
|
+
"img",
|
|
25
|
+
"compress",
|
|
26
|
+
"resize",
|
|
27
|
+
"minify",
|
|
28
|
+
"optimize"
|
|
27
29
|
],
|
|
30
|
+
"main": "./lib/index.js",
|
|
31
|
+
"types": "./lib/index.d.ts",
|
|
32
|
+
"type": "module",
|
|
28
33
|
"scripts": {
|
|
29
34
|
"freshlock": "rm -rf node_modules/ && rm .yarn/install-state.gz && rm yarn.lock && yarn",
|
|
30
35
|
"postinstall": "node install/install.js",
|
|
@@ -37,19 +42,8 @@
|
|
|
37
42
|
"build": "tsc",
|
|
38
43
|
"test": "NODE_OPTIONS='--loader=ts-node/esm' mocha"
|
|
39
44
|
},
|
|
40
|
-
"keywords": [
|
|
41
|
-
"gif",
|
|
42
|
-
"gifsicle",
|
|
43
|
-
"image",
|
|
44
|
-
"img",
|
|
45
|
-
"compress",
|
|
46
|
-
"resize",
|
|
47
|
-
"minify",
|
|
48
|
-
"optimize"
|
|
49
|
-
],
|
|
50
|
-
"type": "module",
|
|
51
45
|
"dependencies": {
|
|
52
|
-
"@lesjoursfr/bin-wrapper": "^13.1.
|
|
46
|
+
"@lesjoursfr/bin-wrapper": "^13.1.1",
|
|
53
47
|
"execa": "^9.6.1",
|
|
54
48
|
"image-size": "^2.0.2",
|
|
55
49
|
"tar": "^7.5.13",
|
|
@@ -60,14 +54,14 @@
|
|
|
60
54
|
"@tsconfig/node22": "22.0.5",
|
|
61
55
|
"@types/mocha": "10.0.10",
|
|
62
56
|
"@types/node": "24.12.2",
|
|
63
|
-
"eslint": "10.2.
|
|
57
|
+
"eslint": "10.2.1",
|
|
64
58
|
"eslint-config-prettier": "10.1.8",
|
|
65
59
|
"globals": "17.5.0",
|
|
66
60
|
"mocha": "11.7.5",
|
|
67
61
|
"prettier": "3.8.3",
|
|
68
62
|
"ts-node": "10.9.2",
|
|
69
|
-
"typescript": "6.0.
|
|
70
|
-
"typescript-eslint": "8.
|
|
63
|
+
"typescript": "6.0.3",
|
|
64
|
+
"typescript-eslint": "8.59.0"
|
|
71
65
|
},
|
|
72
66
|
"packageManager": "yarn@4.14.1"
|
|
73
67
|
}
|
package/src/core/color.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Gifsicle } from "../gifsicle.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Convert to 8-bit greyscale.
|
|
5
|
-
*
|
|
6
|
-
* @param {Boolean} [greyscale=true]
|
|
7
|
-
* @returns {Gifsicle}
|
|
8
|
-
* @throws {TypeError} Invalid parameters
|
|
9
|
-
*/
|
|
10
|
-
export function greyscale(this: Gifsicle, greyscale: boolean | undefined): Gifsicle {
|
|
11
|
-
if (greyscale !== undefined) {
|
|
12
|
-
this.options.greyscale = greyscale;
|
|
13
|
-
} else {
|
|
14
|
-
this.options.greyscale = true;
|
|
15
|
-
}
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Alternative spelling of `greyscale`.
|
|
21
|
-
*
|
|
22
|
-
* @param {Boolean} [grayscale=true]
|
|
23
|
-
* @returns {Gifsicle}
|
|
24
|
-
* @throws {TypeError} Invalid parameters
|
|
25
|
-
*/
|
|
26
|
-
export function grayscale(this: Gifsicle, grayscale: boolean | undefined) {
|
|
27
|
-
return this.greyscale(grayscale);
|
|
28
|
-
}
|
package/src/core/input.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "fs";
|
|
2
|
-
import { isGif } from "../toolbox/is-gif.js";
|
|
3
|
-
|
|
4
|
-
export function readFile(input: string | Buffer): Buffer {
|
|
5
|
-
if (typeof input === "string") {
|
|
6
|
-
input = readFileSync(input);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
if (!isGif(input)) {
|
|
10
|
-
throw new TypeError("Expected 'input' to be a gif file");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return input;
|
|
14
|
-
}
|
package/src/core/optimize.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Gifsicle } from "../gifsicle.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Optimization levels.
|
|
5
|
-
*/
|
|
6
|
-
export enum OptimizationLevel {
|
|
7
|
-
O1 = "O1",
|
|
8
|
-
O2 = "O2",
|
|
9
|
-
O3 = "O3",
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Optimization options.
|
|
14
|
-
*/
|
|
15
|
-
export type OptimizeOptions = {
|
|
16
|
-
level?: OptimizationLevel;
|
|
17
|
-
lossiness?: number;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Optimize the gif.
|
|
22
|
-
*
|
|
23
|
-
* @param {Object} [options]
|
|
24
|
-
* @param {OptimizationLevel} [options.level=OptimizationLevel.O1] - the optimization level.
|
|
25
|
-
* @param {Number} [options.lossiness=20] - the lossiness value to shrink the number of colors [0,200].
|
|
26
|
-
* @returns {Gifsicle}
|
|
27
|
-
* @throws {TypeError} Invalid parameters
|
|
28
|
-
*/
|
|
29
|
-
export function optimize(this: Gifsicle, options: OptimizeOptions | undefined): Gifsicle {
|
|
30
|
-
// Default options
|
|
31
|
-
this.options.optimize = { level: OptimizationLevel.O1, lossiness: 20 };
|
|
32
|
-
|
|
33
|
-
// Process parameters
|
|
34
|
-
if (options !== undefined) {
|
|
35
|
-
// Level
|
|
36
|
-
if (options.level !== undefined) {
|
|
37
|
-
this.options.optimize.level = options.level;
|
|
38
|
-
}
|
|
39
|
-
// Lossiness
|
|
40
|
-
if (options.lossiness !== undefined) {
|
|
41
|
-
if (Number.isInteger(options.lossiness) && options.lossiness > 0 && options.lossiness < 200) {
|
|
42
|
-
this.options.optimize.lossiness = options.lossiness;
|
|
43
|
-
} else {
|
|
44
|
-
throw new TypeError("Expected 'lossiness' to be an integer in the range [0,200]");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return this;
|
|
49
|
-
}
|
package/src/core/output.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { execa } from "execa";
|
|
2
|
-
import { writeFileSync } from "fs";
|
|
3
|
-
import { Gifsicle, GifsicleInternalOptions } from "../gifsicle.js";
|
|
4
|
-
import { gifsicleWrapper } from "../wrapper.js";
|
|
5
|
-
import { computeCroppingPoint } from "./resize.js";
|
|
6
|
-
|
|
7
|
-
async function processFile(input: Buffer, options: GifsicleInternalOptions) {
|
|
8
|
-
const args = ["--no-warnings", "--no-app-extensions"];
|
|
9
|
-
|
|
10
|
-
if (options.greyscale === true) {
|
|
11
|
-
args.push("--use-colormap=gray");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (options.crop !== undefined) {
|
|
15
|
-
const { x, y } = computeCroppingPoint(input, options.crop);
|
|
16
|
-
args.push(`--crop=${x}, ${y}+${options.crop.width}x${options.crop.height}`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (options.resize !== undefined) {
|
|
20
|
-
if (options.resize.width !== undefined || options.resize.height !== undefined) {
|
|
21
|
-
if (options.resize.withoutEnlargement === true) {
|
|
22
|
-
args.push(`--resize-fit=${options.resize.width || "_"}x${options.resize.height || "_"}`);
|
|
23
|
-
} else {
|
|
24
|
-
args.push(`--resize-touch=${options.resize.width || "_"}x${options.resize.height || "_"}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (options.optimize !== undefined) {
|
|
30
|
-
if (options.optimize.level !== undefined) {
|
|
31
|
-
args.push(`-${options.optimize.level}`);
|
|
32
|
-
}
|
|
33
|
-
if (options.optimize.lossiness !== undefined) {
|
|
34
|
-
args.push(`--lossy=${options.optimize.lossiness}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const { stdout } = await execa(gifsicleWrapper.path, args, {
|
|
39
|
-
encoding: "buffer",
|
|
40
|
-
maxBuffer: Infinity,
|
|
41
|
-
input,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return stdout;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Save the result in a file.
|
|
49
|
-
*
|
|
50
|
-
* @param {String} [fileOut]
|
|
51
|
-
*/
|
|
52
|
-
export async function toFile(this: Gifsicle, fileOut: string): Promise<void> {
|
|
53
|
-
writeFileSync(fileOut, await processFile(this.input, this.options));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Get the result file as a Buffer.
|
|
58
|
-
*
|
|
59
|
-
* @returns {Uint8Array}
|
|
60
|
-
*/
|
|
61
|
-
export async function toBuffer(this: Gifsicle): Promise<Uint8Array> {
|
|
62
|
-
return processFile(this.input, this.options);
|
|
63
|
-
}
|
package/src/core/resize.ts
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { imageSize } from "image-size";
|
|
2
|
-
import { Gifsicle } from "../gifsicle.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Reduction kernels.
|
|
6
|
-
*/
|
|
7
|
-
export enum ReductionKernel {
|
|
8
|
-
sample = "sample",
|
|
9
|
-
mix = "mix",
|
|
10
|
-
catrom = "catrom",
|
|
11
|
-
mitchell = "mitchell",
|
|
12
|
-
lanczos2 = "lanczos2",
|
|
13
|
-
lanczos3 = "lanczos3",
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Position modes for cropping.
|
|
18
|
-
*/
|
|
19
|
-
export enum CroppingPosition {
|
|
20
|
-
center = "center",
|
|
21
|
-
top = "top",
|
|
22
|
-
right = "right",
|
|
23
|
-
bottom = "bottom",
|
|
24
|
-
left = "left",
|
|
25
|
-
topRight = "topRight",
|
|
26
|
-
bottomRight = "bottomRight",
|
|
27
|
-
bottomLeft = "bottomLeft",
|
|
28
|
-
topLeft = "topLeft",
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Resize options.
|
|
33
|
-
*/
|
|
34
|
-
export type ResizeOptions = {
|
|
35
|
-
kernel: ReductionKernel | undefined;
|
|
36
|
-
withoutEnlargement: boolean | undefined;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Cropping options.
|
|
41
|
-
*/
|
|
42
|
-
export type CroppingOptions = {
|
|
43
|
-
position: CroppingPosition | undefined;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Resize image to `width`, `height` or `width x height`.
|
|
48
|
-
*
|
|
49
|
-
* @param {Number} [width] - pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
|
|
50
|
-
* @param {Number} [height] - pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
|
|
51
|
-
* @param {Object} [options]
|
|
52
|
-
* @param {ReductionKernel} [options.kernel=ReductionKernel.lanczos3] - the kernel to use for image reduction.
|
|
53
|
-
* @param {Boolean} [options.withoutEnlargement=false] - do not enlarge if the width *or* height are already less than the specified dimensions, equivalent to GraphicsMagick's `>` geometry option. *
|
|
54
|
-
* @returns {Gifsicle}
|
|
55
|
-
* @throws {TypeError} Invalid parameters
|
|
56
|
-
*/
|
|
57
|
-
export function resize(
|
|
58
|
-
this: Gifsicle,
|
|
59
|
-
width: number | undefined,
|
|
60
|
-
height: number | undefined,
|
|
61
|
-
options: ResizeOptions | undefined
|
|
62
|
-
): Gifsicle {
|
|
63
|
-
// Default options
|
|
64
|
-
this.options.resize = { kernel: ReductionKernel.lanczos3, withoutEnlargement: false };
|
|
65
|
-
|
|
66
|
-
// Process parameters
|
|
67
|
-
if (width !== undefined) {
|
|
68
|
-
if (Number.isInteger(width) && width > 0) {
|
|
69
|
-
this.options.resize.width = width;
|
|
70
|
-
} else {
|
|
71
|
-
throw new TypeError("Expected 'width' to be a positive integer");
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (height !== undefined) {
|
|
75
|
-
if (Number.isInteger(height) && height > 0) {
|
|
76
|
-
this.options.resize.height = height;
|
|
77
|
-
} else {
|
|
78
|
-
throw new TypeError("Expected 'height' to be a positive integer");
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if (options !== undefined) {
|
|
82
|
-
// Kernel
|
|
83
|
-
if (options.kernel !== undefined) {
|
|
84
|
-
this.options.resize.kernel = options.kernel;
|
|
85
|
-
}
|
|
86
|
-
// Without enlargement
|
|
87
|
-
if (options.withoutEnlargement !== undefined) {
|
|
88
|
-
this.options.resize.withoutEnlargement = options.withoutEnlargement;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return this;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Crop the image to `width x height`.
|
|
96
|
-
*
|
|
97
|
-
* @param {number} [width] - pixels wide the resultant image should be.
|
|
98
|
-
* @param {number} [height] - pixels high the resultant image should be.
|
|
99
|
-
* @param {Object} [options]
|
|
100
|
-
* @param {CroppingPosition} [options.position=CroppingPosition.center] - position of the cropping rectangle.
|
|
101
|
-
* @returns {Gifsicle}
|
|
102
|
-
* @throws {TypeError} Invalid parameters
|
|
103
|
-
*/
|
|
104
|
-
export function crop(this: Gifsicle, width: number, height: number, options: CroppingOptions | undefined): Gifsicle {
|
|
105
|
-
// Default options
|
|
106
|
-
this.options.crop = { width: 0, height: 0, position: CroppingPosition.center };
|
|
107
|
-
|
|
108
|
-
// Process parameters
|
|
109
|
-
if (Number.isInteger(width) && width > 0) {
|
|
110
|
-
this.options.crop.width = width;
|
|
111
|
-
} else {
|
|
112
|
-
throw new TypeError("Expected 'width' to be a positive integer");
|
|
113
|
-
}
|
|
114
|
-
if (Number.isInteger(height) && height > 0) {
|
|
115
|
-
this.options.crop.height = height;
|
|
116
|
-
} else {
|
|
117
|
-
throw new TypeError("Expected 'height' to be a positive integer");
|
|
118
|
-
}
|
|
119
|
-
if (options !== undefined) {
|
|
120
|
-
// Position
|
|
121
|
-
if (options.position !== undefined) {
|
|
122
|
-
this.options.crop.position = options.position;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return this;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export function computeCroppingPoint(
|
|
129
|
-
input: Buffer,
|
|
130
|
-
crop: { width: number; height: number; position: CroppingPosition }
|
|
131
|
-
): { x: number; y: number } {
|
|
132
|
-
const size = imageSize(input);
|
|
133
|
-
if (size.width === undefined || size.height === undefined) {
|
|
134
|
-
throw new Error("Can't compute the image size");
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
let px = 0;
|
|
138
|
-
let py = 0;
|
|
139
|
-
switch (crop.position) {
|
|
140
|
-
case CroppingPosition.center:
|
|
141
|
-
px = Math.floor((size.width - crop.width) / 2);
|
|
142
|
-
py = Math.floor((size.height - crop.height) / 2);
|
|
143
|
-
break;
|
|
144
|
-
case CroppingPosition.top:
|
|
145
|
-
px = Math.floor((size.width - crop.width) / 2);
|
|
146
|
-
py = 0;
|
|
147
|
-
break;
|
|
148
|
-
case CroppingPosition.right:
|
|
149
|
-
px = size.width - crop.width;
|
|
150
|
-
py = Math.floor((size.height - crop.height) / 2);
|
|
151
|
-
break;
|
|
152
|
-
case CroppingPosition.bottom:
|
|
153
|
-
px = Math.floor((size.width - crop.width) / 2);
|
|
154
|
-
py = size.height - crop.height;
|
|
155
|
-
break;
|
|
156
|
-
case CroppingPosition.left:
|
|
157
|
-
px = 0;
|
|
158
|
-
py = Math.floor((size.height - crop.height) / 2);
|
|
159
|
-
break;
|
|
160
|
-
case CroppingPosition.topRight:
|
|
161
|
-
px = size.width - crop.width;
|
|
162
|
-
py = 0;
|
|
163
|
-
break;
|
|
164
|
-
case CroppingPosition.bottomRight:
|
|
165
|
-
px = size.width - crop.width;
|
|
166
|
-
py = size.height - crop.height;
|
|
167
|
-
break;
|
|
168
|
-
case CroppingPosition.bottomLeft:
|
|
169
|
-
px = 0;
|
|
170
|
-
py = size.height - crop.height;
|
|
171
|
-
break;
|
|
172
|
-
case CroppingPosition.topLeft:
|
|
173
|
-
px = 0;
|
|
174
|
-
py = 0;
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
return { x: px, y: py };
|
|
178
|
-
}
|
package/src/gifsicle.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { grayscale, greyscale } from "./core/color.js";
|
|
2
|
-
import { readFile } from "./core/input.js";
|
|
3
|
-
import { OptimizeOptions, optimize } from "./core/optimize.js";
|
|
4
|
-
import { toBuffer, toFile } from "./core/output.js";
|
|
5
|
-
import { CroppingPosition, ReductionKernel, crop, resize } from "./core/resize.js";
|
|
6
|
-
|
|
7
|
-
export interface GifsicleInternalOptions {
|
|
8
|
-
greyscale?: boolean;
|
|
9
|
-
resize?: { width?: number; height?: number; kernel: ReductionKernel; withoutEnlargement: boolean };
|
|
10
|
-
crop?: { width: number; height: number; position: CroppingPosition };
|
|
11
|
-
optimize?: OptimizeOptions;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Export Gifsicle class.
|
|
16
|
-
*/
|
|
17
|
-
export class Gifsicle {
|
|
18
|
-
options: GifsicleInternalOptions;
|
|
19
|
-
input: Buffer;
|
|
20
|
-
|
|
21
|
-
constructor(input: string | Buffer) {
|
|
22
|
-
this.input = readFile(input);
|
|
23
|
-
this.options = {};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public greyscale = greyscale;
|
|
27
|
-
public grayscale = grayscale;
|
|
28
|
-
public resize = resize;
|
|
29
|
-
public crop = crop;
|
|
30
|
-
public optimize = optimize;
|
|
31
|
-
public toFile = toFile;
|
|
32
|
-
public toBuffer = toBuffer;
|
|
33
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { OptimizationLevel } from "./core/optimize.js";
|
|
2
|
-
import { CroppingPosition, ReductionKernel } from "./core/resize.js";
|
|
3
|
-
import { Gifsicle } from "./gifsicle.js";
|
|
4
|
-
|
|
5
|
-
function gifsicle(input: string | Buffer): Gifsicle {
|
|
6
|
-
return new Gifsicle(input);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
gifsicle.kernel = ReductionKernel;
|
|
10
|
-
gifsicle.position = CroppingPosition;
|
|
11
|
-
gifsicle.level = OptimizationLevel;
|
|
12
|
-
|
|
13
|
-
export default gifsicle;
|
package/src/install.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { execa } from "execa";
|
|
2
|
-
import { mkdir, rm } from "fs/promises";
|
|
3
|
-
import process from "process";
|
|
4
|
-
import { x as extract } from "tar";
|
|
5
|
-
import { temporaryFile } from "tempy";
|
|
6
|
-
import { gifsicleSourcePath, gifsicleWrapper } from "./wrapper.js";
|
|
7
|
-
|
|
8
|
-
async function buildFromSource(file: string, cmd: Array<string>): Promise<void> {
|
|
9
|
-
const temporary = temporaryFile();
|
|
10
|
-
console.log(`use the temporary folder : ${temporary}`);
|
|
11
|
-
await mkdir(temporary, { recursive: true });
|
|
12
|
-
|
|
13
|
-
await extract({ file: file, cwd: temporary, strip: 1 });
|
|
14
|
-
|
|
15
|
-
for (const x of cmd) {
|
|
16
|
-
await execa(x, { cwd: temporary, shell: true, encoding: "utf8" });
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
await rm(temporary, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
(async () => {
|
|
23
|
-
try {
|
|
24
|
-
await gifsicleWrapper.run(["--version"]);
|
|
25
|
-
console.log("gifsicle pre-build test passed successfully");
|
|
26
|
-
} catch (error) {
|
|
27
|
-
if (error instanceof Error) {
|
|
28
|
-
console.warn(error.message);
|
|
29
|
-
}
|
|
30
|
-
console.warn("gifsicle pre-build test failed");
|
|
31
|
-
console.info("compiling from source");
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
const source = gifsicleSourcePath;
|
|
35
|
-
const destination = gifsicleWrapper.dest;
|
|
36
|
-
await buildFromSource(source, [
|
|
37
|
-
"autoreconf -ivf",
|
|
38
|
-
`./configure --disable-gifview --disable-gifdiff --prefix="${destination}" --bindir="${destination}"`,
|
|
39
|
-
"make install",
|
|
40
|
-
]);
|
|
41
|
-
|
|
42
|
-
console.log("gifsicle built successfully");
|
|
43
|
-
} catch (error) {
|
|
44
|
-
if (error instanceof Error) {
|
|
45
|
-
console.error(error.stack);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
process.exit(1);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
})();
|
package/src/toolbox/is-gif.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// Based on isGif function from https://github.com/sindresorhus/is-gif
|
|
2
|
-
// https://github.com/sindresorhus/is-gif/blob/main/index.js
|
|
3
|
-
export function isGif(buffer: Buffer) {
|
|
4
|
-
if (!buffer || buffer.length < 3) {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return buffer[0] === 0x47 && buffer[1] === 0x49 && buffer[2] === 0x46;
|
|
9
|
-
}
|
package/src/wrapper.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import BinWrapper from "@lesjoursfr/bin-wrapper";
|
|
2
|
-
import { platform } from "process";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
|
-
|
|
5
|
-
const version = "1.96";
|
|
6
|
-
const base = `https://raw.githubusercontent.com/lesjoursfr/gifsicle-wrapper/main/vendor/v${version}`;
|
|
7
|
-
|
|
8
|
-
export const gifsicleWrapper = new BinWrapper({ strip: 0 });
|
|
9
|
-
gifsicleWrapper.addSrc(`${base}/linux/x64/gifsicle.tar.gz`, "linux", "x64");
|
|
10
|
-
gifsicleWrapper.setDest(fileURLToPath(new URL("../vendor", import.meta.url)));
|
|
11
|
-
gifsicleWrapper.setUse(platform === "win32" ? "gifsicle.exe" : "gifsicle");
|
|
12
|
-
gifsicleWrapper.setVersion(`>=${version}`);
|
|
13
|
-
|
|
14
|
-
export const gifsicleSourcePath = fileURLToPath(
|
|
15
|
-
new URL(`../vendor/v${version}/source/gifsicle.tar.gz`, import.meta.url)
|
|
16
|
-
);
|