spessoplayer 0.5.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.mjs ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+ /*
3
+ Copyright (C) 2025 unixatch
4
+
5
+ it under the terms of the GNU General Public License as published by
6
+ This program is free software: you can redistribute it and/or modify
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with spessoplayer. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ const { spawnSync } = await import("child_process");
20
+ const { runProgramSync, tryToInstall } = await import("./utils.mjs");
21
+
22
+ let readline,
23
+ stdin,
24
+ stdout,
25
+ stderr;
26
+ /**
27
+ * Checks if a program exists, if it doesn't exist,
28
+ * it asks the user for confirmation to install via package managers
29
+ * @param {String} program - the program to check
30
+ * @param {String} [noInstallMsg=""] - the message to show when the user refuses to install it
31
+ */
32
+ async function runCheck(program, noInstallMsg = "") {
33
+ try {
34
+ runProgramSync({ spawnSync, program })
35
+ } catch (e) {
36
+ if (e.message !== "Program doesn't exist") {
37
+ console.error(e);
38
+ console.error(`${red}There was an error while trying to check ${program}, exiting...${normal}`);
39
+ process.exit(1);
40
+ }
41
+ console.warn("\x1b[33;4m"+program+"\x1b[0;33m is not installed or it's not visible globally\x1b[0m");
42
+ if (!readline) {
43
+ readline = await import("readline/promises");
44
+ ({ stdin, stdout, stderr } = await import ("process"));
45
+ }
46
+
47
+ let answer;
48
+ try {
49
+ const rl = readline.createInterface({ input: stdin, output: stdout });
50
+ answer = await rl.question("Do you want to install it [Y|n]? ");
51
+ rl.close()
52
+ } catch (e2) {
53
+ if (e2.name === "AbortError") {
54
+ console.error(`\n${gray}Installation of dependencies interrupted with Ctrl+c${normal}`);
55
+ process.exit(2)
56
+ }
57
+ }
58
+ // ↓ In case it's neither y or n
59
+ if (/(?:y|yes)/i.test(answer) || !/(?:n|no)/.test(answer)) {
60
+ tryToInstall(program, spawnSync, { stdout, stderr })
61
+ } else if (/(?:n|no)/.test(answer)) {
62
+ console.warn("\x1b[33m"+noInstallMsg+"\x1b[0m")
63
+ }
64
+ }
65
+ }
66
+ // ffmpeg check
67
+ await runCheck(
68
+ "ffmpeg",
69
+ "Continuing installation, but you'll get errors when trying to convert to other formats"
70
+ )
71
+ // SoX check
72
+ await runCheck(
73
+ "sox",
74
+ "Continuing installation, but you'll get errors when trying to add effects"
75
+ )
76
+ // mpv check
77
+ await runCheck(
78
+ "mpv",
79
+ "Continuing installation, but you'll get errors when trying to play songs directly"
80
+ )
81
+ export { runCheck }