-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (36 loc) · 1.08 KB
/
index.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
const {grey,red,yellow,green} = require('chalk')
const logUpdate = require('log-update');
const elegantSpinner = require('elegant-spinner');
const t = require('outdent')
const taskler = (tasks, done = n => n) => {
let canvas = {};
const refreshLoopInerval = setInterval(() => {
logUpdate(t`
${
Object.keys(canvas).map(line => {
return t`
${canvas[line].status === 'running' ? yellow(canvas[line].spinner()) : green('✔') } ${canvas[line].title}${canvas[line].status === 'running' ? canvas[line].sub ? '\n' + grey(' → ' + canvas[line].sub) : '' : ''}`
}).join('\n')
}
`);
if(!Object.values(canvas).some(({status}) => status === 'running')) {
clearInterval(refreshLoopInerval);
done();
}
}, 80);
tasks.forEach(({title, task}) => {
canvas[title] = {
status: 'running',
title,
sub: '',
spinner: elegantSpinner()
}
task({
emit: text => canvas[title].sub = text,
succeed: () => {
canvas[title].status = 'succeed'
}
})
})
}
module.exports = taskler