/
cli.mjs
60 lines (52 loc) · 1.67 KB
/
cli.mjs
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
#!/usr/bin/env node
import all, { lts, current, nightly } from './module.mjs';
const args = process.argv.slice(2);
const asJson = args.find((arg) => /^j+[son]*$/im.test(arg));
function formatData(data) {
if (asJson) {
console.log(JSON.stringify(data, null, 2));
} else if (Object.keys(data).length === 1) {
console.log(data[Object.keys(data)[0]]);
} else {
data.lts && console.log(`LTS: ${data.lts}`);
data.current && console.log(`Current: ${data.current}`);
data.nightly && console.log(`Nightly: ${data.nightly}`);
}
}
if (args.length === 0 || (args.length === 1 && asJson)) {
const versions = await all();
formatData(versions, true);
} else {
switch (args[0].toLowerCase()) {
case /^-*[h\?]+[elp]*$/m.test(args[0]) ? args[0] : '':
help();
break;
case 'l':
case 'lts':
const ltsVersion = await lts();
formatData({ lts: ltsVersion });
break;
case 'c':
case 'current':
const currentVersion = await current();
formatData({ current: currentVersion });
break;
case 'n':
case 'nightly':
const nightlyVersion = await nightly();
formatData({ nightly: nightlyVersion });
break;
default:
console.log('Type "vernode help" to see available commands');
}
}
function help() {
console.log('\nShow all versions (LTS, Current and Nightly)');
console.log('Just run this app without arguments\n');
console.log('Show LTS version (l, lts)');
console.log('Example: vernode lts\n');
console.log('Show Current version (c, current)');
console.log('Example: vernode current\n');
console.log('Show Nightly version (n, nightly)');
console.log('Example: vernode nightly\n');
}