forked from mocasus/Auto-FreeCF
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostinstall.js
More file actions
56 lines (45 loc) · 1.65 KB
/
Copy pathpostinstall.js
File metadata and controls
56 lines (45 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// postinstall.js - runs after npm install
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const ROOT = __dirname;
const VENV = path.join(ROOT, 'venv');
const INSTALLED = path.join(VENV, '.installed');
console.log('🚀 Auto-FreeCF - Setting up...');
// Find Python
function findPython() {
for (const cmd of ['python3', 'python']) {
try {
const ver = execSync(`${cmd} --version 2>&1`, { encoding: 'utf8' }).trim();
if (ver.startsWith('Python 3')) return cmd;
} catch {}
}
return null;
}
const python = findPython();
if (!python) {
console.error('❌ Python 3 not found! Install: https://www.python.org/downloads/');
process.exit(1);
}
console.log(`✓ Python: ${python}`);
// Create venv
if (!fs.existsSync(VENV)) {
console.log('📦 Creating virtual environment...');
execSync(`${python} -m venv venv`, { cwd: ROOT, stdio: 'inherit' });
console.log('✓ Virtual environment created');
}
// Install deps
if (!fs.existsSync(INSTALLED)) {
console.log('📦 Installing dependencies (this may take ~5 min)...');
const pip = process.platform === 'win32'
? path.join(VENV, 'Scripts', 'pip')
: path.join(VENV, 'bin', 'pip');
execSync(`${pip} install -q -r requirements.txt`, { cwd: ROOT, stdio: 'inherit' });
const patchright = process.platform === 'win32'
? path.join(VENV, 'Scripts', 'patchright')
: path.join(VENV, 'bin', 'patchright');
execSync(`${patchright} install chromium`, { cwd: ROOT, stdio: 'inherit' });
fs.writeFileSync(INSTALLED, '');
console.log('✓ Dependencies installed');
}
console.log('✅ Setup complete! Run `moycf` to start.');