@tryghost/listr-smart-renderer 0.2.10 → 0.4.0
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/README.md +28 -3
- package/index.js +8 -1
- package/lib/smart-renderer.js +7 -7
- package/lib/task-runner.js +20 -0
- package/lib/utils.js +16 -9
- package/package.json +14 -9
package/README.md
CHANGED
|
@@ -19,9 +19,9 @@ or
|
|
|
19
19
|
|
|
20
20
|
## Usage
|
|
21
21
|
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
```js
|
|
23
|
+
import SmartRenderer from '@tryghost/listr-smart-renderer';
|
|
24
|
+
import Listr from 'listr';
|
|
25
25
|
|
|
26
26
|
const list = new Listr([
|
|
27
27
|
{
|
|
@@ -36,6 +36,31 @@ const list = new Listr([
|
|
|
36
36
|
list.run();
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
This package also exports a `makeTaskRunner` method that simplifies your script:
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import {makeTaskRunner} from '@tryghost/listr-smart-renderer';
|
|
43
|
+
|
|
44
|
+
let tasks = [
|
|
45
|
+
{
|
|
46
|
+
title: 'Do some thing',
|
|
47
|
+
task: async (ctx) => {
|
|
48
|
+
// Things here
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
title: 'Do more thing',
|
|
53
|
+
task: async (ctx) => {
|
|
54
|
+
// more here
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
let taskRunner = makeTaskRunner(tasks);
|
|
60
|
+
|
|
61
|
+
await taskRunner.run();
|
|
62
|
+
```
|
|
63
|
+
|
|
39
64
|
## Options
|
|
40
65
|
|
|
41
66
|
These options should be provided in the [Listr](https://github.com/SamVerschueren/listr) options object.
|
package/index.js
CHANGED
package/lib/smart-renderer.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import logUpdate from 'log-update';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import cliTruncate from 'cli-truncate';
|
|
4
|
+
import stripAnsi from 'strip-ansi';
|
|
5
|
+
import {indentString, getSymbol, isDefined, taskNumber} from './utils.js';
|
|
6
|
+
|
|
7
7
|
const arrowRight = '→';
|
|
8
8
|
const arrowDown = '↓';
|
|
9
9
|
|
|
@@ -146,4 +146,4 @@ class SmartRenderer {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
export default SmartRenderer;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Listr from 'listr';
|
|
2
|
+
import smartRenderer from './smart-renderer.js';
|
|
3
|
+
|
|
4
|
+
export default (tasks, options = {}) => {
|
|
5
|
+
let nonVerboseRenderer = options.renderer || smartRenderer;
|
|
6
|
+
|
|
7
|
+
options.renderer = options.verbose ? 'verbose' : nonVerboseRenderer;
|
|
8
|
+
options.exitOnError = options.exitOnError || false;
|
|
9
|
+
options.concurrent = options.concurrent !== undefined ? options.concurrent : 3;
|
|
10
|
+
|
|
11
|
+
// Allow a simple flag to be passed in to set "top level" settings
|
|
12
|
+
if (options.topLevel) {
|
|
13
|
+
// Top level tasks should exit on error, subtasks should report errors, not exit entirely
|
|
14
|
+
options.exitOnError = true;
|
|
15
|
+
// Top level tasks should execute one-after-the-other, most subtasks can have some concurrency
|
|
16
|
+
options.concurrent = false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return new Listr(tasks, options);
|
|
20
|
+
};
|
package/lib/utils.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import logSymbols from 'log-symbols';
|
|
3
|
+
import IndentString from 'indent-string';
|
|
4
|
+
import elegantSpinner from 'elegant-spinner';
|
|
5
|
+
|
|
6
6
|
const pointer = chalk.yellow('›');
|
|
7
7
|
const skipped = chalk.yellow('↓');
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
const isDefined = x => x !== null && x !== undefined;
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const getSymbol = (task, options) => {
|
|
12
12
|
if (!task.spinner) {
|
|
13
13
|
task.spinner = elegantSpinner();
|
|
14
14
|
}
|
|
@@ -32,12 +32,12 @@ exports.getSymbol = (task, options) => {
|
|
|
32
32
|
return ' ';
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
const indentString = (string, level) => IndentString(string, level, ' ');
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Outputs the task number in the form 05/10, so that the output doesn't jump around
|
|
39
39
|
*/
|
|
40
|
-
|
|
40
|
+
const taskNumber = (index, tasks) => {
|
|
41
41
|
// Quick and dirty left pad
|
|
42
42
|
let padSize = String(tasks.length).length;
|
|
43
43
|
let padding = new Array(padSize).join(0);
|
|
@@ -45,3 +45,10 @@ exports.taskNumber = (index, tasks) => {
|
|
|
45
45
|
|
|
46
46
|
return `${taskNum}/${tasks.length}`;
|
|
47
47
|
};
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
isDefined,
|
|
51
|
+
getSymbol,
|
|
52
|
+
indentString,
|
|
53
|
+
taskNumber
|
|
54
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/listr-smart-renderer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
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",
|
|
8
|
+
"type": "module",
|
|
8
9
|
"scripts": {
|
|
9
10
|
"dev": "echo \"Implement me!\"",
|
|
10
|
-
"test": "
|
|
11
|
+
"test": "node --experimental-vm-modules $(yarn bin jest)",
|
|
11
12
|
"lint": "eslint . --ext .js --cache",
|
|
12
13
|
"posttest": "yarn lint"
|
|
13
14
|
},
|
|
@@ -24,14 +25,18 @@
|
|
|
24
25
|
"publishConfig": {
|
|
25
26
|
"access": "public"
|
|
26
27
|
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"jest": "29.1.2",
|
|
30
|
+
"jest-extended": "3.1.0"
|
|
31
|
+
},
|
|
27
32
|
"dependencies": {
|
|
28
|
-
"chalk": "
|
|
29
|
-
"cli-truncate": "^
|
|
30
|
-
"elegant-spinner": "^
|
|
31
|
-
"indent-string": "^
|
|
32
|
-
"log-symbols": "
|
|
33
|
-
"log-update": "^
|
|
33
|
+
"chalk": "5.1.2",
|
|
34
|
+
"cli-truncate": "^3.0.0",
|
|
35
|
+
"elegant-spinner": "^3.0.0",
|
|
36
|
+
"indent-string": "^5.0.0",
|
|
37
|
+
"log-symbols": "5.1.0",
|
|
38
|
+
"log-update": "^5.0.0",
|
|
34
39
|
"strip-ansi": "^6.0.0"
|
|
35
40
|
},
|
|
36
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "8f119b6c370337a90aa51dfbdb8d46ed7f5d154c"
|
|
37
42
|
}
|