@tryghost/listr-smart-renderer 0.2.3 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/index.js +1 -148
- package/lib/smart-renderer.js +149 -0
- package/lib/utils.js +2 -3
- package/package.json +4 -5
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -82,4 +82,4 @@ Follow the instructions for the top-level repo.
|
|
|
82
82
|
|
|
83
83
|
# Copyright & License
|
|
84
84
|
|
|
85
|
-
Copyright (c) 2013-
|
|
85
|
+
Copyright (c) 2013-2022 Ghost Foundation, Sam Verschueren - Released under the [MIT license](LICENSE).
|
package/index.js
CHANGED
|
@@ -1,148 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const logUpdate = require('log-update');
|
|
3
|
-
const chalk = require('chalk');
|
|
4
|
-
const figures = require('figures');
|
|
5
|
-
const cliTruncate = require('cli-truncate');
|
|
6
|
-
const stripAnsi = require('strip-ansi');
|
|
7
|
-
const {indentString, getSymbol, isDefined, taskNumber} = require('./lib/utils');
|
|
8
|
-
|
|
9
|
-
const dataRenderer = (data, prefix = '') => {
|
|
10
|
-
if (typeof data === 'string') {
|
|
11
|
-
data = stripAnsi(data.trim().split('\n').filter(Boolean).pop());
|
|
12
|
-
|
|
13
|
-
if (data === '') {
|
|
14
|
-
data = undefined;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (isDefined(data)) {
|
|
19
|
-
return ` ${chalk.gray(cliTruncate(`${figures.arrowRight} ${prefix} ${data}`, process.stdout.columns - 3))}`;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const fullRenderer = (tasks, options, level = 0) => {
|
|
24
|
-
let output = [];
|
|
25
|
-
|
|
26
|
-
for (const task of tasks) {
|
|
27
|
-
if (!task.isEnabled()) {
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Skipped logic
|
|
32
|
-
const skipped = task.isSkipped() ? ` ${chalk.dim('[skipped]')}` : '';
|
|
33
|
-
|
|
34
|
-
// Main output
|
|
35
|
-
output.push(indentString(`${getSymbol(task, options)} ${task.title}${skipped}`, level));
|
|
36
|
-
|
|
37
|
-
// Handle any task data that needs to be output
|
|
38
|
-
if (isDefined(task.output)) {
|
|
39
|
-
let data = dataRenderer(task.output);
|
|
40
|
-
if (isDefined(data)) {
|
|
41
|
-
output.push(data);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Deal with subtasks
|
|
46
|
-
if (task.hasSubtasks()) {
|
|
47
|
-
output = output.concat(renderHelper(task.subtasks, options, level + 1));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return output.join('\n');
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const summaryRenderer = (tasks, options, level = 0) => {
|
|
55
|
-
let output = [];
|
|
56
|
-
let states = {complete: [], failed: [], skipped: [], disabled: []};
|
|
57
|
-
|
|
58
|
-
tasks.forEach((task, index) => {
|
|
59
|
-
if (task.hasFailed()) {
|
|
60
|
-
states.failed.push(task);
|
|
61
|
-
|
|
62
|
-
if (!task.output && task.hasSubtasks()) {
|
|
63
|
-
task.output = `${chalk.red.dim(`Subtask failed ${figures.arrowDown}`)}`;
|
|
64
|
-
}
|
|
65
|
-
output.push(indentString(`${getSymbol(task, options)} ${taskNumber(index, tasks)}: ${task.title} - ${task.output}`, level));
|
|
66
|
-
} else {
|
|
67
|
-
// Handle any task data that needs to be output
|
|
68
|
-
if (isDefined(task.output)) {
|
|
69
|
-
let data = dataRenderer(task.output, taskNumber(index, tasks));
|
|
70
|
-
if (isDefined(data)) {
|
|
71
|
-
output.push(indentString(data, level));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (task.isPending()) {
|
|
76
|
-
output.push(indentString(`${getSymbol(task, options)} ${taskNumber(index, tasks)}: ${task.title}`, level));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (task.hasSubtasks()) {
|
|
80
|
-
output = output.concat(renderHelper(task.subtasks, options, level + 1));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (task.isCompleted()) {
|
|
84
|
-
states.complete.push(task);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (task.isSkipped()) {
|
|
88
|
-
states.skipped.push(task);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (!task.isEnabled()) {
|
|
92
|
-
states.disabled.push(task);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
output.push(indentString(`Total: ${tasks.length}. Complete: ${states.complete.length}, Failed: ${states.failed.length}, Skipped: ${states.skipped.length}, Disabled: ${states.disabled.length}`, level));
|
|
97
|
-
|
|
98
|
-
return output.join('\n');
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const renderHelper = (tasks, options, level = 0) => {
|
|
102
|
-
// Decide which renderer we want to use
|
|
103
|
-
const renderer = tasks.length > options.maxFullTasks ? summaryRenderer : fullRenderer;
|
|
104
|
-
return renderer(tasks, options, level);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const render = (tasks, options, level = 0) => {
|
|
108
|
-
logUpdate(renderHelper(tasks, options, level));
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
class SmartRenderer {
|
|
112
|
-
constructor(tasks, options) {
|
|
113
|
-
this._tasks = tasks;
|
|
114
|
-
this._mode = 'full';
|
|
115
|
-
this._options = Object.assign({
|
|
116
|
-
maxFullTasks: 30,
|
|
117
|
-
clearOutput: false
|
|
118
|
-
}, options);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
render() {
|
|
122
|
-
if (this._id) {
|
|
123
|
-
// Do not render if we are already rendering
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
this._id = setInterval(() => {
|
|
128
|
-
render(this._tasks, this._options);
|
|
129
|
-
}, 100);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
end(err) {
|
|
133
|
-
if (this._id) {
|
|
134
|
-
clearInterval(this._id);
|
|
135
|
-
this._id = undefined;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
render(this._tasks, this._options);
|
|
139
|
-
|
|
140
|
-
if (this._options.clearOutput && err === undefined) {
|
|
141
|
-
logUpdate.clear();
|
|
142
|
-
} else {
|
|
143
|
-
logUpdate.done();
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
module.exports = SmartRenderer;
|
|
1
|
+
module.exports = require('./lib/smart-renderer');
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const logUpdate = require('log-update');
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
const cliTruncate = require('cli-truncate');
|
|
5
|
+
const stripAnsi = require('strip-ansi');
|
|
6
|
+
const {indentString, getSymbol, isDefined, taskNumber} = require('./utils');
|
|
7
|
+
const arrowRight = '→';
|
|
8
|
+
const arrowDown = '↓';
|
|
9
|
+
|
|
10
|
+
const dataRenderer = (data, prefix = '') => {
|
|
11
|
+
if (typeof data === 'string') {
|
|
12
|
+
data = stripAnsi(data.trim().split('\n').filter(Boolean).pop());
|
|
13
|
+
|
|
14
|
+
if (data === '') {
|
|
15
|
+
data = undefined;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (isDefined(data)) {
|
|
20
|
+
return ` ${chalk.gray(cliTruncate(`${arrowRight} ${prefix} ${data}`, process.stdout.columns - 3))}`;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const fullRenderer = (tasks, options, level = 0) => {
|
|
25
|
+
let output = [];
|
|
26
|
+
|
|
27
|
+
for (const task of tasks) {
|
|
28
|
+
if (!task.isEnabled()) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Skipped logic
|
|
33
|
+
const skipped = task.isSkipped() ? ` ${chalk.dim('[skipped]')}` : '';
|
|
34
|
+
|
|
35
|
+
// Main output
|
|
36
|
+
output.push(indentString(`${getSymbol(task, options)} ${task.title}${skipped}`, level));
|
|
37
|
+
|
|
38
|
+
// Handle any task data that needs to be output
|
|
39
|
+
if (isDefined(task.output)) {
|
|
40
|
+
let data = dataRenderer(task.output);
|
|
41
|
+
if (isDefined(data)) {
|
|
42
|
+
output.push(data);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Deal with subtasks
|
|
47
|
+
if (task.hasSubtasks()) {
|
|
48
|
+
output = output.concat(renderHelper(task.subtasks, options, level + 1));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return output.join('\n');
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const summaryRenderer = (tasks, options, level = 0) => {
|
|
56
|
+
let output = [];
|
|
57
|
+
let states = {complete: [], failed: [], skipped: [], disabled: []};
|
|
58
|
+
|
|
59
|
+
tasks.forEach((task, index) => {
|
|
60
|
+
if (task.hasFailed()) {
|
|
61
|
+
states.failed.push(task);
|
|
62
|
+
|
|
63
|
+
if (!task.output && task.hasSubtasks()) {
|
|
64
|
+
task.output = `${chalk.red.dim(`Subtask failed ${arrowDown}`)}`;
|
|
65
|
+
}
|
|
66
|
+
output.push(indentString(`${getSymbol(task, options)} ${taskNumber(index, tasks)}: ${task.title} - ${task.output}`, level));
|
|
67
|
+
} else {
|
|
68
|
+
// Handle any task data that needs to be output
|
|
69
|
+
if (isDefined(task.output)) {
|
|
70
|
+
let data = dataRenderer(task.output, taskNumber(index, tasks));
|
|
71
|
+
if (isDefined(data)) {
|
|
72
|
+
output.push(indentString(data, level));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (task.isPending()) {
|
|
77
|
+
output.push(indentString(`${getSymbol(task, options)} ${taskNumber(index, tasks)}: ${task.title}`, level));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (task.hasSubtasks()) {
|
|
81
|
+
output = output.concat(renderHelper(task.subtasks, options, level + 1));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (task.isCompleted()) {
|
|
85
|
+
states.complete.push(task);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (task.isSkipped()) {
|
|
89
|
+
states.skipped.push(task);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!task.isEnabled()) {
|
|
93
|
+
states.disabled.push(task);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
output.push(indentString(`Total: ${tasks.length}. Complete: ${states.complete.length}, Failed: ${states.failed.length}, Skipped: ${states.skipped.length}, Disabled: ${states.disabled.length}`, level));
|
|
98
|
+
|
|
99
|
+
return output.join('\n');
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const renderHelper = (tasks, options, level = 0) => {
|
|
103
|
+
// Decide which renderer we want to use
|
|
104
|
+
const renderer = tasks.length > options.maxFullTasks ? summaryRenderer : fullRenderer;
|
|
105
|
+
return renderer(tasks, options, level);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const render = (tasks, options, level = 0) => {
|
|
109
|
+
logUpdate(renderHelper(tasks, options, level));
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
class SmartRenderer {
|
|
113
|
+
constructor(tasks, options) {
|
|
114
|
+
this._tasks = tasks;
|
|
115
|
+
this._mode = 'full';
|
|
116
|
+
this._options = Object.assign({
|
|
117
|
+
maxFullTasks: 30,
|
|
118
|
+
clearOutput: false
|
|
119
|
+
}, options);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
render() {
|
|
123
|
+
if (this._id) {
|
|
124
|
+
// Do not render if we are already rendering
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
this._id = setInterval(() => {
|
|
129
|
+
render(this._tasks, this._options);
|
|
130
|
+
}, 100);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
end(err) {
|
|
134
|
+
if (this._id) {
|
|
135
|
+
clearInterval(this._id);
|
|
136
|
+
this._id = undefined;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
render(this._tasks, this._options);
|
|
140
|
+
|
|
141
|
+
if (this._options.clearOutput && err === undefined) {
|
|
142
|
+
logUpdate.clear();
|
|
143
|
+
} else {
|
|
144
|
+
logUpdate.done();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = SmartRenderer;
|
package/lib/utils.js
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
const chalk = require('chalk');
|
|
3
3
|
const logSymbols = require('log-symbols');
|
|
4
4
|
const indentString = require('indent-string');
|
|
5
|
-
const figures = require('figures');
|
|
6
5
|
const elegantSpinner = require('elegant-spinner');
|
|
7
|
-
const pointer = chalk.yellow(
|
|
8
|
-
const skipped = chalk.yellow(
|
|
6
|
+
const pointer = chalk.yellow('›');
|
|
7
|
+
const skipped = chalk.yellow('↓');
|
|
9
8
|
|
|
10
9
|
exports.isDefined = x => x !== null && x !== undefined;
|
|
11
10
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/listr-smart-renderer",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"repository": "https://github.com/TryGhost/migrate/tree/
|
|
3
|
+
"version": "0.2.7",
|
|
4
|
+
"repository": "https://github.com/TryGhost/migrate/tree/main/packages/listr-smart-renderer",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "index.js",
|
|
@@ -25,14 +25,13 @@
|
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"chalk": "4.1.
|
|
28
|
+
"chalk": "4.1.2",
|
|
29
29
|
"cli-truncate": "^2.0.0",
|
|
30
30
|
"elegant-spinner": "^2.0.0",
|
|
31
|
-
"figures": "3.2.0",
|
|
32
31
|
"indent-string": "^4.0.0",
|
|
33
32
|
"log-symbols": "4.1.0",
|
|
34
33
|
"log-update": "^4.0.0",
|
|
35
34
|
"strip-ansi": "^6.0.0"
|
|
36
35
|
},
|
|
37
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "6407ac2c624bf34de37bdb3608698ca1b1b27b9a"
|
|
38
37
|
}
|