-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (47 loc) · 1.84 KB
/
index.js
File metadata and controls
55 lines (47 loc) · 1.84 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
const {Command} = require('commander');
const program = new Command();
const {version} = require('./package.json');
const startWorker = require('webgme-executor-worker');
const fs = require('fs');
const os = require('os');
const path = require('path');
const {promisify} = require('util');
const unlink = promisify(fs.unlink);
const writeFile = promisify(fs.writeFile);
const readFile = promisify(fs.readFile);
const childProcess = require('child_process');
const exec = promisify(childProcess.exec);
program
.version(version)
.option('-t, --accessToken <token>', 'Access token for an authorized user')
.option('-c, --cache <path>', 'Path to worker cache directory', 'worker-cache')
.option('-H, --host <url>', 'URL of DeepForge instance', 'https://editor.deepforge.org')
.action(async cmd => {
const {accessToken, cache, host} = cmd;
process.env.DEEPFORGE_WORKER_CACHE = cache;
await installWorkerDeps();
const config = {};
config[host] = {apiToken: accessToken};
const configFile = path.join(os.tmpdir(), `config-${Date.now()}.json`);
await writeFile(configFile, JSON.stringify(config));
process.on('SIGINT', cleanUp.bind(null, configFile));
process.on('uncaughtException', cleanUp.bind(null, configFile));
process.argv.splice(2, process.argv.length - 2);
process.argv.push(configFile);
startWorker();
});
program.parse(process.argv);
async function cleanUp(configFile) {
try {
await unlink(configFile);
process.exit();
} catch (err) {
console.log('Unable to remove config file:', err);
process.exit(1);
}
}
async function installWorkerDeps() {
const deps = await readFile(path.join(__dirname, 'worker-dependencies.txt'), 'utf8');
const installCmd = `npm install ${deps}`;
await exec(installCmd);
}