@oclif/core 3.26.6 → 4.0.0-beta.10

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.
Files changed (124) hide show
  1. package/lib/args.d.ts +4 -4
  2. package/lib/cache.d.ts +3 -3
  3. package/lib/cache.js +1 -1
  4. package/lib/command.d.ts +18 -18
  5. package/lib/command.js +12 -21
  6. package/lib/config/config.d.ts +14 -40
  7. package/lib/config/config.js +120 -153
  8. package/lib/config/plugin-loader.d.ts +6 -6
  9. package/lib/config/plugin-loader.js +4 -28
  10. package/lib/config/plugin.d.ts +3 -3
  11. package/lib/config/plugin.js +7 -11
  12. package/lib/config/ts-path.d.ts +1 -1
  13. package/lib/config/ts-path.js +1 -2
  14. package/lib/config/util.d.ts +1 -1
  15. package/lib/config/util.js +5 -21
  16. package/lib/errors/error.js +5 -8
  17. package/lib/errors/errors/cli.d.ts +5 -5
  18. package/lib/errors/errors/cli.js +5 -5
  19. package/lib/errors/errors/pretty-print.d.ts +2 -2
  20. package/lib/errors/errors/pretty-print.js +2 -2
  21. package/lib/errors/exit.d.ts +1 -0
  22. package/lib/errors/exit.js +8 -0
  23. package/lib/errors/handle.js +4 -11
  24. package/lib/errors/index.d.ts +1 -3
  25. package/lib/errors/index.js +5 -12
  26. package/lib/errors/warn.d.ts +5 -0
  27. package/lib/errors/warn.js +10 -5
  28. package/lib/execute.js +1 -1
  29. package/lib/flags.d.ts +4 -4
  30. package/lib/{cli-ux/flush.js → flush.js} +2 -2
  31. package/lib/help/command.js +6 -5
  32. package/lib/help/formatter.d.ts +3 -3
  33. package/lib/help/formatter.js +8 -9
  34. package/lib/help/index.d.ts +1 -0
  35. package/lib/help/index.js +23 -17
  36. package/lib/help/root.js +3 -3
  37. package/lib/index.d.ts +6 -7
  38. package/lib/index.js +8 -12
  39. package/lib/interfaces/config.d.ts +9 -20
  40. package/lib/interfaces/errors.d.ts +5 -5
  41. package/lib/interfaces/flags.d.ts +2 -2
  42. package/lib/interfaces/index.d.ts +2 -1
  43. package/lib/interfaces/logger.d.ts +9 -0
  44. package/lib/interfaces/parser.d.ts +6 -6
  45. package/lib/interfaces/pjson.d.ts +217 -151
  46. package/lib/interfaces/plugin.d.ts +26 -24
  47. package/lib/interfaces/theme.d.ts +30 -19
  48. package/lib/interfaces/theme.js +2 -19
  49. package/lib/interfaces/topic.d.ts +2 -2
  50. package/lib/logger.d.ts +14 -0
  51. package/lib/logger.js +90 -0
  52. package/lib/main.js +5 -3
  53. package/lib/parser/errors.d.ts +1 -1
  54. package/lib/parser/errors.js +5 -5
  55. package/lib/parser/help.js +2 -2
  56. package/lib/parser/parse.js +2 -1
  57. package/lib/performance.js +3 -2
  58. package/lib/settings.d.ts +5 -11
  59. package/lib/util/determine-priority.d.ts +21 -0
  60. package/lib/util/determine-priority.js +55 -0
  61. package/lib/util/find-root.d.ts +1 -0
  62. package/lib/util/find-root.js +19 -19
  63. package/lib/util/fs.js +12 -0
  64. package/lib/util/ids.d.ts +1 -1
  65. package/lib/util/read-pjson.d.ts +7 -0
  66. package/lib/util/read-pjson.js +60 -0
  67. package/lib/util/read-tsconfig.js +3 -8
  68. package/lib/{cli-ux → ux}/action/base.d.ts +5 -7
  69. package/lib/{cli-ux → ux}/action/base.js +0 -3
  70. package/lib/{cli-ux → ux}/action/spinner.d.ts +5 -4
  71. package/lib/{cli-ux → ux}/action/spinner.js +16 -39
  72. package/lib/ux/action/types.d.ts +5 -0
  73. package/lib/ux/action/types.js +2 -0
  74. package/lib/ux/colorize-json.d.ts +28 -0
  75. package/lib/ux/colorize-json.js +67 -0
  76. package/lib/ux/index.d.ts +69 -0
  77. package/lib/ux/index.js +88 -0
  78. package/lib/{cli-ux → ux}/list.d.ts +1 -1
  79. package/lib/{cli-ux → ux}/list.js +1 -2
  80. package/lib/ux/theme.d.ts +9 -0
  81. package/lib/ux/theme.js +43 -0
  82. package/lib/ux/write.d.ts +2 -0
  83. package/lib/ux/write.js +22 -0
  84. package/package.json +37 -42
  85. package/flush.d.ts +0 -3
  86. package/flush.js +0 -1
  87. package/handle.js +0 -1
  88. package/lib/cli-ux/action/spinners.d.ts +0 -251
  89. package/lib/cli-ux/action/spinners.js +0 -374
  90. package/lib/cli-ux/action/types.d.ts +0 -5
  91. package/lib/cli-ux/config.d.ts +0 -25
  92. package/lib/cli-ux/config.js +0 -52
  93. package/lib/cli-ux/exit.d.ts +0 -8
  94. package/lib/cli-ux/exit.js +0 -16
  95. package/lib/cli-ux/index.d.ts +0 -133
  96. package/lib/cli-ux/index.js +0 -183
  97. package/lib/cli-ux/prompt.d.ts +0 -32
  98. package/lib/cli-ux/prompt.js +0 -185
  99. package/lib/cli-ux/stream.d.ts +0 -23
  100. package/lib/cli-ux/stream.js +0 -43
  101. package/lib/cli-ux/styled/index.d.ts +0 -4
  102. package/lib/cli-ux/styled/index.js +0 -36
  103. package/lib/cli-ux/styled/object.d.ts +0 -1
  104. package/lib/cli-ux/styled/object.js +0 -39
  105. package/lib/cli-ux/styled/progress.d.ts +0 -2
  106. package/lib/cli-ux/styled/progress.js +0 -8
  107. package/lib/cli-ux/styled/table.d.ts +0 -45
  108. package/lib/cli-ux/styled/table.js +0 -345
  109. package/lib/cli-ux/styled/tree.d.ts +0 -9
  110. package/lib/cli-ux/styled/tree.js +0 -37
  111. package/lib/cli-ux/theme.d.ts +0 -11
  112. package/lib/cli-ux/theme.js +0 -61
  113. package/lib/cli-ux/wait.d.ts +0 -2
  114. package/lib/cli-ux/wait.js +0 -5
  115. package/lib/cli-ux/write.d.ts +0 -8
  116. package/lib/cli-ux/write.js +0 -15
  117. package/lib/errors/config.d.ts +0 -6
  118. package/lib/errors/config.js +0 -38
  119. package/lib/errors/logger.d.ts +0 -8
  120. package/lib/errors/logger.js +0 -45
  121. /package/lib/{cli-ux/flush.d.ts → flush.d.ts} +0 -0
  122. /package/lib/{cli-ux/action/types.js → interfaces/logger.js} +0 -0
  123. /package/lib/{cli-ux → ux}/action/simple.d.ts +0 -0
  124. /package/lib/{cli-ux → ux}/action/simple.js +0 -0
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readPjson = void 0;
4
+ const cosmiconfig_1 = require("cosmiconfig");
5
+ const node_path_1 = require("node:path");
6
+ const logger_1 = require("../logger");
7
+ const fs_1 = require("./fs");
8
+ const debug = (0, logger_1.makeDebug)('read-pjson');
9
+ /**
10
+ * Read the package.json file from a given path and add the oclif config (found by cosmiconfig) if it exists.
11
+ *
12
+ * We can assume that the package.json file exists because the plugin root has already been loaded at this point.
13
+ */
14
+ async function readPjson(path) {
15
+ const pjsonPath = (0, node_path_1.join)(path, 'package.json');
16
+ if (process.env.OCLIF_DISABLE_RC) {
17
+ debug('OCLIF_DISABLE_RC is set, skipping rc search');
18
+ return (0, fs_1.readJson)(pjsonPath);
19
+ }
20
+ const pjson = await (0, fs_1.readJson)(pjsonPath);
21
+ // don't bother with cosmiconfig if the plugin's package.json already has an oclif config
22
+ if (pjson.oclif) {
23
+ debug(`found oclif config in ${pjsonPath}`);
24
+ return pjson;
25
+ }
26
+ debug(`searching for oclif config in ${path}`);
27
+ const explorer = (0, cosmiconfig_1.cosmiconfig)('oclif', {
28
+ /**
29
+ * Remove the following from the defaults:
30
+ * - package.json
31
+ * - any files under .config/
32
+ */
33
+ searchPlaces: [
34
+ '.oclifrc',
35
+ '.oclifrc.json',
36
+ '.oclifrc.yaml',
37
+ '.oclifrc.yml',
38
+ '.oclifrc.js',
39
+ '.oclifrc.ts',
40
+ '.oclifrc.mjs',
41
+ '.oclifrc.cjs',
42
+ 'oclif.config.js',
43
+ 'oclif.config.ts',
44
+ 'oclif.config.mjs',
45
+ 'oclif.config.cjs',
46
+ ],
47
+ searchStrategy: 'none',
48
+ });
49
+ const result = await explorer.search(path);
50
+ if (!result?.config) {
51
+ debug(`no oclif config found in ${path}`);
52
+ return pjson;
53
+ }
54
+ debug(`found oclif config for ${path}: %O`, result);
55
+ return {
56
+ ...pjson,
57
+ oclif: result?.config ?? {},
58
+ };
59
+ }
60
+ exports.readPjson = readPjson;
@@ -1,15 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.readTSConfig = void 0;
7
- const debug_1 = __importDefault(require("debug"));
8
4
  const promises_1 = require("node:fs/promises");
