@oclif/core 3.26.4 → 4.0.0-beta.2

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 (78) hide show
  1. package/lib/command.js +6 -6
  2. package/lib/config/config.d.ts +3 -4
  3. package/lib/config/config.js +42 -39
  4. package/lib/config/ts-path.js +5 -5
  5. package/lib/errors/error.js +2 -5
  6. package/lib/errors/errors/cli.js +3 -3
  7. package/lib/errors/exit.d.ts +1 -0
  8. package/lib/errors/exit.js +8 -0
  9. package/lib/errors/index.d.ts +1 -1
  10. package/lib/errors/index.js +5 -8
  11. package/lib/errors/logger.js +5 -2
  12. package/lib/errors/warn.d.ts +13 -2
  13. package/lib/errors/warn.js +15 -11
  14. package/lib/execute.js +1 -1
  15. package/lib/{cli-ux/flush.js → flush.js} +1 -1
  16. package/lib/help/command.js +6 -5
  17. package/lib/help/formatter.js +8 -9
  18. package/lib/help/index.js +6 -9
  19. package/lib/help/root.js +3 -3
  20. package/lib/index.d.ts +2 -3
  21. package/lib/index.js +6 -12
  22. package/lib/interfaces/config.d.ts +1 -0
  23. package/lib/interfaces/pjson.d.ts +1 -1
  24. package/lib/interfaces/theme.d.ts +30 -19
  25. package/lib/interfaces/theme.js +2 -19
  26. package/lib/main.js +2 -2
  27. package/lib/parser/errors.js +5 -5
  28. package/lib/parser/help.js +2 -2
  29. package/lib/util/read-tsconfig.js +1 -1
  30. package/lib/{cli-ux → ux}/action/base.d.ts +5 -7
  31. package/lib/{cli-ux → ux}/action/base.js +0 -3
  32. package/lib/{cli-ux → ux}/action/spinner.d.ts +5 -4
  33. package/lib/{cli-ux → ux}/action/spinner.js +16 -39
  34. package/lib/ux/action/types.d.ts +5 -0
  35. package/lib/ux/colorize-json.d.ts +28 -0
  36. package/lib/ux/colorize-json.js +67 -0
  37. package/lib/ux/index.d.ts +64 -0
  38. package/lib/ux/index.js +76 -0
  39. package/lib/{cli-ux → ux}/list.d.ts +1 -1
  40. package/lib/{cli-ux → ux}/list.js +1 -2
  41. package/lib/ux/theme.d.ts +9 -0
  42. package/lib/ux/theme.js +43 -0
  43. package/lib/ux/write.d.ts +2 -0
  44. package/lib/ux/write.js +22 -0
  45. package/package.json +11 -33
  46. package/lib/cli-ux/action/spinners.d.ts +0 -251
  47. package/lib/cli-ux/action/spinners.js +0 -374
  48. package/lib/cli-ux/action/types.d.ts +0 -5
  49. package/lib/cli-ux/config.d.ts +0 -25
  50. package/lib/cli-ux/config.js +0 -52
  51. package/lib/cli-ux/exit.d.ts +0 -8
  52. package/lib/cli-ux/exit.js +0 -16
  53. package/lib/cli-ux/index.d.ts +0 -133
  54. package/lib/cli-ux/index.js +0 -183
  55. package/lib/cli-ux/prompt.d.ts +0 -32
  56. package/lib/cli-ux/prompt.js +0 -185
  57. package/lib/cli-ux/stream.d.ts +0 -23
  58. package/lib/cli-ux/stream.js +0 -43
  59. package/lib/cli-ux/styled/index.d.ts +0 -4
  60. package/lib/cli-ux/styled/index.js +0 -36
  61. package/lib/cli-ux/styled/object.d.ts +0 -1
  62. package/lib/cli-ux/styled/object.js +0 -39
  63. package/lib/cli-ux/styled/progress.d.ts +0 -2
  64. package/lib/cli-ux/styled/progress.js +0 -8
  65. package/lib/cli-ux/styled/table.d.ts +0 -45
  66. package/lib/cli-ux/styled/table.js +0 -345
  67. package/lib/cli-ux/styled/tree.d.ts +0 -9
  68. package/lib/cli-ux/styled/tree.js +0 -37
  69. package/lib/cli-ux/theme.d.ts +0 -11
  70. package/lib/cli-ux/theme.js +0 -61
  71. package/lib/cli-ux/wait.d.ts +0 -2
  72. package/lib/cli-ux/wait.js +0 -5
  73. package/lib/cli-ux/write.d.ts +0 -8
  74. package/lib/cli-ux/write.js +0 -15
  75. /package/lib/{cli-ux/flush.d.ts → flush.d.ts} +0 -0
  76. /package/lib/{cli-ux → ux}/action/simple.d.ts +0 -0
  77. /package/lib/{cli-ux → ux}/action/simple.js +0 -0
  78. /package/lib/{cli-ux → ux}/action/types.js +0 -0
