-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.js
executable file
·44 lines (36 loc) · 1.23 KB
/
run.js
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
#!/usr/bin/env node
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import path from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Track if it's the first run
let firstRun = true;
function start() {
// Set the terminal title
console.log('\u001b]2;Universal Constructor\u0007');
// Remove the -r or --reset flag if it's not the first run
let args = process.argv.slice(2);
if (!firstRun && (args.includes('-r') || args.includes('--reset'))) {
args = args.filter(arg => ['--reset', '-r'].includes(arg) === false);
}
// use --no-deprecation until openai fixes their fetch/punycode shit
const childProcess = spawn('node', [
'--no-deprecation',
`${__dirname}/src/repl.js`,
...args,
], { stdio: 'inherit' });
childProcess.on('exit', (code) => {
firstRun = false;
if (code === 0) {
console.log('Restarting. (Press ctrl-c twice to exit)');
start();
} else {
console.log(`Exited with code ${code}. No restart`);
}
});
}
process.on('SIGINT', () => {
// let repl.js handle this.
});
start(); // Start the process for the first time