ttsd-colabcli 1.0.2 → 1.0.3
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/cli.js +20 -17
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -2,12 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
5
6
|
const { spawn, execSync } = require('child_process');
|
|
6
7
|
|
|
8
|
+
const HOME_DIR = path.join(os.homedir(), '.colabcli');
|
|
9
|
+
if (!fs.existsSync(HOME_DIR)) {
|
|
10
|
+
fs.mkdirSync(HOME_DIR, { recursive: true });
|
|
11
|
+
}
|
|
12
|
+
|
|
7
13
|
const CMD = process.argv[2] || 'start';
|
|
8
|
-
const ENV_PATH = path.join(
|
|
14
|
+
const ENV_PATH = path.join(HOME_DIR, '.env');
|
|
9
15
|
const CORE_DIR = path.join(__dirname, 'core');
|
|
10
|
-
const PID_FILE = path.join(
|
|
16
|
+
const PID_FILE = path.join(HOME_DIR, '.daemon.pid');
|
|
17
|
+
const VENV_DIR = path.join(HOME_DIR, 'venv');
|
|
11
18
|
|
|
12
19
|
async function promptConfig() {
|
|
13
20
|
const inquirer = require('inquirer');
|
|
@@ -35,21 +42,20 @@ async function promptConfig() {
|
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
function setupPythonEnv() {
|
|
38
|
-
|
|
39
|
-
if (!fs.existsSync(venvDir)) {
|
|
45
|
+
if (!fs.existsSync(VENV_DIR)) {
|
|
40
46
|
console.log('Creating Python virtual environment...');
|
|
41
47
|
try {
|
|
42
|
-
execSync(`python3 -m venv "${
|
|
48
|
+
execSync(`python3 -m venv "${VENV_DIR}"`, { stdio: 'inherit' });
|
|
43
49
|
} catch (e) {
|
|
44
50
|
console.log('python3 not found, trying python...');
|
|
45
|
-
execSync(`python -m venv "${
|
|
51
|
+
execSync(`python -m venv "${VENV_DIR}"`, { stdio: 'inherit' });
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
console.log('Installing dependencies...');
|
|
50
56
|
const pip = process.platform === 'win32'
|
|
51
|
-
? path.join(
|
|
52
|
-
: path.join(
|
|
57
|
+
? path.join(VENV_DIR, 'Scripts', 'pip')
|
|
58
|
+
: path.join(VENV_DIR, 'bin', 'pip');
|
|
53
59
|
execSync(`"${pip}" install -r "${path.join(CORE_DIR, 'requirements.txt')}" -q`, { stdio: 'inherit' });
|
|
54
60
|
}
|
|
55
61
|
|
|
@@ -75,17 +81,14 @@ async function start() {
|
|
|
75
81
|
console.log('Starting Satellite Daemon in background...');
|
|
76
82
|
|
|
77
83
|
const pythonBin = process.platform === 'win32'
|
|
78
|
-
? path.join(
|
|
79
|
-
: path.join(
|
|
80
|
-
|
|
81
|
-
// Copy .env to core dir so daemon.py can load it
|
|
82
|
-
fs.copyFileSync(ENV_PATH, path.join(CORE_DIR, '.env'));
|
|
84
|
+
? path.join(VENV_DIR, 'Scripts', 'python')
|
|
85
|
+
: path.join(VENV_DIR, 'bin', 'python');
|
|
83
86
|
|
|
84
|
-
const out = fs.openSync(path.join(
|
|
85
|
-
const err = fs.openSync(path.join(
|
|
87
|
+
const out = fs.openSync(path.join(HOME_DIR, 'daemon.log'), 'a');
|
|
88
|
+
const err = fs.openSync(path.join(HOME_DIR, 'daemon.error.log'), 'a');
|
|
86
89
|
|
|
87
|
-
const child = spawn(pythonBin, ['daemon.py'], {
|
|
88
|
-
cwd:
|
|
90
|
+
const child = spawn(pythonBin, [path.join(CORE_DIR, 'daemon.py')], {
|
|
91
|
+
cwd: HOME_DIR,
|
|
89
92
|
detached: true,
|
|
90
93
|
stdio: ['ignore', out, err]
|
|
91
94
|
});
|