utils.js 788 B

12345678910111213141516171819202122232425262728293031323334
  1. 'use strict';
  2. const chalk = require('chalk');
  3. const logSymbols = require('log-symbols');
  4. const figures = require('figures');
  5. const elegantSpinner = require('elegant-spinner');
  6. const pointer = chalk.yellow(figures.pointer);
  7. const skipped = chalk.yellow(figures.arrowDown);
  8. exports.isDefined = x => x !== null && x !== undefined;
  9. exports.getSymbol = (task, options) => {
  10. if (!task.spinner) {
  11. task.spinner = elegantSpinner();
  12. }
  13. if (task.isPending()) {
  14. return options.showSubtasks !== false && task.subtasks.length > 0 ? pointer : chalk.yellow(task.spinner());
  15. }
  16. if (task.isCompleted()) {
  17. return logSymbols.success;
  18. }
  19. if (task.hasFailed()) {
  20. return task.subtasks.length > 0 ? pointer : logSymbols.error;
  21. }
  22. if (task.isSkipped()) {
  23. return skipped;
  24. }
  25. return ' ';
  26. };