-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcli.js
executable file
·74 lines (71 loc) · 2.59 KB
/
cli.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
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
73
74
#!/usr/bin/env node
const Kitchen = require('./src/kitchen');
const execa = require('execa');
const fs = require('fs-extra');
const defaulProcessGroupName = 'appchef-agent';
const args = require('yargs')
.command('start-agents [ecosystem] [options]', 'Starts agents', yargs => {
yargs.positional('ecosystem', {
describe: 'path of pm2 ecosystem file',
default: __dirname + '/ecosystem.config.js',
type: 'string'
});
}, async (argv) => {
const args = process.argv.filter(a => a.startsWith('--'));
args.unshift('start', argv['ecosystem'], '--', `--processGroup="${defaulProcessGroupName}"`);
await execa('pm2', args, {
stdout: process.stdout,
stdin: process.stdin,
stderr: process.stderr,
shell: true
});
}).command('stop-agents', 'Stop agents', {}, async (argv) => {
await execa('pm2', ['delete', defaulProcessGroupName]);
}).command('manage [options]', 'takes and processes orders', async yargs => {
const argv = yargs.argv;
argv.platforms.split(',').forEach(v => {
argv.platforms = v;
new Kitchen(argv).manager.manage(argv.killTimeout);
});
})
.command('process [options]', 'Process build one by one', yargs => {
const args = yargs.argv;
return new Kitchen(args).manager.process();
})
.command('processBuild [options]', 'Assemble cooks to prepare builds', yargs => {
const args = yargs.argv;
return new Kitchen(args).manager.processOrder(args.orderId);
})
.option('appChef', {
describe: 'URL of AppChef server.',
type: 'string'
})
.option('appChefKey', {
describe: 'Secret key to access AppChef.',
type: 'string'
}).option('platforms', {
describe: 'comma separated platforms to target',
type: 'string',
default: 'android'
}).option('opi', {
alias: 'orderPullInterval',
describe: 'Minimum time to rest between builds.',
default: 5000,
type: 'number'
}).option('oi', {
alias: 'orderId',
describe: 'id of order to process',
type: 'string'
}).option('wsDir', {
describe: 'directory to use for builds',
default: require('os').homedir() + '/.app_chef/ws/',
type: 'string'
})
.help('h')
.alias('h', 'help').argv;
process.on('unhandledRejection', (reason, p) => {
console.log("Unhandled rejection at: ", p, " reason: ", reason);
});
process.on('uncaughtException', e => {
console.error("Uncaught Exception: ", e);
});