git-cli-yt 1.1.7 → 1.1.8

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.
Files changed (2) hide show
  1. package/bin/cli.js +53 -2
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -1,9 +1,56 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ const { execSync, spawn } = require("child_process");
4
+ const path = require("path");
5
+ const fs = require("fs");
6
+ const os = require("os");
7
+
8
+ // Carrega o arquivo .env da pasta atual se existir
9
+ require("dotenv").config({ path: path.join(process.cwd(), ".env") });
10
+
11
+ const packageDir = path.join(__dirname, "..");
12
+ const isWindows = process.platform === "win32";
13
+
14
+ // Ambiente virtual isolado no Temp do usuário
15
+ const venvDir = path.join(os.tmpdir(), "cli-yt-venv");
16
+
17
+ const pythonExecutable = isWindows
18
+ ? path.join(venvDir, "Scripts", "python.exe")
19
+ : path.join(venvDir, "bin", "python");
20
+
21
+ const pipExecutable = isWindows
22
+ ? path.join(venvDir, "Scripts", "pip.exe")
23
+ : path.join(venvDir, "bin", "pip");
24
+
25
+ function checkPython() {
26
+ try {
27
+ const cmd = isWindows ? "where python" : "which python3 || which python";
28
+ execSync(cmd, { stdio: "ignore" });
29
+ } catch (e) {
30
+ console.error("❌ Erro: Python 3 não foi encontrado no sistema.");
31
+ process.exit(1);
32
+ }
33
+ }
34
+
35
+ function setupVenv() {
36
+ const pythonCmd = isWindows ? "python" : "python3";
37
+
38
+ if (!fs.existsSync(pythonExecutable)) {
39
+ console.log("⚙️ Criando ambiente virtual Python isolado...");
40
+ execSync(`${pythonCmd} -m venv "${venvDir}"`, { stdio: "inherit" });
41
+ }
42
+
43
+ const reqFile = path.join(packageDir, "requirements.txt");
44
+ if (fs.existsSync(reqFile)) {
45
+ console.log("📦 Verificando/Instalando dependências...");
46
+ execSync(`"${pipExecutable}" install -q -r "${reqFile}"`, { stdio: "inherit" });
47
+ }
48
+ }
49
+
3
50
  function runPlayer() {
4
51
  const mainPy = path.join(packageDir, "main.py");
5
52
 
6
- // Apenas repassa o process.env original sem injetar strings vazias
53
+ // Passa o process.env original sem criar chaves vazias
7
54
  const child = spawn(pythonExecutable, [mainPy], {
8
55
  stdio: "inherit",
9
56
  cwd: process.cwd(),
@@ -13,4 +60,8 @@ function runPlayer() {
13
60
  child.on("exit", (code) => {
14
61
  process.exit(code || 0);
15
62
  });
16
- }
63
+ }
64
+
65
+ checkPython();
66
+ setupVenv();
67
+ runPlayer();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-cli-yt",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "YouTube TUI Player executável via NPX",
5
5
  "main": "bin/cli.js",
6
6
  "bin": {