9
5
  const node_path_1 = require("node:path");
10
6
  const warn_1 = require("../errors/warn");
7
+ const logger_1 = require("../logger");
11
8
  const util_1 = require("./util");
12
- const debug = (0, debug_1.default)('read-tsconfig');
9
+ const debug = (0, logger_1.makeDebug)('read-tsconfig');
13
10
  function resolve(root, name) {
14
11
  try {
15
12
  return require.resolve(name, { paths: [root] });
@@ -50,9 +47,7 @@ async function readTSConfig(root, tsconfigName = 'tsconfig.json') {
50
47
  return;
51
48
  }
52
49
  const read = async (path) => {
53
- const localRoot = await upUntil(path, async (p) =>
54
- // eslint-disable-next-line unicorn/no-await-expression-member
55
- (await (0, promises_1.readdir)(p)).includes('package.json'));
50
+ const localRoot = await upUntil(path, async (p) => (await (0, promises_1.readdir)(p)).includes('package.json'));
56
51
  if (!localRoot)
57
52
  return;
58
53
  try {
@@ -1,13 +1,10 @@
1
1
  import { Options } from './types';
2
- export interface ITask {
2
+ type Task = {
3
3
  action: string;
4
4
  active: boolean;
5
5
  status: string | undefined;
6
- }
6
+ };
7
7
  export type ActionType = 'debug' | 'simple' | 'spinner';
8
- /**
9
- * @deprecated `ux` will be removed in the next major. See https://github.com/oclif/core/discussions/999
10
- */
11
8
  export declare class ActionBase {
12
9
  std: 'stderr' | 'stdout';
13
10
  protected stdmocks?: ['stderr' | 'stdout', string[]][];
@@ -18,8 +15,8 @@ export declare class ActionBase {
18
15
  get running(): boolean;
19
16
  get status(): string | undefined;
20
17
  set status(status: string | undefined);
21
- get task(): ITask | undefined;
22
- set task(task: ITask | undefined);
18
+ get task(): Task | undefined;
19
+ set task(task: Task | undefined);
23
20
  pause(fn: () => any, icon?: string): Promise<any>;
24
21
  pauseAsync<T>(fn: () => Promise<T>, icon?: string): Promise<T>;
25
22
  start(action: string, status?: string, opts?: Options): void;
@@ -34,3 +31,4 @@ export declare class ActionBase {
34
31
  protected _write(std: 'stderr' | 'stdout', s: string | string[]): void;
35
32
  private get globals();
36
33
  }
34
+ export {};
@@ -3,9 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ActionBase = void 0;
4
4
  const node_util_1 = require("node:util");
5
5
  const util_1 = require("../../util/util");
6
- /**
7
- * @deprecated `ux` will be removed in the next major. See https://github.com/oclif/core/discussions/999
8
- */
9
6
  class ActionBase {
10
7
  std = 'stderr';
11
8
  stdmocks;
@@ -1,12 +1,13 @@
1
- /// <reference types="node" />
2
1
  import { ActionBase, ActionType } from './base';
3
2
  import { Options } from './types';
4
3
  export default class SpinnerAction extends ActionBase {
5
- frameIndex: number;
6
- frames: string[];
7
- spinner?: NodeJS.Timeout;
8
4
  type: ActionType;
5
+ private color;
6
+ private frameIndex;
7
+ private frames;
8
+ private spinner?;
9
9
  constructor();
10
+ protected colorize(s: string): string;
10
11
  protected _frame(): string;
11
12
  private _lines;
12
13
  protected _pause(icon?: string): void;
@@ -1,62 +1,38 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
29
- const ansi_styles_1 = __importDefault(require("ansi-styles"));
30
- const chalk_1 = __importDefault(require("chalk"));
31
- const strip_ansi_1 = __importDefault(require("strip-ansi"));
32
- const supportsColor = __importStar(require("supports-color"));
6
+ const ansis_1 = __importDefault(require("ansis"));
7
+ const cli_spinners_1 = __importDefault(require("cli-spinners"));
8
+ const cache_1 = __importDefault(require("../../cache"));
33
9
  const screen_1 = require("../../screen");
10
+ const theme_1 = require("../theme");
34
11
  const base_1 = require("./base");
35
- const spinners_1 = __importDefault(require("./spinners"));
36
12
  const ansiEscapes = require('ansi-escapes');
37
- function color(s) {
38
- if (!supportsColor)
39
- return s;
40
- const has256 = supportsColor.stdout ? supportsColor.stdout.has256 : (process.env.TERM || '').includes('256');
41
- return has256 ? `\u001B[38;5;104m${s}${ansi_styles_1.default.reset.open}` : chalk_1.default.magenta(s);
42
- }
43
13
  class SpinnerAction extends base_1.ActionBase {
14
+ type = 'spinner';
15
+ color = 'magenta';
44
16
  frameIndex;
45
17
  frames;
46
18
  spinner;
47
- type = 'spinner';
48
19
  constructor() {
49
20
  super();
50
21
  this.frames = this.getFrames();
51
22
  this.frameIndex = 0;
52
23
  }
24
+ colorize(s) {
25
+ return (0, theme_1.colorize)(this.color, s);
26
+ }
53
27
  _frame() {
54
28
  const frame = this.frames[this.frameIndex];
55
29
  this.frameIndex = ++this.frameIndex % this.frames.length;
56
- return color(frame);
30
+ return this.colorize(frame);
57
31
  }
58
32
  _lines(s) {
59
- return (0, strip_ansi_1.default)(s).split('\n').map((l) => Math.ceil(l.length / screen_1.errtermwidth)).reduce((c, i) => c + i, 0);
33
+ return ansis_1.default.strip(s).split('\n')
34
+ .map((l) => Math.ceil(l.length / screen_1.errtermwidth))
35
+ .reduce((c, i) => c + i, 0);
60
36
  }
61
37
  _pause(icon) {
62
38
  if (this.spinner)
@@ -84,6 +60,7 @@ class SpinnerAction extends base_1.ActionBase {
84
60
  this.output = undefined;
85
61
  }
86
62
  _start(opts) {
63
+ this.color = cache_1.default.getInstance().get('config')?.theme?.spinner ?? this.color;
87
64
  if (opts.style)
88
65
  this.frames = this.getFrames(opts);
89
66
  this._reset();
@@ -104,8 +81,8 @@ class SpinnerAction extends base_1.ActionBase {
104
81
  }
105
82
  getFrames(opts) {
106
83
  if (opts?.style)
107
- return spinners_1.default[opts.style].frames;
108
- return spinners_1.default[process.platform === 'win32' ? 'line' : 'dots2'].frames;
84
+ return cli_spinners_1.default[opts.style].frames;
85
+ return cli_spinners_1.default[process.platform === 'win32' ? 'line' : 'dots2'].frames;
109
86
  }
110
87
  }
111
88
  exports.default = SpinnerAction;
@@ -0,0 +1,5 @@
1
+ import * as spinners from 'cli-spinners';
2
+ export type Options = {
3
+ stdout?: boolean;
4
+ style?: spinners.SpinnerName | 'random';
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,28 @@
1
+ type Options = {
2
+ pretty?: boolean | undefined;
3
+ theme?: Record<string, string> | undefined;
4
+ };
5
+ export declare function tokenize(json?: unknown, options?: Options): {
6
+ type: string;
7
+ value: string;
8
+ }[];
9
+ /**
10
+ * Add color to JSON.
11
+ *
12
+ * options
13
+ * pretty: set to true to pretty print the JSON (defaults to true)
14
+ * theme: theme to use for colorizing. See keys below for available options. All keys are optional and must be valid colors (e.g. hex code, rgb, or standard ansi color).
15
+ *
16
+ * Available theme keys:
17
+ * - brace
18
+ * - bracket
19
+ * - colon
20
+ * - comma
21
+ * - key
22
+ * - string
23
+ * - number
24
+ * - boolean
25
+ * - null
26
+ */
27
+ export default function colorizeJson(json: unknown, options?: Options): string;
28
+ export {};
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tokenize = void 0;
4
+ const theme_1 = require("./theme");
5
+ const tokenTypes = [
6
+ { regex: /^\s+/, tokenType: 'whitespace' },
7
+ { regex: /^[{}]/, tokenType: 'brace' },
8
+ { regex: /^[[\]]/, tokenType: 'bracket' },
9
+ { regex: /^:/, tokenType: 'colon' },
10
+ { regex: /^,/, tokenType: 'comma' },
11
+ { regex: /^-?\d+(?:\.\d+)?(?:e[+-]?\d+)?/i, tokenType: 'number' },
12
+ { regex: /^"(?:\\.|[^"\\])*"(?=\s*:)/, tokenType: 'key' },
13
+ { regex: /^"(?:\\.|[^"\\])*"/, tokenType: 'string' },
14
+ { regex: /^true|^false/, tokenType: 'boolean' },
15
+ { regex: /^null/, tokenType: 'null' },
16
+ ];
17
+ function formatInput(json, options) {
18
+ return options?.pretty
19
+ ? JSON.stringify(typeof json === 'string' ? JSON.parse(json) : json, null, 2)
20
+ : typeof json === 'string'
21
+ ? json
22
+ : JSON.stringify(json);
23
+ }
24
+ function tokenize(json, options) {
25
+ let input = formatInput(json, options);
26
+ const tokens = [];
27
+ let foundToken = false;
28
+ do {
29
+ for (const tokenType of tokenTypes) {
30
+ const match = tokenType.regex.exec(input);
31
+ if (match) {
32
+ tokens.push({ type: tokenType.tokenType, value: match[0] });
33
+ input = input.slice(match[0].length);
34
+ foundToken = true;
35
+ break;
36
+ }
37
+ }
38
+ } while (hasRemainingTokens(input, foundToken));
39
+ return tokens;
40
+ }
41
+ exports.tokenize = tokenize;
42
+ function hasRemainingTokens(input, foundToken) {
43
+ return (input?.length ?? 0) > 0 && foundToken;
44
+ }
45
+ /**
46
+ * Add color to JSON.
47
+ *
48
+ * options
49
+ * pretty: set to true to pretty print the JSON (defaults to true)
50
+ * theme: theme to use for colorizing. See keys below for available options. All keys are optional and must be valid colors (e.g. hex code, rgb, or standard ansi color).
51
+ *
52
+ * Available theme keys:
53
+ * - brace
54
+ * - bracket
55
+ * - colon
56
+ * - comma
57
+ * - key
58
+ * - string
59
+ * - number
60
+ * - boolean
61
+ * - null
62
+ */
63
+ function colorizeJson(json, options) {
64
+ const opts = { ...options, pretty: options?.pretty ?? true };
65
+ return tokenize(json, opts).reduce((acc, token) => acc + (0, theme_1.colorize)(options?.theme?.[token.type], token.value), '');
66
+ }
67
+ exports.default = colorizeJson;
@@ -0,0 +1,69 @@
1
+ import { error } from '../errors/error';
2
+ import { exit } from '../errors/exit';
3
+ import { warn } from '../errors/warn';
4
+ import Simple from './action/simple';
5
+ import Spinner from './action/spinner';
6
+ import colorizeJson from './colorize-json';
7
+ import { colorize } from './theme';
8
+ export { error } from '../errors/error';
9
+ export { exit } from '../errors/exit';
10
+ export { warn } from '../errors/warn';
11
+ export { default as colorizeJson } from './colorize-json';
12
+ export { colorize } from './theme';
13
+ export { stderr, stdout } from './write';
14
+ export declare const ux: {
15
+ action: Simple | Spinner;
16
+ /**
17
+ * Add color to text.
18
+ * @param color color to use. Can be hex code (e.g. `#ff0000`), rgb (e.g. `rgb(255, 255, 255)`) or a standard ansi color (e.g. `red`)
19
+ * @param text string to colorize
20
+ * @returns colorized string
21
+ */
22
+ colorize: typeof colorize;
23
+ /**
24
+ * Add color to JSON.
25
+ *
26
+ * options
27
+ * pretty: set to true to pretty print the JSON (defaults to true)
28
+ * theme: theme to use for colorizing. See keys below for available options. All keys are optional and must be valid colors (e.g. hex code, rgb, or standard ansi color).
29
+ *
30
+ * Available theme keys:
31
+ * - brace
32
+ * - bracket
33
+ * - colon
34
+ * - comma
35
+ * - key
36
+ * - string
37
+ * - number
38
+ * - boolean
39
+ * - null
40
+ */
41
+ colorizeJson: typeof colorizeJson;
42
+ /**
43
+ * Throw an error.
44
+ *
45
+ * If `exit` option is `false`, the error will be logged to stderr but not exit the process.
46
+ * If `exit` is set to a number, the process will exit with that code.
47
+ */
48
+ error: typeof error;
49
+ /**
50
+ * Exit the process with provided exit code (defaults to 0).
51
+ */
52
+ exit: typeof exit;
53
+ /**
54
+ * Log a formatted string to stderr.
55
+ *
56
+ * See node's util.format() for formatting options.
57
+ */
58
+ stderr: (str: string | string[] | undefined, ...args: string[]) => void;
59
+ /**
60
+ * Log a formatted string to stdout.
61
+ *
62
+ * See node's util.format() for formatting options.
63
+ */
64
+ stdout: (str: string | string[] | undefined, ...args: string[]) => void;
65
+ /**
66
+ * Prints a pretty warning message to stderr.
67
+ */
68
+ warn: typeof warn;
69
+ };
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ux = exports.stdout = exports.stderr = exports.colorize = exports.colorizeJson = exports.warn = exports.exit = exports.error = void 0;
7
+ const error_1 = require("../errors/error");
8
+ const exit_1 = require("../errors/exit");
9
+ const warn_1 = require("../errors/warn");
10
+ const simple_1 = __importDefault(require("./action/simple"));
11
+ const spinner_1 = __importDefault(require("./action/spinner"));
12
+ const colorize_json_1 = __importDefault(require("./colorize-json"));
13
+ const theme_1 = require("./theme");
14
+ const write_1 = require("./write");
15
+ var error_2 = require("../errors/error");
16
+ Object.defineProperty(exports, "error", { enumerable: true, get: function () { return error_2.error; } });
17
+ var exit_2 = require("../errors/exit");
18
+ Object.defineProperty(exports, "exit", { enumerable: true, get: function () { return exit_2.exit; } });
19
+ var warn_2 = require("../errors/warn");
20
+ Object.defineProperty(exports, "warn", { enumerable: true, get: function () { return warn_2.warn; } });
21
+ var colorize_json_2 = require("./colorize-json");
22
+ Object.defineProperty(exports, "colorizeJson", { enumerable: true, get: function () { return __importDefault(colorize_json_2).default; } });
23
+ var theme_2 = require("./theme");
24
+ Object.defineProperty(exports, "colorize", { enumerable: true, get: function () { return theme_2.colorize; } });
25
+ var write_2 = require("./write");
26
+ Object.defineProperty(exports, "stderr", { enumerable: true, get: function () { return write_2.stderr; } });
27
+ Object.defineProperty(exports, "stdout", { enumerable: true, get: function () { return write_2.stdout; } });
28
+ const ACTION_TYPE = (Boolean(process.stderr.isTTY) &&
29
+ !process.env.CI &&
30
+ !['dumb', 'emacs-color'].includes(process.env.TERM) &&
31
+ 'spinner') ||
32
+ 'simple';
33
+ exports.ux = {
34
+ action: ACTION_TYPE === 'spinner' ? new spinner_1.default() : new simple_1.default(),
35
+ /**
36
+ * Add color to text.
37
+ * @param color color to use. Can be hex code (e.g. `#ff0000`), rgb (e.g. `rgb(255, 255, 255)`) or a standard ansi color (e.g. `red`)
38
+ * @param text string to colorize
39
+ * @returns colorized string
40
+ */
41
+ colorize: theme_1.colorize,
42
+ /**
43
+ * Add color to JSON.
44
+ *
45
+ * options
46
+ * pretty: set to true to pretty print the JSON (defaults to true)
47
+ * theme: theme to use for colorizing. See keys below for available options. All keys are optional and must be valid colors (e.g. hex code, rgb, or standard ansi color).
48
+ *
49
+ * Available theme keys:
50
+ * - brace
51
+ * - bracket
52
+ * - colon
53
+ * - comma
54
+ * - key
55
+ * - string
56
+ * - number
57
+ * - boolean
58
+ * - null
59
+ */
60
+ colorizeJson: colorize_json_1.default,
61
+ /**
62
+ * Throw an error.
63
+ *
64
+ * If `exit` option is `false`, the error will be logged to stderr but not exit the process.
65
+ * If `exit` is set to a number, the process will exit with that code.
66
+ */
67
+ error: error_1.error,
68
+ /**
69
+ * Exit the process with provided exit code (defaults to 0).
70
+ */
71
+ exit: exit_1.exit,
72
+ /**
73
+ * Log a formatted string to stderr.
74
+ *
75
+ * See node's util.format() for formatting options.
76
+ */
77
+ stderr: write_1.stderr,
78
+ /**
79
+ * Log a formatted string to stdout.
80
+ *
81
+ * See node's util.format() for formatting options.
82
+ */
83
+ stdout: write_1.stdout,
84
+ /**
85
+ * Prints a pretty warning message to stderr.
86
+ */
87
+ warn: warn_1.warn,
88
+ };
@@ -1,3 +1,3 @@
1
1
  export type IListItem = [string, string | undefined];
2
2
  export type IList = IListItem[];
3
- export declare function renderList(items: IListItem[]): string;
3
+ export default function renderList(items: IListItem[]): string;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.renderList = void 0;
4
3
  const screen_1 = require("../screen");
5
4
  const util_1 = require("../util/util");
6
5
  const wordwrap = require('wordwrap');
@@ -26,4 +25,4 @@ function renderList(items) {
26
25
  });
27
26
  return lines.join('\n');
28
27
  }
29
- exports.renderList = renderList;
28
+ exports.default = renderList;
@@ -0,0 +1,9 @@
1
+ import { StandardAnsi, Theme } from '../interfaces/theme';
2
+ /**
3
+ * Add color to text.
4
+ * @param color color to use. Can be hex code (e.g. `#ff0000`), rgb (e.g. `rgb(255, 255, 255)`) or a standard ansi color (e.g. `red`)
5
+ * @param text string to colorize
6
+ * @returns colorized string
7
+ */
8
+ export declare function colorize(color: string | StandardAnsi | undefined, text: string): string;
9
+ export declare function parseTheme(theme: Record<string, string | Record<string, string>>): Theme;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseTheme = exports.colorize = void 0;
7
+ const ansis_1 = __importDefault(require("ansis"));
8
+ const theme_1 = require("../interfaces/theme");
9
+ function isStandardChalk(color) {
10
+ return theme_1.STANDARD_ANSI.includes(color);
11
+ }
12
+ /**
13
+ * Add color to text.
14
+ * @param color color to use. Can be hex code (e.g. `#ff0000`), rgb (e.g. `rgb(255, 255, 255)`) or a standard ansi color (e.g. `red`)
15
+ * @param text string to colorize
16
+ * @returns colorized string
17
+ */
18
+ function colorize(color, text) {
19
+ if (!color)
20
+ return text;
21
+ if (isStandardChalk(color))
22
+ return ansis_1.default[color](text);
23
+ if (color.startsWith('#'))
24
+ return ansis_1.default.hex(color)(text);
25
+ if (color.startsWith('rgb')) {
26
+ const [red, green, blue] = color
27
+ .slice(4, -1)
28
+ .split(',')
29
+ .map((c) => Number.parseInt(c.trim(), 10));
30
+ return ansis_1.default.rgb(red, green, blue)(text);
31
+ }
32
+ return text;
33
+ }
34
+ exports.colorize = colorize;
35
+ function parseTheme(theme) {
36
+ return Object.fromEntries(Object.entries(theme)
37
+ .map(([key, value]) => [key, typeof value === 'string' ? isValid(value) : parseTheme(value)])
38
+ .filter(([_, value]) => value));
39
+ }
40
+ exports.parseTheme = parseTheme;
41
+ function isValid(color) {
42
+ return color.startsWith('#') || color.startsWith('rgb') || isStandardChalk(color) ? color : undefined;
43
+ }
@@ -0,0 +1,2 @@
1
+ export declare const stdout: (str: string | string[] | undefined, ...args: string[]) => void;
2
+ export declare const stderr: (str: string | string[] | undefined, ...args: string[]) => void;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.stderr = exports.stdout = void 0;
4
+ const node_util_1 = require("node:util");
5
+ const stdout = (str, ...args) => {
6
+ if (typeof str === 'string' || !str) {
7
+ process.stdout.write((0, node_util_1.format)(str, ...args) + '\n');
8
+ }
9
+ else {
10
+ process.stdout.write((0, node_util_1.format)(...str, ...args) + '\n');
11
+ }
12
+ };
13
+ exports.stdout = stdout;
14
+ const stderr = (str, ...args) => {
15
+ if (typeof str === 'string' || !str) {
16
+ process.stderr.write((0, node_util_1.format)(str, ...args) + '\n');
17
+ }
18
+ else {
19
+ process.stderr.write((0, node_util_1.format)(...str, ...args) + '\n');
20
+ }
21
+ };
22
+ exports.stderr = stderr;