charify 2.0.2 → 2.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/LICENSE +1 -1
- package/package.json +1 -1
- package/src/loadSharp.js +24 -1
package/LICENSE
CHANGED
package/package.json
CHANGED
package/src/loadSharp.js
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import { execSync } from "child_process";
|
|
2
|
+
import readline from "readline";
|
|
2
3
|
|
|
3
4
|
let sharpInstance;
|
|
4
5
|
|
|
6
|
+
function askYesNo(question) {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
const rl = readline.createInterface({
|
|
9
|
+
input: process.stdin,
|
|
10
|
+
output: process.stdout,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
rl.question(question, (answer) => {
|
|
14
|
+
rl.close();
|
|
15
|
+
resolve(answer.trim().toLowerCase() === "y");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
5
20
|
export async function loadSharp() {
|
|
6
21
|
if (sharpInstance) return sharpInstance;
|
|
7
22
|
|
|
@@ -10,9 +25,17 @@ export async function loadSharp() {
|
|
|
10
25
|
return sharpInstance;
|
|
11
26
|
} catch {
|
|
12
27
|
console.warn(
|
|
13
|
-
"[Warning]: 'sharp' package not found.
|
|
28
|
+
"[Warning]: 'sharp' package not found. charify might not work without it."
|
|
14
29
|
);
|
|
15
30
|
|
|
31
|
+
const install = await askYesNo(
|
|
32
|
+
"Do you want to install 'sharp' now? (y/n): "
|
|
33
|
+
);
|
|
34
|
+
if (!install) {
|
|
35
|
+
console.log("Skipping 'sharp' installation. Please install it manually.");
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
16
39
|
try {
|
|
17
40
|
execSync("npm install sharp", { stdio: "inherit" });
|
|
18
41
|
sharpInstance = (await import("sharp")).default;
|