@tryghost/listr-smart-renderer 0.3.0 → 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 CHANGED
@@ -19,9 +19,9 @@ or
19
19
 
20
20
  ## Usage
21
21
 
22
- ```
23
- const SmartRenderer = require('@tryghost/listr-smart-renderer');
24
- const Listr = require('listr');
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
@@ -1 +1,8 @@
1
- module.exports = require('./lib/smart-renderer');
1
+ import SmartRenderer from './lib/smart-renderer.js';
2
+ import makeTaskRunner from './lib/task-runner.js';
3
+
4
+ export default SmartRenderer;
5
+
6
+ export {
7
+ makeTaskRunner
8
+ };
@@ -1,9 +1,9 @@
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');
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
- module.exports = SmartRenderer;
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
- 'use strict';
2
- const chalk = require('chalk');
3
- const logSymbols = require('log-symbols');
4
- const indentString = require('indent-string');
5
- const elegantSpinner = require('elegant-spinner');
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
- exports.isDefined = x => x !== null && x !== undefined;
9
+ const isDefined = x => x !== null && x !== undefined;
10
10
 
11
- exports.getSymbol = (task, options) => {
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
- exports.indentString = (string, level) => indentString(string, level, ' ');
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
- exports.taskNumber = (index, tasks) => {
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.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": "NODE_ENV=testing jest",
11
+ "test": "node --experimental-vm-modules $(yarn bin jest)",
11
12
  "lint": "eslint . --ext .js --cache",
12
13
  "posttest": "yarn lint"
13
14
  },
@@ -29,13 +30,13 @@
29
30
  "jest-extended": "3.1.0"
30
31
  },
31
32
  "dependencies": {
32
- "chalk": "4.1.2",
33
- "cli-truncate": "^2.0.0",
34
- "elegant-spinner": "^2.0.0",
35
- "indent-string": "^4.0.0",
36
- "log-symbols": "4.1.0",
37
- "log-update": "^4.0.0",
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",
38
39
  "strip-ansi": "^6.0.0"
39
40
  },
40
- "gitHead": "35cb5c1ca6a826e1e596c4f2e209ab690fa06fa0"
41
+ "gitHead": "8f119b6c370337a90aa51dfbdb8d46ed7f5d154c"
41
42
  }