package/lib/index.d.ts CHANGED
@@ -1,13 +1,11 @@
1
1
  export * as Args from './args';
2
- export * as ux from './cli-ux';
3
- export { flush } from './cli-ux/flush';
4
- export { stderr, stdout } from './cli-ux/stream';
5
2
  export { Command } from './command';
6
3
  export { Config, Plugin } from './config';
7
4
  export * as Errors from './errors';
8
5
  export { handle } from './errors/handle';
9
6
  export { execute } from './execute';
10
7
  export * as Flags from './flags';
8
+ export { flush } from './flush';
11
9
  export { CommandHelp, Help, HelpBase, loadHelpClass } from './help';
12
10
  export { HelpSection, HelpSectionKeyValueTable, HelpSectionRenderer } from './help/formatter';
13
11
  export * as Interfaces from './interfaces';
@@ -18,3 +16,4 @@ export * as Parser from './parser';
18
16
  export { Performance } from './performance';
19
17
  export { Settings, settings } from './settings';
20
18
  export { toConfiguredId, toStandardizedId } from './util/ids';
19
+ export { methods as ux } from './ux';
package/lib/index.js CHANGED
@@ -22,30 +22,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.toStandardizedId = exports.toConfiguredId = exports.settings = exports.Performance = exports.Parser = exports.ModuleLoader = exports.run = exports.Interfaces = exports.loadHelpClass = exports.HelpBase = exports.Help = exports.CommandHelp = exports.Flags = exports.execute = exports.handle = exports.Errors = exports.Plugin = exports.Config = exports.Command = exports.stdout = exports.stderr = exports.flush = exports.ux = exports.Args = void 0;
30
- const write_1 = __importDefault(require("./cli-ux/write"));
26
+ exports.ux = exports.toStandardizedId = exports.toConfiguredId = exports.settings = exports.Performance = exports.Parser = exports.ModuleLoader = exports.run = exports.Interfaces = exports.loadHelpClass = exports.HelpBase = exports.Help = exports.CommandHelp = exports.flush = exports.Flags = exports.execute = exports.handle = exports.Errors = exports.Plugin = exports.Config = exports.Command = exports.Args = void 0;
31
27
  function checkCWD() {
32
28
  try {
33
29
  process.cwd();
34
30
  }
35
31
  catch (error) {
36
32
  if (error.code === 'ENOENT') {
37
- write_1.default.stderr('WARNING: current directory does not exist\n');
33
+ process.stderr.write('WARNING: current directory does not exist\n');
38
34
  }
39
35
  }
40
36
  }
41
37
  checkCWD();
42
38
  exports.Args = __importStar(require("./args"));
43
- exports.ux = __importStar(require("./cli-ux"));
44
- var flush_1 = require("./cli-ux/flush");
45
- Object.defineProperty(exports, "flush", { enumerable: true, get: function () { return flush_1.flush; } });
46
- var stream_1 = require("./cli-ux/stream"); // Remove these in the next major version
47
- Object.defineProperty(exports, "stderr", { enumerable: true, get: function () { return stream_1.stderr; } });
48
- Object.defineProperty(exports, "stdout", { enumerable: true, get: function () { return stream_1.stdout; } });
49
39
  var command_1 = require("./command");
50
40
  Object.defineProperty(exports, "Command", { enumerable: true, get: function () { return command_1.Command; } });
51
41
  var config_1 = require("./config");
