-
Notifications
You must be signed in to change notification settings - Fork 10
/
spinner.js
executable file
·51 lines (41 loc) · 1009 Bytes
/
spinner.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
#!/usr/bin/env node
const ora = require('ora');
const chalk = require('chalk');
const cache = {};
const isTTY = process.env.CI ? false : process.stdout.isTTY;
function create(text) {
if (!isTTY) {
console.log(chalk`{cyan [create-nextron-app]} ${text}`);
return;
}
const { spinner } = cache;
if (spinner) {
spinner.succeed();
delete cache.spinner;
}
cache.spinner = ora({
text,
color: 'magenta',
}).start();
}
function clear(message, isError) {
if (!isTTY) {
console.log(chalk`{cyan [create-nextron-app]} ${message}`);
return;
}
const { spinner } = cache;
if (spinner) {
(isError ? spinner.fail() : spinner.succeed());
delete cache.spinner;
console.log('');
}
const prefix = isError ? chalk.red('Error!') : chalk.green('Done!');
console.log(`${prefix} ${message}`);
}
function fail(message) {
clear(message, true);
process.exit(1);
}
module.exports.create = create;
module.exports.clear = clear;
module.exports.fail = fail;