-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
72 lines (62 loc) · 2.48 KB
/
Copy pathserver.js
File metadata and controls
72 lines (62 loc) · 2.48 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env node
const { Command } = require('commander');
const { saveConfig, loadConfig } = require('./lib/config');
const { setupRuntime, getRuntimePath, getExecutable } = require('./lib/downloader.js');
const { runFile } = require("./lib/runtimeHandler.js");
const program = new Command();
program
.name('adjust')
.description('A lightweight CLI to manage and execute isolated language runtimes.')
.version('1.0.0');
program
.command('install <language>')
.description('Download and configure an isolated runtime (e.g., node, python)')
.action(async (language) => {
if(!['python', 'node'].includes(language)){
console.error(`\n ✖ Unsupported language: ${language}`);
console.log(` Supported runtimes: node, python\n`);
process.exit(1);
}
console.log(`\n ➜ Initializing isolated setup for ${language}...`);
try {
await setupRuntime(language);
getExecutable(language);
const config = await loadConfig();
config.activeLanguage = language;
config.environment[language] = {
path: getRuntimePath(language),
installed_at: new Date().toISOString()
}
await saveConfig(config);
console.log(`\n ✓ ${language} runtime installed and configured successfully.`);
console.log(` ➜ Active runtime set to: ${language}`);
console.log(`\n Run a file using: adjust run <filename>\n`);
}
catch (err) {
console.error(`\n ✖ Failed to setup ${language}:`, err.message, `\n`);
process.exit(1);
}
});
program
.command('list')
.description('List available and active runtimes')
.action(async () => {
const config = await loadConfig();
console.log(`\n Active Runtime : ${config.activeLanguage || 'None'}`);
console.log(` Installed Environments:`);
if (Object.keys(config.environment).length === 0) {
console.log(` (none)`);
} else {
for (const [lang, data] of Object.entries(config.environment)) {
console.log(` • ${lang} (installed at: ${data.installed_at})`);
}
}
console.log('');
});
program
.command('run <file>')
.description('Execute a file using its isolated runtime environment')
.action(async (file) => {
await runFile(file);
});
program.parse();