@@ -57,6 +47,8 @@ Object.defineProperty(exports, "handle", { enumerable: true, get: function () {
57
47
  var execute_1 = require("./execute");
58
48
  Object.defineProperty(exports, "execute", { enumerable: true, get: function () { return execute_1.execute; } });
59
49
  exports.Flags = __importStar(require("./flags"));
50
+ var flush_1 = require("./flush");
51
+ Object.defineProperty(exports, "flush", { enumerable: true, get: function () { return flush_1.flush; } });
60
52
  var help_1 = require("./help");
61
53
  Object.defineProperty(exports, "CommandHelp", { enumerable: true, get: function () { return help_1.CommandHelp; } });
62
54
  Object.defineProperty(exports, "Help", { enumerable: true, get: function () { return help_1.Help; } });
@@ -74,3 +66,5 @@ Object.defineProperty(exports, "settings", { enumerable: true, get: function ()
74
66
  var ids_1 = require("./util/ids");
75
67
  Object.defineProperty(exports, "toConfiguredId", { enumerable: true, get: function () { return ids_1.toConfiguredId; } });
76
68
  Object.defineProperty(exports, "toStandardizedId", { enumerable: true, get: function () { return ids_1.toStandardizedId; } });
69
+ var ux_1 = require("./ux");
70
+ Object.defineProperty(exports, "ux", { enumerable: true, get: function () { return ux_1.methods; } });
@@ -126,6 +126,7 @@ export interface Config {
126
126
  readonly theme?: Theme;
127
127
  topicSeparator: ' ' | ':';
128
128
  readonly topics: Topic[];
129
+ readonly updateConfig: NonNullable<PJSON.CLI['oclif']['update']>;
129
130
  /**
130
131
  * user agent to use for http calls
131
132
  *
@@ -148,7 +148,7 @@ export declare namespace PJSON {
148
148
  subtopics?: Plugin['oclif']['topics'];
149
149
  };
150
150
  };
151
- update: {
151
+ update?: {
152
152
  autoupdate?: {
153
153
  debounce?: number;
154
154
  rollout?: number;
@@ -1,21 +1,32 @@
1
- export declare const STANDARD_CHALK: readonly ["white", "black", "blue", "yellow", "green", "red", "magenta", "cyan", "gray", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright", "bgBlack", "bgRed", "bgGreen", "bgYellow", "bgBlue", "bgMagenta", "bgCyan", "bgWhite", "bgGray", "bgBlackBright", "bgRedBright", "bgGreenBright", "bgYellowBright", "bgBlueBright", "bgMagentaBright", "bgCyanBright", "bgWhiteBright", "bold", "underline", "dim", "italic", "strikethrough"];
2
- export type StandardChalk = (typeof STANDARD_CHALK)[number];
3
- export declare const THEME_KEYS: readonly ["alias", "bin", "command", "commandSummary", "dollarSign", "flag", "flagDefaultValue", "flagOptions", "flagRequired", "flagSeparator", "sectionDescription", "sectionHeader", "topic", "version"];
4
- export type ThemeKey = (typeof THEME_KEYS)[number];
1
+ export declare const STANDARD_ANSI: readonly ["white", "black", "blue", "yellow", "green", "red", "magenta", "cyan", "gray", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright", "bgBlack", "bgRed", "bgGreen", "bgYellow", "bgBlue", "bgMagenta", "bgCyan", "bgWhite", "bgGray", "bgBlackBright", "bgRedBright", "bgGreenBright", "bgYellowBright", "bgBlueBright", "bgMagentaBright", "bgCyanBright", "bgWhiteBright", "bold", "underline", "dim", "italic", "strikethrough"];
2
+ export type StandardAnsi = (typeof STANDARD_ANSI)[number];
3
+ export type JsonTheme = {
4
+ brace?: string | StandardAnsi;
5
+ bracket?: string | StandardAnsi;
6
+ colon?: string | StandardAnsi;
7
+ comma?: string | StandardAnsi;
8
+ key?: string | StandardAnsi;
9
+ string?: string | StandardAnsi;
10
+ number?: string | StandardAnsi;
11
+ boolean?: string | StandardAnsi;
12
+ null?: string | StandardAnsi;
13
+ };
5
14
  export type Theme = {
6
- [key: string | ThemeKey]: string | StandardChalk | undefined;
7
- alias?: string | StandardChalk;
8
- bin?: string | StandardChalk;
9
- command?: string | StandardChalk;
10
- commandSummary?: string | StandardChalk;
11
- dollarSign?: string | StandardChalk;
12
- flag?: string | StandardChalk;
13
- flagDefaultValue?: string | StandardChalk;
14
- flagOptions?: string | StandardChalk;
15
- flagRequired?: string | StandardChalk;
16
- flagSeparator?: string | StandardChalk;
17
- sectionDescription?: string | StandardChalk;
18
- sectionHeader?: string | StandardChalk;
19
- topic?: string | StandardChalk;
20
- version?: string | StandardChalk;
15
+ [key: string]: string | StandardAnsi | Theme | undefined;
16
+ alias?: string | StandardAnsi;
17
+ bin?: string | StandardAnsi;
18
+ command?: string | StandardAnsi;
19
+ commandSummary?: string | StandardAnsi;
20
+ dollarSign?: string | StandardAnsi;
21
+ flag?: string | StandardAnsi;
22
+ flagDefaultValue?: string | StandardAnsi;
23
+ flagOptions?: string | StandardAnsi;
24
+ flagRequired?: string | StandardAnsi;
25
+ flagSeparator?: string | StandardAnsi;
26
+ json?: JsonTheme;
27
+ sectionDescription?: string | StandardAnsi;
28
+ sectionHeader?: string | StandardAnsi;
29
+ spinner?: string | StandardAnsi;
30
+ topic?: string | StandardAnsi;
31
+ version?: string | StandardAnsi;
21
32
  };
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.THEME_KEYS = exports.STANDARD_CHALK = void 0;
4
- // chalk doesn't export a list of standard colors, so we have to supply our own
5
- exports.STANDARD_CHALK = [
3
+ exports.STANDARD_ANSI = void 0;
4
+ exports.STANDARD_ANSI = [
6
5
  'white',
7
6
  'black',
8
7
  'blue',
@@ -43,19 +42,3 @@ exports.STANDARD_CHALK = [
43
42
  'italic',
44
43
  'strikethrough',
45
44
  ];
46
- exports.THEME_KEYS = [
47
- 'alias',
48
- 'bin',
49
- 'command',
50
- 'commandSummary',
51
- 'dollarSign',
52
- 'flag',
53
- 'flagDefaultValue',
54
- 'flagOptions',
55
- 'flagRequired',
56
- 'flagSeparator',
57
- 'sectionDescription',
58
- 'sectionHeader',
59
- 'topic',
60
- 'version',
61
- ];
package/lib/main.js CHANGED
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.run = exports.versionAddition = exports.helpAddition = void 0;
7
7
  const node_url_1 = require("node:url");
8
8
  const cache_1 = __importDefault(require("./cache"));
9
- const cli_ux_1 = require("./cli-ux");
10
9
  const config_1 = require("./config");
11
10
  const help_1 = require("./help");
12
11
  const performance_1 = require("./performance");
13
12
  const symbols_1 = require("./symbols");
13
+ const ux_1 = __importDefault(require("./ux"));
14
14
  const debug = require('debug')('oclif:main');
15
15
  const helpAddition = (argv, config) => {
16
16
  if (argv.length === 0 && !config.isSingleCommandCLI)
@@ -67,7 +67,7 @@ async function run(argv, options) {
67
67
  await config.runHook('init', { argv: argvSlice, id });
68
68
  // display version if applicable
69
69
  if ((0, exports.versionAddition)(argv, config)) {
70
- cli_ux_1.ux.log(config.userAgent);
70
+ ux_1.default.stdout(config.userAgent);
71
71
  await collectPerf();
72
72
  return;
73
73
  }
@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FailedFlagValidationError = exports.ArgInvalidOptionError = exports.FlagInvalidOptionError = exports.NonExistentFlagsError = exports.UnexpectedArgsError = exports.RequiredArgsError = exports.InvalidArgsSpecError = exports.CLIParseError = exports.CLIError = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
7
+ const ansis_1 = __importDefault(require("ansis"));
8
8
  const cache_1 = __importDefault(require("../cache"));
9
- const list_1 = require("../cli-ux/list");
10
9
  const errors_1 = require("../errors");
11
10
  const util_1 = require("../util/util");
11
+ const list_1 = __importDefault(require("../ux/list"));
12
12
  var errors_2 = require("../errors");
13
13
  Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return errors_2.CLIError; } });
14
14
  class CLIParseError extends errors_1.CLIError {
@@ -27,7 +27,7 @@ class InvalidArgsSpecError extends CLIParseError {
27
27
  let message = 'Invalid argument spec';
28
28
  const namedArgs = Object.values(args).filter((a) => a.name);
29
29
  if (namedArgs.length > 0) {
30
- const list = (0, list_1.renderList)(namedArgs.map((a) => [`${a.name} (${a.required ? 'required' : 'optional'})`, a.description]));
30
+ const list = (0, list_1.default)(namedArgs.map((a) => [`${a.name} (${a.required ? 'required' : 'optional'})`, a.description]));
31
31
  message += `:\n${list}`;
32
32
  }
33
33
  super({ exit: cache_1.default.getInstance().get('exitCodes')?.invalidArgsSpec ?? exit, message, parse });
@@ -41,7 +41,7 @@ class RequiredArgsError extends CLIParseError {
41
41
  let message = `Missing ${args.length} required arg${args.length === 1 ? '' : 's'}`;
42
42
  const namedArgs = args.filter((a) => a.name);
43
43
  if (namedArgs.length > 0) {
44
- const list = (0, list_1.renderList)(namedArgs.map((a) => {
44
+ const list = (0, list_1.default)(namedArgs.map((a) => {
45
45
  const description = a.options ? `(${a.options.join('|')}) ${a.description}` : a.description;
46
46
  return [a.name, description];
47
47
  }));
@@ -97,7 +97,7 @@ class FailedFlagValidationError extends CLIParseError {
97
97
  const reasons = failed.map((r) => r.reason);
98
98
  const deduped = (0, util_1.uniq)(reasons);
99
99
  const errString = deduped.length === 1 ? 'error' : 'errors';
100
- const message = `The following ${errString} occurred:\n ${chalk_1.default.dim(deduped.join('\n '))}`;
100
+ const message = `The following ${errString} occurred:\n ${ansis_1.default.dim(deduped.join('\n '))}`;
101
101
  super({ exit: cache_1.default.getInstance().get('exitCodes')?.failedFlagValidation ?? exit, message, parse });
102
102
  }
103
103
  }
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.flagUsages = exports.flagUsage = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
7
+ const ansis_1 = __importDefault(require("ansis"));
8
8
  const util_1 = require("../util/util");
9
9
  function flagUsage(flag, options = {}) {
10
10
  const label = [];
@@ -21,7 +21,7 @@ function flagUsage(flag, options = {}) {
21
21
  let description = flag.summary || flag.description || '';
22
22
  if (options.displayRequired && flag.required)
23
23
  description = `(required) ${description}`;
24
- description = description ? chalk_1.default.dim(description) : undefined;
24
+ description = description ? ansis_1.default.dim(description) : undefined;
25
25
  return [` ${label.join(',').trim()}${usage}`, description];
26
26
  }
27
27
  exports.flagUsage = flagUsage;
@@ -46,7 +46,7 @@ async function readTSConfig(root, tsconfigName = 'tsconfig.json') {
46
46
  catch { }
47
47
  }
48
48
  if (!typescript) {
49
- (0, warn_1.memoizedWarn)('Could not find typescript. Please ensure that typescript is a devDependency. Falling back to compiled source.');
49
+ (0, warn_1.warn)('Could not find typescript. Please ensure that typescript is a devDependency. Falling back to compiled source.');
50
50
  return;
51
51
  }
52
52
  const read = async (path) => {
@@ -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,28 @@
1
+ type Options = {
2
+ pretty?: boolean;
3
+ theme?: Record<string, string>;
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,64 @@
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 declare const methods: {
9
+ action: Simple | Spinner;
10
+ /**
11
+ * Add color to text.
12
+ * @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`)
13
+ * @param text string to colorize
14
+ * @returns colorized string
15
+ */
16
+ colorize: typeof colorize;
17
+ /**
18
+ * Add color to JSON.
19
+ *
20
+ * options
21
+ * pretty: set to true to pretty print the JSON (defaults to true)
22
+ * 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).
23
+ *
24
+ * Available theme keys:
25
+ * - brace
26
+ * - bracket
27
+ * - colon
28
+ * - comma
29
+ * - key
30
+ * - string
31
+ * - number
32
+ * - boolean
33
+ * - null
34
+ */
35
+ colorizeJson: typeof colorizeJson;
36
+ /**
37
+ * Throw an error.
38
+ *
39
+ * If `exit` option is `false`, the error will be logged to stderr but not exit the process.
40
+ * If `exit` is set to a number, the process will exit with that code.
41
+ */
42
+ error: typeof error;
43
+ /**
44
+ * Exit the process with provided exit code (defaults to 0).
45
+ */
46
+ exit: typeof exit;
47
+ /**
48
+ * Log a formatted string to stderr.
49
+ *
50
+ * See node's util.format() for formatting options.
51
+ */
52
+ stderr: (str: string | string[] | undefined, ...args: string[]) => void;
53
+ /**
54
+ * Log a formatted string to stdout.
55
+ *
56
+ * See node's util.format() for formatting options.
57
+ */
58
+ stdout: (str: string | string[] | undefined, ...args: string[]) => void;
59
+ /**
60
+ * Prints a pretty warning message to stderr.
61
+ */
62
+ warn: typeof warn;
63
+ };
64
+ export default methods;