@cliptude/cli 0.1.1 → 0.1.2

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.
@@ -3,10 +3,13 @@
3
3
 
4
4
  const { spawnSync } = require("child_process");
5
5
  const fs = require("fs");
6
+ const os = require("os");
6
7
  const path = require("path");
7
8
 
8
9
  const pkgRoot = path.resolve(__dirname, "..", "..");
9
10
  const args = process.argv.slice(2);
11
+ const venvDir =
12
+ process.env.CLIPTUDE_VENV || path.join(os.homedir(), ".cliptude", "venv");
10
13
 
11
14
  function pythonCandidates() {
12
15
  if (process.platform === "win32") {
@@ -29,37 +32,102 @@ function findPython() {
29
32
  return null;
30
33
  }
31
34
 
32
- function ensurePackage(py) {
35
+ function venvPython() {
36
+ if (process.platform === "win32") {
37
+ return path.join(venvDir, "Scripts", "python.exe");
38
+ }
39
+ return path.join(venvDir, "bin", "python");
40
+ }
41
+
42
+ function packageVersion() {
43
+ try {
44
+ return JSON.parse(fs.readFileSync(path.join(pkgRoot, "package.json"), "utf8"))
45
+ .version;
46
+ } catch {
47
+ return "";
48
+ }
49
+ }
50
+
51
+ function markerPath() {
52
+ return path.join(venvDir, ".cliptude-cli-version");
53
+ }
54
+
55
+ function importOk(py) {
33
56
  const check = spawnSync(py, ["-c", "import cliptude_mcp.cli"], {
34
57
  encoding: "utf8",
35
58
  });
36
- if (check.status === 0) {
37
- return;
59
+ return check.status === 0;
60
+ }
61
+
62
+ function installedVersionMatches(py) {
63
+ if (!importOk(py)) {
64
+ return false;
65
+ }
66
+ const want = packageVersion();
67
+ if (!want) {
68
+ return true;
38
69
  }
70
+ try {
71
+ return fs.readFileSync(markerPath(), "utf8").trim() === want;
72
+ } catch {
73
+ return false;
74
+ }
75
+ }
76
+
77
+ function run(py, argv) {
78
+ return spawnSync(py, argv, { stdio: "inherit" });
79
+ }
80
+
81
+ function ensureVenv(systemPy) {
82
+ const py = venvPython();
83
+ if (fs.existsSync(py) && installedVersionMatches(py)) {
84
+ return py;
85
+ }
86
+
87
+ fs.mkdirSync(path.dirname(venvDir), { recursive: true });
88
+ if (!fs.existsSync(py)) {
89
+ const created = run(systemPy, ["-m", "venv", venvDir]);
90
+ if (created.status !== 0 || !fs.existsSync(py)) {
91
+ console.error(
92
+ "Could not create a Python virtualenv at " +
93
+ venvDir +
94
+ ". Install Python 3.10+.",
95
+ );
96
+ process.exit(created.status ?? 1);
97
+ }
98
+ }
99
+
39
100
  const pyproject = path.join(pkgRoot, "pyproject.toml");
40
101
  if (!fs.existsSync(pyproject)) {
41
102
  console.error("Cliptude CLI package is missing pyproject.toml.");
42
103
  process.exit(1);
43
104
  }
44
- const install = spawnSync(
45
- py,
46
- ["-m", "pip", "install", "--quiet", pkgRoot],
47
- { stdio: "inherit" },
48
- );
105
+
106
+ let install = run(py, ["-m", "pip", "install", "--upgrade", "--quiet", pkgRoot]);
107
+ if (install.status !== 0) {
108
+ run(py, ["-m", "ensurepip", "--upgrade"]);
109
+ install = run(py, ["-m", "pip", "install", "--upgrade", "--quiet", pkgRoot]);
110
+ }
49
111
  if (install.status !== 0) {
50
- console.error("Could not install the Cliptude Python CLI. Install Python 3.10+ and pip.");
112
+ console.error("Could not install the Cliptude Python CLI into " + venvDir);
51
113
  process.exit(install.status ?? 1);
52
114
  }
115
+
116
+ const version = packageVersion();
117
+ if (version) {
118
+ fs.writeFileSync(markerPath(), version + "\n");
119
+ }
120
+ return py;
53
121
  }
54
122
 
55
- const py = findPython();
56
- if (!py) {
57
- console.error("Python 3.10+ is required. Install it, then re-run: npm i -g @cliptude/cli");
123
+ const systemPy = findPython();
124
+ if (!systemPy) {
125
+ console.error(
126
+ "Python 3.10+ is required. Install it, then re-run: npm i -g @cliptude/cli",
127
+ );
58
128
  process.exit(1);
59
129
  }
60
130
 
61
- ensurePackage(py);
62
- const result = spawnSync(py, ["-m", "cliptude_mcp.cli", ...args], {
63
- stdio: "inherit",
64
- });
131
+ const py = ensureVenv(systemPy);
132
+ const result = run(py, ["-m", "cliptude_mcp.cli", ...args]);
65
133
  process.exit(result.status ?? 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cliptude/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Cliptude CLI — generate videos from saved templates.",
5
5
  "homepage": "https://github.com/cliptude/cliptude#readme",
6
6
  "bin": {
package/pyproject.toml CHANGED
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "cliptude-mcp"
7
- version = "0.1.1"
7
+ version = "0.1.2"
8
8
  description = "Cliptude jobs CLI and MCP server (thin client of /api/v1)."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"