git-cli-yt 2.0.0 → 2.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/bin/cli.js +23 -2
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -8,10 +8,11 @@ const { execFileSync, spawn } = require("child_process");
|
|
|
8
8
|
|
|
9
9
|
const packageDir = path.join(__dirname, "..");
|
|
10
10
|
const isWindows = process.platform === "win32";
|
|
11
|
-
const venvDir = path.join(os.tmpdir(), "cli-yt-
|
|
11
|
+
const venvDir = path.join(os.tmpdir(), "cli-yt-venv");
|
|
12
12
|
const pythonExecutable = isWindows
|
|
13
13
|
? path.join(venvDir, "Scripts", "python.exe")
|
|
14
14
|
: path.join(venvDir, "bin", "python");
|
|
15
|
+
const pyvenvConfig = path.join(venvDir, "pyvenv.cfg");
|
|
15
16
|
const mainPy = path.join(packageDir, "main.py");
|
|
16
17
|
const requirementsFile = path.join(packageDir, "requirements.txt");
|
|
17
18
|
|
|
@@ -41,8 +42,28 @@ function findPython() {
|
|
|
41
42
|
throw new Error("Python 3.9 ou superior não foi encontrado.");
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
function isValidVenv() {
|
|
46
|
+
if (!fs.existsSync(pythonExecutable) || !fs.existsSync(pyvenvConfig)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
execFileSync(
|
|
51
|
+
pythonExecutable,
|
|
52
|
+
["-c", "import sys; raise SystemExit(0 if sys.version_info >= (3, 9) else 1)"],
|
|
53
|
+
{ stdio: "ignore", windowsHide: true },
|
|
54
|
+
);
|
|
55
|
+
return true;
|
|
56
|
+
} catch (_) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
44
61
|
function setupVenv(python) {
|
|
45
|
-
if (!
|
|
62
|
+
if (!isValidVenv()) {
|
|
63
|
+
if (fs.existsSync(venvDir)) {
|
|
64
|
+
console.log("♻️ Recriando ambiente virtual inválido...");
|
|
65
|
+
fs.rmSync(venvDir, { recursive: true, force: true });
|
|
66
|
+
}
|
|
46
67
|
console.log("⚙️ Criando ambiente virtual Python isolado...");
|
|
47
68
|
execFileSync(
|
|
48
69
|
python.command,
|