forked from AtomMaterialUI/mtslack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
65 lines (55 loc) · 1.68 KB
/
main.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
#!/usr/bin/env node
const chalk = require('chalk');
const clear = require('clear');
const figlet = require('figlet');
const isRoot = require('is-elevated');
const sample = require('@feizheng/next-sample');
const cli = require('./lib/cli');
const {execute} = require('./lib/command');
const pkg = require('./package.json');
async function run() {
console.log(chalk.yellow(figlet.textSync('mtslack', {
font: sample(['whimsy']),
horizontalLayout: 'default',
verticalLayout: 'default',
width: 80,
whitespaceBreak: true
})));
console.log(chalk.italic(`version ${pkg.version} by @mallowigi`));
console.log(chalk.cyan('Welcome to the mtslack CLI!'));
console.log('');
if (!isRoot()) {
console.log(chalk.red('You must be root to execute this command. Run with "sudo mtslack" (or run as a Windows Administrator)'));
process.exit(1);
}
// noinspection JSDeclarationsAtScopeStart
const {ask: answer} = await cli.ask();
execute(answer);
}
// Start
async function main() {
clear();
await checkForUpdates();
}
async function checkForUpdates() {
// noinspection LocalVariableNamingConventionJS
const AutoUpdate = require('cli-autoupdate');
let shouldUpdate = false;
const update = new AutoUpdate(pkg);
console.log(chalk.bold('Checking for updates...'));
update.on('update', () => {
console.log(chalk.bold('A new update is available! Starting autoupdate...'));
shouldUpdate = true;
});
update.on('finish', async () => {
console.log(chalk.bold('Finished checking for updates!'));
if (shouldUpdate) {
console.log('Update finished. Please rerun the command.');
process.exit(0);
}
else {
await run();
}
});
}
main();