brain-cleaner 1.2.0 → 1.2.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.
@@ -1,17 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { spawn } = require('child_process');
3
+ const { spawn, execSync } = require('child_process');
4
4
  const path = require('path');
5
- const fs = require('fs');
6
5
 
7
6
  /**
8
- * JS Wrapper for Brain Cleaner (Python)
7
+ * Enhanced JS Wrapper for Brain Cleaner (Python)
8
+ * Handles auto-installation of dependencies.
9
9
  */
10
10
 
11
11
  function findPython() {
12
- const commands = ['python3', 'python'];
13
- const { execSync } = require('child_process');
14
-
12
+ const commands = ['python3', 'python', 'py'];
15
13
  for (const cmd of commands) {
16
14
  try {
17
15
  execSync(`${cmd} --version`, { stdio: 'ignore' });
@@ -23,21 +21,41 @@ function findPython() {
23
21
  return null;
24
22
  }
25
23
 
24
+ function checkAndInstallDeps(python) {
25
+ console.log('\x1b[36mFinalizing Brain Cleaner installation...\x1b[0m');
26
+ const deps = ['blessed', 'Pillow'];
27
+
28
+ for (const dep of deps) {
29
+ try {
30
+ // Check if dependency exists
31
+ execSync(`${python} -c "import ${dep.toLowerCase()}"`, { stdio: 'ignore' });
32
+ } catch (e) {
33
+ console.log(`\x1b[33mDependency '${dep}' not found. Installing...\x1b[0m`);
34
+ try {
35
+ execSync(`${python} -m pip install ${dep}`, { stdio: 'inherit' });
36
+ } catch (pipErr) {
37
+ console.error(`\x1b[31mFailed to install '${dep}'. Please run 'pip install ${dep}' manually.\x1b[0m`);
38
+ }
39
+ }
40
+ }
41
+ }
42
+
26
43
  const python = findPython();
27
44
 
28
45
  if (!python) {
29
46
  console.error('\x1b[31mError: Python not found!\x1b[0m');
30
- console.error('Brain Cleaner requires Python 3.9 or higher to run.');
31
- console.error('Please install Python and try again: https://www.python.org/downloads/');
47
+ console.error('Brain Cleaner requires Python 3.9 or higher.');
48
+ console.error('Please install Python: https://www.python.org/downloads/');
32
49
  process.exit(1);
33
50
  }
34
51
 
52
+ // Ensure dependencies are present
53
+ checkAndInstallDeps(python);
54
+
35
55
  // Path to the python entry point
36
56
  const scriptPath = path.join(__dirname, '..', 'console', 'brain_cleaner_cli.py');
37
-
38
- // Since we are running from NPM, we might need to ensure dependencies are installed
39
- // For now, we just pass the arguments to the python script
40
57
  const args = process.argv.slice(2);
58
+
41
59
  const pythonProcess = spawn(python, [scriptPath, ...args], {
42
60
  stdio: 'inherit',
43
61
  env: { ...process.env, PYTHONPATH: path.join(__dirname, '..') }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brain-cleaner",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "System residue cleaner for AI tools and NPM modules",
5
5
  "main": "bin/brain-cleaner.js",
6
6
  "bin": {