@salesforce/sf-plugins-core 1.1.0 → 1.2.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/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [1.2.0](https://github.com/salesforcecli/sf-plugins-core/compare/v1.1.0...v1.2.0) (2022-01-27)
6
+
7
+ ### Features
8
+
9
+ - expose ux methods in SfCommand ([8e58a93](https://github.com/salesforcecli/sf-plugins-core/commit/8e58a93a942d5a0305a77a82e938f778c59fcd16))
10
+
5
11
  ## [1.1.0](https://github.com/salesforcecli/sf-plugins-core/compare/v1.0.5...v1.1.0) (2022-01-03)
6
12
 
7
13
  ### Features
package/README.md CHANGED
@@ -2,4 +2,44 @@
2
2
 
3
3
  # Description
4
4
 
5
- Utilities for writing [sf](https://github.com/salesforcecli/cli) plugins.
5
+ The @salesforce/sf-pluins-core provides utilities for writing [sf](https://github.com/salesforcecli/cli) plugins.
6
+
7
+ ## SfCommand Abstract Class
8
+
9
+ The SfCommand abstract class extends [@oclif/core's Command class](https://github.com/oclif/core/blob/main/src/command.ts) for examples of how to build a definition.
10
+ ) class and adds useful extensions to ease the development of commands for use in the Salesforce Unified CLI.
11
+
12
+ - SfCommand takes a generic type that defines the success JSON result
13
+ - Enable the json flag support by default
14
+ - Provides functions that help place success messages, warnings and errors into the correct location in JSON results
15
+ - Enables additional help sections to the standard oclif command help output
16
+ - Provides access to the [cli-ux cli actions](https://github.com/oclif/cli-ux#cliaction) via the public property `spinner` in SfCommand. This avoids having to import that interface from cli-ux.
17
+
18
+ ## Sf Hooks
19
+
20
+ Interface that defines the well known Unified CLI command hooks.
21
+ SfHooks takes advantage of the [oclif hooks framework](https://oclif.io/docs/hooks), which provides a set of predefined events and the provides ability to define your own.
22
+
23
+ A hook has a name, say `sf:deploy` and to participate in the hook's run call, one creates a hook consumer, that registers itself using the name `sf:deploy`.
24
+ There can be more than one hook registered with the same name and when the hook is "run", oclif hook will run each registered hook consumer, collect all results and return those results to the caller.
25
+
26
+ - See [oclif hooks API docs](https://oclif.io/docs/hooks.ts) for a general description of hooks.
27
+ - See [SfHooks](src/hooks.ts) for current hook definitions available in Unified CLI.
28
+ - See Command [Deploy](https://github.com/salesforcecli/plugin-deploy-retrieve/blob/main/src/commands/deploy.ts) for and example of how to run a hook (search for [SfHook](https://github.com/salesforcecli/plugin-deploy-retrieve/blob/main/src/commands/deploy.ts).run in linked file).
29
+ - See [@salesforce/plugin-deploy-retrieve-metadataA#src/hooks/deploy.ts](https://github.com/salesforcecli/plugin-deploy-retrieve-metadata/blob/main/src/hooks/deploy.ts) as an example implementation of a hook consumer.
30
+
31
+ ## Deployer Interface
32
+
33
+ Interface for deploying Deployables. See [@salesforce/plugin-deploy-retrieve-metadata#src/utils/metadataDeployer.ts](https://github.com/salesforcecli/plugin-deploy-retrieve-metadata/blob/main/src/utils/metadataDeployer.ts) as an example implementation.
34
+
35
+ ## Deauthorizer Abstract Class
36
+
37
+ The Deauthorizer is an abstract class that is used to implement a concrete implementations of deauthorizing an environment.
38
+
39
+ ## Prompter Class
40
+
41
+ A general purpose class that prompts a user for information. See [inquirer NPM Module](https://www.npmjs.com/package/inquirer) for more information.
42
+
43
+ ## Flags
44
+
45
+ Flags is a convenience reference to [@oclif/core#Flags](https://github.com/oclif/core/blob/main/src/flags.ts)
@@ -1,4 +1,8 @@
1
1
  import { JsonMap } from '@salesforce/ts-types';
2
+ /**
3
+ * The Deauthorizer is an abstract class that is used to implement a concrete implementations
4
+ * of deauthorizing an environment.
5
+ */
2
6
  export declare abstract class Deauthorizer<T = JsonMap> {
3
7
  removeAll(): Promise<Deauthorizer.Result>;
4
8
  /**
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2020, salesforce.com, inc.
3
+ * Copyright (c) 2022, salesforce.com, inc.
4
4
  * All rights reserved.
5
5
  * Licensed under the BSD 3-Clause license.
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.Deauthorizer = void 0;
10
+ /**
11
+ * The Deauthorizer is an abstract class that is used to implement a concrete implementations
12
+ * of deauthorizing an environment.
13
+ */
10
14
  class Deauthorizer {
11
15
  async removeAll() {
12
16
  const result = {
package/lib/deployer.d.ts CHANGED
@@ -9,12 +9,12 @@ export declare abstract class Deployable {
9
9
  abstract getParent(): Deployer;
10
10
  }
11
11
  /**
12
- * Interface for deploying Salesforce Org metadata.
12
+ * Interface for deploying Deployables.
13
13
  */
14
14
  export declare abstract class Deployer extends EventEmitter {
15
15
  /**
16
16
  * Deployables are individual pieces that can be deployed on their own. For example,
17
- * each pacakge in a salesforce project is considered a deployable that can be deployed
17
+ * each package in a salesforce project is considered a deployable that can be deployed
18
18
  * on its own.
19
19
  */
20
20
  deployables: Deployable[];
package/lib/deployer.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2021, salesforce.com, inc.
3
+ * Copyright (c) 2022, salesforce.com, inc.
4
4
  * All rights reserved.
5
5
  * Licensed under the BSD 3-Clause license.
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
@@ -8,24 +8,24 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.Deployer = exports.Deployable = void 0;
10
10
  const events_1 = require("events");
11
- const cli_ux_1 = require("cli-ux");
12
- const prompter_1 = require("./prompter");
11
+ const core_1 = require("@oclif/core");
12
+ const ux_1 = require("./ux");
13
13
  class Deployable {
14
14
  }
15
15
  exports.Deployable = Deployable;
16
16
  /**
17
- * Interface for deploying Salesforce Org metadata.
17
+ * Interface for deploying Deployables.
18
18
  */
19
19
  class Deployer extends events_1.EventEmitter {
20
20
  constructor() {
21
21
  super(...arguments);
22
22
  /**
23
23
  * Deployables are individual pieces that can be deployed on their own. For example,
24
- * each pacakge in a salesforce project is considered a deployable that can be deployed
24
+ * each package in a salesforce project is considered a deployable that can be deployed
25
25
  * on its own.
26
26
  */
27
27
  this.deployables = [];
28
- this.prompter = new prompter_1.Prompter();
28
+ this.prompter = new ux_1.Prompter();
29
29
  }
30
30
  /**
31
31
  * Method for displaying deploy progress to the user
@@ -36,7 +36,7 @@ class Deployer extends events_1.EventEmitter {
36
36
  * Log messages to the console
37
37
  */
38
38
  log(msg, ...args) {
39
- cli_ux_1.default.log(msg, ...args);
39
+ core_1.CliUx.ux.log(msg, ...args);
40
40
  }
41
41
  /**
42
42
  * Prompt user for additional information
package/lib/exported.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { generateTableChoices, toHelpSection } from './util';
1
+ export { toHelpSection } from './util';
2
2
  export { Deployable, Deployer } from './deployer';
3
3
  export { Deauthorizer } from './deauthorizer';
4
- export { Prompter } from './prompter';
4
+ export { Progress, Prompter, generateTableChoices } from './ux';
5
5
  export { SfHook } from './hooks';
6
6
  export * from './types';
7
7
  export { SfCommand, SfCommandInterface } from './sfCommand';
package/lib/exported.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2021, salesforce.com, inc.
3
+ * Copyright (c) 2022, salesforce.com, inc.
4
4
  * All rights reserved.
5
5
  * Licensed under the BSD 3-Clause license.
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
@@ -16,17 +16,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.Flags = exports.SfCommand = exports.SfHook = exports.Prompter = exports.Deauthorizer = exports.Deployer = exports.Deployable = exports.toHelpSection = exports.generateTableChoices = void 0;
19
+ exports.Flags = exports.SfCommand = exports.SfHook = exports.generateTableChoices = exports.Prompter = exports.Progress = exports.Deauthorizer = exports.Deployer = exports.Deployable = exports.toHelpSection = void 0;
20
20
  var util_1 = require("./util");
21
- Object.defineProperty(exports, "generateTableChoices", { enumerable: true, get: function () { return util_1.generateTableChoices; } });
22
21
  Object.defineProperty(exports, "toHelpSection", { enumerable: true, get: function () { return util_1.toHelpSection; } });
23
22
  var deployer_1 = require("./deployer");
24
23
  Object.defineProperty(exports, "Deployable", { enumerable: true, get: function () { return deployer_1.Deployable; } });
25
24
  Object.defineProperty(exports, "Deployer", { enumerable: true, get: function () { return deployer_1.Deployer; } });
26
25
  var deauthorizer_1 = require("./deauthorizer");
27
26
  Object.defineProperty(exports, "Deauthorizer", { enumerable: true, get: function () { return deauthorizer_1.Deauthorizer; } });
28
- var prompter_1 = require("./prompter");
29
- Object.defineProperty(exports, "Prompter", { enumerable: true, get: function () { return prompter_1.Prompter; } });
27
+ var ux_1 = require("./ux");
28
+ Object.defineProperty(exports, "Progress", { enumerable: true, get: function () { return ux_1.Progress; } });
29
+ Object.defineProperty(exports, "Prompter", { enumerable: true, get: function () { return ux_1.Prompter; } });
30
+ Object.defineProperty(exports, "generateTableChoices", { enumerable: true, get: function () { return ux_1.generateTableChoices; } });
30
31
  var hooks_1 = require("./hooks");
31
32
  Object.defineProperty(exports, "SfHook", { enumerable: true, get: function () { return hooks_1.SfHook; } });
32
33
  __exportStar(require("./types"), exports);
package/lib/hooks.d.ts CHANGED
@@ -3,6 +3,9 @@ import { Hook, Hooks } from '@oclif/core/lib/interfaces/hooks';
3
3
  import { Deployer } from './deployer';
4
4
  import { EnvList, EnvDisplay, JsonObject, Deploy, Login, Logout } from './types';
5
5
  import { Deauthorizer } from './deauthorizer';
6
+ /**
7
+ * Interface that defines the well known Unified CLI command hooks.
8
+ */
6
9
  interface SfHooks<T = unknown> extends Hooks {
7
10
  'sf:env:list': EnvList.HookMeta<T & JsonObject>;
8
11
  'sf:env:display': EnvDisplay.HookMeta<T & JsonObject>;
@@ -11,6 +14,9 @@ interface SfHooks<T = unknown> extends Hooks {
11
14
  'sf:logout': Logout.HookMeta<T & Deauthorizer>;
12
15
  }
13
16
  declare type GenericHook<T extends keyof SfHooks, P> = Hook<T, SfHooks<P>>;
17
+ /**
18
+ * Class that provides a static method to run a well known hook.
19
+ */
14
20
  export declare class SfHook {
15
21
  static run<T extends keyof SfHooks>(config: Config, hookName: T, options?: SfHooks[T]['options']): Promise<Hook.Result<SfHooks[T]['return']>>;
16
22
  }
package/lib/hooks.js CHANGED
@@ -1,21 +1,24 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2021, salesforce.com, inc.
3
+ * Copyright (c) 2022, salesforce.com, inc.
4
4
  * All rights reserved.
5
5
  * Licensed under the BSD 3-Clause license.
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.SfHook = void 0;
10
- const cli_ux_1 = require("cli-ux");
11
10
  const kit_1 = require("@salesforce/kit");
11
+ const core_1 = require("@oclif/core");
12
+ /**
13
+ * Class that provides a static method to run a well known hook.
14
+ */
12
15
  class SfHook {
13
16
  static async run(config, hookName, options = {}) {
14
17
  const timeout = kit_1.Duration.milliseconds(kit_1.env.getNumber('SF_HOOK_TIMEOUT_MS') || 5000);
15
18
  const results = await config.runHook(hookName, options, timeout.milliseconds);
16
19
  results.failures.forEach((failure) => {
17
- cli_ux_1.cli.debug(`Failed to run ${hookName} hook for ${failure.plugin.name}`);
18
- cli_ux_1.cli.debug(failure.error.toString());
20
+ core_1.CliUx.ux.debug(`Failed to run ${hookName} hook for ${failure.plugin.name}`);
21
+ core_1.CliUx.ux.debug(failure.error.toString());
19
22
  });
20
23
  return results;
21
24
  }
@@ -1,5 +1,6 @@
1
- import { Command, Config, HelpSection, Interfaces } from '@oclif/core';
2
- import { Spinner } from './ux';
1
+ import { CliUx, Command, Config, HelpSection, Interfaces } from '@oclif/core';
2
+ import { AnyJson } from '@salesforce/ts-types';
3
+ import { Progress, Prompter, Spinner, Ux } from './ux';
3
4
  export interface SfCommandInterface extends Interfaces.Command {
4
5
  configurationVariablesSection?: HelpSection;
5
6
  envVariablesSection?: HelpSection;
@@ -18,8 +19,12 @@ export declare abstract class SfCommand<T> extends Command {
18
19
  static configurationVariablesSection?: HelpSection;
19
20
  static envVariablesSection?: HelpSection;
20
21
  static errorCodes?: HelpSection;
22
+ static tableFlags: typeof CliUx.Table.table.flags;
21
23
  spinner: Spinner;
24
+ progress: Progress;
22
25
  private warnings;
26
+ private ux;
27
+ private prompter;
23
28
  constructor(argv: string[], config: Config);
24
29
  /**
25
30
  * Log warning to users. If --json is enabled, then the warning
@@ -31,6 +36,36 @@ export declare abstract class SfCommand<T> extends Command {
31
36
  * logging to the console.
32
37
  */
33
38
  logSensitive(msg?: string): void;
39
+ /**
40
+ * Display a table on the console. Will automatically be suppressed when --json flag is present.
41
+ */
42
+ table<R extends Ux.Table.Data>(data: R[], columns: Ux.Table.Columns<R>, options?: Ux.Table.Options): void;
43
+ /**
44
+ * Log a stylized url to the console. Will automatically be suppressed when --json flag is present.
45
+ */
46
+ url(text: string, uri: string, params?: {}): void;
47
+ /**
48
+ * Log stylized JSON to the console. Will automatically be suppressed when --json flag is present.
49
+ */
50
+ styledJSON(obj: AnyJson): void;
51
+ /**
52
+ * Log stylized object to the console. Will automatically be suppressed when --json flag is present.
53
+ */
54
+ styledObject(obj: AnyJson): void;
55
+ /**
56
+ * Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
57
+ *
58
+ * This will NOT be automatically suppressed when the --json flag is present since we assume
59
+ * that any command that prompts the user for required information will not also support the --json flag.
60
+ *
61
+ * If you need to conditionally suppress prompts to support json output, then do the following:
62
+ *
63
+ * @example
64
+ * if (!this.jsonEnabled()) {
65
+ * await this.prompt();
66
+ * }
67
+ */
68
+ prompt<R = Prompter.Answers>(questions: Prompter.Questions<R>, initialAnswers?: Partial<R>): Promise<R>;
34
69
  /**
35
70
  * Wrap the command result into the standardized JSON structure.
36
71
  */
package/lib/sfCommand.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SfCommand = void 0;
4
4
  /*
5
- * Copyright (c) 2021, salesforce.com, inc.
5
+ * Copyright (c) 2022, salesforce.com, inc.
6
6
  * All rights reserved.
7
7
  * Licensed under the BSD 3-Clause license.
8
8
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
@@ -24,7 +24,11 @@ class SfCommand extends core_1.Command {
24
24
  constructor(argv, config) {
25
25
  super(argv, config);
26
26
  this.warnings = [];
27
- this.spinner = new ux_1.Spinner(this.jsonEnabled());
27
+ const outputEnabled = !this.jsonEnabled();
28
+ this.spinner = new ux_1.Spinner(outputEnabled);
29
+ this.progress = new ux_1.Progress(outputEnabled);
30
+ this.ux = new ux_1.Ux(outputEnabled);
31
+ this.prompter = new ux_1.Prompter();
28
32
  }
29
33
  /**
30
34
  * Log warning to users. If --json is enabled, then the warning
@@ -43,6 +47,46 @@ class SfCommand extends core_1.Command {
43
47
  this.warn(messages.getMessage('warning.security'));
44
48
  this.log(msg);
45
49
  }
50
+ /**
51
+ * Display a table on the console. Will automatically be suppressed when --json flag is present.
52
+ */
53
+ table(data, columns, options) {
54
+ this.ux.table(data, columns, options);
55
+ }
56
+ /**
57
+ * Log a stylized url to the console. Will automatically be suppressed when --json flag is present.
58
+ */
59
+ url(text, uri, params = {}) {
60
+ this.ux.url(text, uri, params);
61
+ }
62
+ /**
63
+ * Log stylized JSON to the console. Will automatically be suppressed when --json flag is present.
64
+ */
65
+ styledJSON(obj) {
66
+ this.ux.styledJSON(obj);
67
+ }
68
+ /**
69
+ * Log stylized object to the console. Will automatically be suppressed when --json flag is present.
70
+ */
71
+ styledObject(obj) {
72
+ this.ux.styledObject(obj);
73
+ }
74
+ /**
75
+ * Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
76
+ *
77
+ * This will NOT be automatically suppressed when the --json flag is present since we assume
78
+ * that any command that prompts the user for required information will not also support the --json flag.
79
+ *
80
+ * If you need to conditionally suppress prompts to support json output, then do the following:
81
+ *
82
+ * @example
83
+ * if (!this.jsonEnabled()) {
84
+ * await this.prompt();
85
+ * }
86
+ */
87
+ async prompt(questions, initialAnswers) {
88
+ return this.prompter.prompt(questions, initialAnswers);
89
+ }
46
90
  /**
47
91
  * Wrap the command result into the standardized JSON structure.
48
92
  */
@@ -70,4 +114,5 @@ class SfCommand extends core_1.Command {
70
114
  }
71
115
  exports.SfCommand = SfCommand;
72
116
  SfCommand.enableJsonFlag = true;
117
+ SfCommand.tableFlags = core_1.CliUx.ux.table.flags;
73
118
  //# sourceMappingURL=sfCommand.js.map
@@ -46,8 +46,8 @@ export declare namespace EnvDisplay {
46
46
  /**
47
47
  * By default `sf env list` will render a table with all the data provided by the hook.
48
48
  * The columns of the table are derived from the keys of the provided data. These column
49
- * headers are Title Cased for readability. To overwrite a column name specifiy it the `keys`
50
- * property.
49
+ * headers are Title Cased for readability. To overwrite a column name specify it with
50
+ * the `keys` property.
51
51
  *
52
52
  * @example
53
53
  * {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2020, salesforce.com, inc.
3
+ * Copyright (c) 2022, salesforce.com, inc.
4
4
  * All rights reserved.
5
5
  * Licensed under the BSD 3-Clause license.
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
@@ -10,8 +10,8 @@ exports.EnvList = void 0;
10
10
  /**
11
11
  * By default `sf env list` will render a table with all the data provided by the hook.
12
12
  * The columns of the table are derived from the keys of the provided data. These column
13
- * headers are Title Cased for readability. To overwrite a column name specifiy it the `keys`
14
- * property.
13
+ * headers are Title Cased for readability. To overwrite a column name specify it with
14
+ * the `keys` property.
15
15
  *
16
16
  * @example
17
17
  * {
package/lib/util.d.ts CHANGED
@@ -1,19 +1,5 @@
1
- import { ChoiceBase } from 'inquirer';
2
- import { Dictionary, Nullable } from '@salesforce/ts-types';
3
1
  import { HelpSection } from '@oclif/core';
4
- import { OrgConfigProperties } from '@salesforce/core';
5
- import { SfdxPropertyKeys } from '@salesforce/core';
6
- import { EnvironmentVariable } from '@salesforce/core';
7
- /**
8
- * Generate a formatted table for list and checkbox prompts
9
- *
10
- * Each option should contain the same keys as specified in columns.
11
- * For example,
12
- * const columns = { name: 'Name', type: 'Type', path: 'Path' };
13
- * const options = [{ name: 'foo', type: 'org', path: '/path/to/foo/' }];
14
- * generateTableChoices(columns, options);
15
- */
16
- export declare function generateTableChoices<T>(columns: Dictionary<string>, choices: Array<Dictionary<Nullable<string> | T>>, padForCheckbox?: boolean): ChoiceBase[];
2
+ import { OrgConfigProperties, SfdxPropertyKeys, EnvironmentVariable } from '@salesforce/core';
17
3
  /**
18
4
  * Function to build a help section for command help.
19
5
  * Takes a string to be used as section header text and an array of enums
package/lib/util.js CHANGED
@@ -1,47 +1,13 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2021, salesforce.com, inc.
3
+ * Copyright (c) 2022, salesforce.com, inc.
4
4
  * All rights reserved.
5
5
  * Licensed under the BSD 3-Clause license.
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.toHelpSection = exports.generateTableChoices = void 0;
10
- const inquirer_1 = require("inquirer");
11
- const ts_types_1 = require("@salesforce/ts-types");
9
+ exports.toHelpSection = void 0;
12
10
  const core_1 = require("@salesforce/core");
13
- const core_2 = require("@salesforce/core");
14
- const core_3 = require("@salesforce/core");
15
- /**
16
- * Generate a formatted table for list and checkbox prompts
17
- *
18
- * Each option should contain the same keys as specified in columns.
19
- * For example,
20
- * const columns = { name: 'Name', type: 'Type', path: 'Path' };
21
- * const options = [{ name: 'foo', type: 'org', path: '/path/to/foo/' }];
22
- * generateTableChoices(columns, options);
23
- */
24
- function generateTableChoices(columns, choices,
25
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
26
- padForCheckbox = true) {
27
- const columnEntries = Object.entries(columns);
28
- const columnLengths = columnEntries.map(([key, value]) => Math.max(ts_types_1.ensureString(value).length, ...choices.map((option) => ts_types_1.ensureString(option[key], `Type ${typeof option[key]} for ${key} in ${Object.keys(option).join(', ')}`)
29
- .length)) + 1);
30
- const choicesOptions = [
31
- new inquirer_1.Separator(`${padForCheckbox ? ' '.repeat(2) : ''}${columnEntries
32
- .map(([, value], index) => value === null || value === void 0 ? void 0 : value.padEnd(columnLengths[index], ' '))
33
- .join('')}`),
34
- ];
35
- for (const meta of choices) {
36
- const name = columnEntries
37
- .map(([key], index) => ts_types_1.ensureString(meta[key]).padEnd(columnLengths[index], ' '))
38
- .join('');
39
- const choice = { name, value: meta.value, short: ts_types_1.ensureString(meta.name) };
40
- choicesOptions.push(choice);
41
- }
42
- return choicesOptions;
43
- }
44
- exports.generateTableChoices = generateTableChoices;
45
11
  /**
46
12
  * Function to build a help section for command help.
47
13
  * Takes a string to be used as section header text and an array of enums
@@ -60,11 +26,11 @@ function toHelpSection(header, ...vars) {
60
26
  if (orgConfig) {
61
27
  return { name: orgConfig.key, description: orgConfig.description };
62
28
  }
63
- const sfdxProperty = core_2.SFDX_ALLOWED_PROPERTIES.find(({ key }) => key === v);
29
+ const sfdxProperty = core_1.SFDX_ALLOWED_PROPERTIES.find(({ key }) => key === v);
64
30
  if (sfdxProperty) {
65
31
  return { name: sfdxProperty.key.valueOf(), description: sfdxProperty.description };
66
32
  }
67
- const envVar = Object.entries(core_3.SUPPORTED_ENV_VARS).find(([k]) => k === v);
33
+ const envVar = Object.entries(core_1.SUPPORTED_ENV_VARS).find(([k]) => k === v);
68
34
  if (envVar) {
69
35
  const [eKey, data] = envVar;
70
36
  return { name: eKey, description: data.description };
@@ -0,0 +1,6 @@
1
+ import { AnyFunction } from '@salesforce/ts-types';
2
+ export declare class UxBase {
3
+ protected outputEnabled: boolean;
4
+ constructor(outputEnabled: boolean);
5
+ protected maybeNoop(fn: AnyFunction<unknown>): void;
6
+ }
package/lib/ux/base.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.UxBase = void 0;
10
+ class UxBase {
11
+ constructor(outputEnabled) {
12
+ this.outputEnabled = outputEnabled;
13
+ }
14
+ maybeNoop(fn) {
15
+ if (this.outputEnabled)
16
+ fn();
17
+ }
18
+ }
19
+ exports.UxBase = UxBase;
20
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1,5 @@
1
+ export { UxBase } from './base';
2
+ export { Ux } from './ux';
3
+ export { Progress } from './progress';
4
+ export { Prompter, generateTableChoices } from './prompter';
5
+ export { Spinner } from './spinner';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Spinner = exports.generateTableChoices = exports.Prompter = exports.Progress = exports.Ux = exports.UxBase = void 0;
10
+ var base_1 = require("./base");
11
+ Object.defineProperty(exports, "UxBase", { enumerable: true, get: function () { return base_1.UxBase; } });
12
+ var ux_1 = require("./ux");
13
+ Object.defineProperty(exports, "Ux", { enumerable: true, get: function () { return ux_1.Ux; } });
14
+ var progress_1 = require("./progress");
15
+ Object.defineProperty(exports, "Progress", { enumerable: true, get: function () { return progress_1.Progress; } });
16
+ var prompter_1 = require("./prompter");
17
+ Object.defineProperty(exports, "Prompter", { enumerable: true, get: function () { return prompter_1.Prompter; } });
18
+ Object.defineProperty(exports, "generateTableChoices", { enumerable: true, get: function () { return prompter_1.generateTableChoices; } });
19
+ var spinner_1 = require("./spinner");
20
+ Object.defineProperty(exports, "Spinner", { enumerable: true, get: function () { return spinner_1.Spinner; } });
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,48 @@
1
+ import { UxBase } from '.';
2
+ /**
3
+ * Class for display a progress bar to the console. Will automatically be suppressed if the --json flag is present.
4
+ */
5
+ export declare class Progress extends UxBase {
6
+ private static DEFAULT_OPTIONS;
7
+ private bar;
8
+ private total;
9
+ constructor(outputEnabled: boolean);
10
+ /**
11
+ * Set the total number of expected components.
12
+ */
13
+ setTotal(total: number): void;
14
+ /**
15
+ * Start the progress bar.
16
+ */
17
+ start(total: number, payload?: Progress.Payload, options?: Partial<Progress.Options>): void;
18
+ /**
19
+ * Update the progress bar.
20
+ */
21
+ update(num: number, payload?: {}): void;
22
+ /**
23
+ * Update the progress bar with the final number and stop it.
24
+ */
25
+ finish(payload?: {}): void;
26
+ /**
27
+ * Stop the progress bar.
28
+ */
29
+ stop(): void;
30
+ private _start;
31
+ }
32
+ export declare namespace Progress {
33
+ type Bar = {
34
+ start: (num: number, payload?: unknown) => void;
35
+ update: (num: number, payload?: unknown) => void;
36
+ updateTotal: (num: number) => void;
37
+ setTotal: (num: number) => void;
38
+ stop: () => void;
39
+ };
40
+ type Options = {
41
+ title: string;
42
+ format: string;
43
+ barCompleteChar: string;
44
+ barIncompleteChar: string;
45
+ linewrap: boolean;
46
+ };
47
+ type Payload = Record<string, unknown>;
48
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Progress = void 0;
10
+ const util = require("util");
11
+ const core_1 = require("@oclif/core");
12
+ const kit_1 = require("@salesforce/kit");
13
+ const _1 = require(".");
14
+ /**
15
+ * Class for display a progress bar to the console. Will automatically be suppressed if the --json flag is present.
16
+ */
17
+ class Progress extends _1.UxBase {
18
+ constructor(outputEnabled) {
19
+ super(outputEnabled);
20
+ }
21
+ /**
22
+ * Set the total number of expected components.
23
+ */
24
+ setTotal(total) {
25
+ this.total = total;
26
+ this.bar.setTotal(total);
27
+ }
28
+ /**
29
+ * Start the progress bar.
30
+ */
31
+ start(total, payload = {}, options = Progress.DEFAULT_OPTIONS) {
32
+ const opts = Object.assign(Progress.DEFAULT_OPTIONS, options);
33
+ opts.format = util.format(opts.format, opts.title);
34
+ this.bar = core_1.CliUx.ux.progress({
35
+ format: opts.format,
36
+ barCompleteChar: opts.barCompleteChar,
37
+ barIncompleteChar: opts.barIncompleteChar,
38
+ linewrap: opts.linewrap,
39
+ });
40
+ this.bar.setTotal(total);
41
+ // this.maybeNoop(() => startProgressBar(this.bar, total, payload));
42
+ this.maybeNoop(() => {
43
+ this._start(total, payload);
44
+ });
45
+ }
46
+ /**
47
+ * Update the progress bar.
48
+ */
49
+ update(num, payload = {}) {
50
+ this.bar.update(num, payload);
51
+ }
52
+ /**
53
+ * Update the progress bar with the final number and stop it.
54
+ */
55
+ finish(payload = {}) {
56
+ this.bar.update(this.total, payload);
57
+ this.bar.stop();
58
+ }
59
+ /**
60
+ * Stop the progress bar.
61
+ */
62
+ stop() {
63
+ this.bar.stop();
64
+ }
65
+ _start(total, payload = {}) {
66
+ const start = kit_1.once((bar, t, p = {}) => {
67
+ bar.start(t);
68
+ if (Object.keys(p).length) {
69
+ bar.update(0, p);
70
+ }
71
+ });
72
+ start(this.bar, total, payload);
73
+ }
74
+ }
75
+ exports.Progress = Progress;
76
+ Progress.DEFAULT_OPTIONS = {
77
+ title: 'PROGRESS',
78
+ format: '%s | {bar} | {value}/{total} Components',
79
+ barCompleteChar: '\u2588',
80
+ barIncompleteChar: '\u2591',
81
+ linewrap: true,
82
+ };
83
+ //# sourceMappingURL=progress.js.map
@@ -0,0 +1,22 @@
1
+ import { QuestionCollection, ChoiceBase } from 'inquirer';
2
+ import { Dictionary, Nullable } from '@salesforce/ts-types';
3
+ export declare class Prompter {
4
+ /**
5
+ * Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
6
+ */
7
+ prompt<T = Prompter.Answers>(questions: Prompter.Questions<T>, initialAnswers?: Partial<T>): Promise<T>;
8
+ }
9
+ export declare namespace Prompter {
10
+ type Answers<T = Record<string, unknown>> = T & Record<string, unknown>;
11
+ type Questions<T> = QuestionCollection<T>;
12
+ }
13
+ /**
14
+ * Generate a formatted table for list and checkbox prompts
15
+ *
16
+ * Each option should contain the same keys as specified in columns.
17
+ * For example,
18
+ * const columns = { name: 'Name', type: 'Type', path: 'Path' };
19
+ * const options = [{ name: 'foo', type: 'org', path: '/path/to/foo/' }];
20
+ * generateTableChoices(columns, options);
21
+ */
22
+ export declare function generateTableChoices<T>(columns: Dictionary<string>, choices: Array<Dictionary<Nullable<string> | T>>, padForCheckbox?: boolean): ChoiceBase[];
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.generateTableChoices = exports.Prompter = void 0;
10
+ const inquirer_1 = require("inquirer");
11
+ const ts_types_1 = require("@salesforce/ts-types");
12
+ class Prompter {
13
+ /**
14
+ * Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
15
+ */
16
+ async prompt(questions, initialAnswers) {
17
+ const answers = await inquirer_1.prompt(questions, initialAnswers);
18
+ return answers;
19
+ }
20
+ }
21
+ exports.Prompter = Prompter;
22
+ /**
23
+ * Generate a formatted table for list and checkbox prompts
24
+ *
25
+ * Each option should contain the same keys as specified in columns.
26
+ * For example,
27
+ * const columns = { name: 'Name', type: 'Type', path: 'Path' };
28
+ * const options = [{ name: 'foo', type: 'org', path: '/path/to/foo/' }];
29
+ * generateTableChoices(columns, options);
30
+ */
31
+ function generateTableChoices(columns, choices,
32
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
+ padForCheckbox = true) {
34
+ const columnEntries = Object.entries(columns);
35
+ const columnLengths = columnEntries.map(([key, value]) => Math.max(ts_types_1.ensureString(value).length, ...choices.map((option) => ts_types_1.ensureString(option[key], `Type ${typeof option[key]} for ${key} in ${Object.keys(option).join(', ')}`)
36
+ .length)) + 1);
37
+ const choicesOptions = [
38
+ new inquirer_1.Separator(`${padForCheckbox ? ' '.repeat(2) : ''}${columnEntries
39
+ .map(([, value], index) => value === null || value === void 0 ? void 0 : value.padEnd(columnLengths[index], ' '))
40
+ .join('')}`),
41
+ ];
42
+ for (const meta of choices) {
43
+ const name = columnEntries
44
+ .map(([key], index) => ts_types_1.ensureString(meta[key]).padEnd(columnLengths[index], ' '))
45
+ .join('');
46
+ const choice = { name, value: meta.value, short: ts_types_1.ensureString(meta.name) };
47
+ choicesOptions.push(choice);
48
+ }
49
+ return choicesOptions;
50
+ }
51
+ exports.generateTableChoices = generateTableChoices;
52
+ //# sourceMappingURL=prompter.js.map
@@ -1,10 +1,10 @@
1
+ import { UxBase } from '.';
1
2
  /**
2
- * This class is a light wrapper around cli.action that allows us to
3
+ * This class is a light wrapper around CliUx.ux.action that allows us to
3
4
  * automatically suppress any actions if `--json` flag is present.
4
5
  */
5
- export declare class Spinner {
6
- private jsonEnabled;
7
- constructor(jsonEnabled: boolean);
6
+ export declare class Spinner extends UxBase {
7
+ constructor(outputEnabled: boolean);
8
8
  /**
9
9
  * Start a spinner on the console.
10
10
  */
@@ -1,55 +1,52 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright (c) 2021, salesforce.com, inc.
3
+ * Copyright (c) 2022, salesforce.com, inc.
4
4
  * All rights reserved.
5
5
  * Licensed under the BSD 3-Clause license.
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.Spinner = void 0;
10
- const cli_ux_1 = require("cli-ux");
10
+ const core_1 = require("@oclif/core");
11
+ const _1 = require(".");
11
12
  /**
12
- * This class is a light wrapper around cli.action that allows us to
13
+ * This class is a light wrapper around CliUx.ux.action that allows us to
13
14
  * automatically suppress any actions if `--json` flag is present.
14
15
  */
15
- class Spinner {
16
- constructor(jsonEnabled) {
17
- this.jsonEnabled = jsonEnabled;
16
+ class Spinner extends _1.UxBase {
17
+ constructor(outputEnabled) {
18
+ super(outputEnabled);
18
19
  }
19
20
  /**
20
21
  * Start a spinner on the console.
21
22
  */
22
23
  start(action, status, opts) {
23
- if (!this.jsonEnabled)
24
- cli_ux_1.cli.action.start(action, status, opts);
24
+ this.maybeNoop(() => core_1.CliUx.ux.action.start(action, status, opts));
25
25
  }
26
26
  /**
27
27
  * Stop the spinner on the console.
28
28
  */
29
29
  stop(msg) {
30
- if (!this.jsonEnabled)
31
- cli_ux_1.cli.action.stop(msg);
30
+ this.maybeNoop(() => core_1.CliUx.ux.action.stop(msg));
32
31
  }
33
32
  /**
34
33
  * Set the status of the current spinner.
35
34
  */
36
35
  set status(status) {
37
- if (!this.jsonEnabled)
38
- cli_ux_1.cli.action.status = status;
36
+ core_1.CliUx.ux.action.status = status;
39
37
  }
40
38
  /**
41
39
  * Get the status of the current spinner.
42
40
  */
43
41
  get status() {
44
- return cli_ux_1.cli.action.status;
42
+ return core_1.CliUx.ux.action.status;
45
43
  }
46
44
  /**
47
45
  * Pause the spinner on the console.
48
46
  */
49
47
  pause(fn, icon) {
50
- if (!this.jsonEnabled)
51
- cli_ux_1.cli.action.pause(fn, icon);
48
+ this.maybeNoop(() => core_1.CliUx.ux.action.pause(fn, icon));
52
49
  }
53
50
  }
54
51
  exports.Spinner = Spinner;
55
- //# sourceMappingURL=ux.js.map
52
+ //# sourceMappingURL=spinner.js.map
package/lib/ux/ux.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { CliUx } from '@oclif/core';
2
+ import { AnyJson } from '@salesforce/ts-types';
3
+ import { UxBase } from './base';
4
+ export declare class Ux extends UxBase {
5
+ constructor(outputEnabled: boolean);
6
+ table<T extends Ux.Table.Data>(data: T[], columns: Ux.Table.Columns<T>, options?: Ux.Table.Options): void;
7
+ url(text: string, uri: string, params?: {}): void;
8
+ styledJSON(obj: AnyJson): void;
9
+ styledObject(obj: AnyJson): void;
10
+ }
11
+ export declare namespace Ux {
12
+ namespace Table {
13
+ type Data = Record<string, unknown>;
14
+ type Columns<T extends Data> = CliUx.Table.table.Columns<T>;
15
+ type Options = CliUx.Table.table.Options;
16
+ }
17
+ }
package/lib/ux/ux.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Ux = void 0;
10
+ const core_1 = require("@oclif/core");
11
+ const base_1 = require("./base");
12
+ class Ux extends base_1.UxBase {
13
+ constructor(outputEnabled) {
14
+ super(outputEnabled);
15
+ }
16
+ table(data, columns, options) {
17
+ this.maybeNoop(() => core_1.CliUx.ux.table(data, columns, options));
18
+ }
19
+ url(text, uri, params = {}) {
20
+ this.maybeNoop(() => core_1.CliUx.ux.url(text, uri, params));
21
+ }
22
+ styledJSON(obj) {
23
+ this.maybeNoop(() => core_1.CliUx.ux.styledJSON(obj));
24
+ }
25
+ styledObject(obj) {
26
+ this.maybeNoop(() => core_1.CliUx.ux.styledObject(obj));
27
+ }
28
+ }
29
+ exports.Ux = Ux;
30
+ //# sourceMappingURL=ux.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/sf-plugins-core",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Utils for writing deploy and retrieve plugins",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -32,11 +32,10 @@
32
32
  "/messages"
33
33
  ],
34
34
  "dependencies": {
35
- "@oclif/core": "^1.0.10",
36
- "@salesforce/core": "3.6.6",
35
+ "@oclif/core": "^1.2.0",
36
+ "@salesforce/core": "3.7.3",
37
37
  "@salesforce/kit": "^1.5.17",
38
38
  "@salesforce/ts-types": "^1.5.20",
39
- "cli-ux": "^6.0.6",
40
39
  "inquirer": "^8.2.0"
41
40
  },
42
41
  "devDependencies": {
@@ -62,7 +61,7 @@
62
61
  "nyc": "^15.1.0",
63
62
  "prettier": "^2.0.5",
64
63
  "pretty-quick": "^3.1.0",
65
- "shelljs": "0.8.1",
64
+ "shelljs": "0.8.5",
66
65
  "sinon": "10.0.0",
67
66
  "strip-ansi": "6.0.0",
68
67
  "ts-node": "^10.4.0",
package/lib/prompter.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { QuestionCollection } from 'inquirer';
2
- export declare class Prompter {
3
- /**
4
- * Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
5
- */
6
- prompt<T = Prompter.Answers>(questions: QuestionCollection<T>, initialAnswers?: Partial<T>): Promise<T>;
7
- }
8
- export declare namespace Prompter {
9
- type Answers<T = Record<string, unknown>> = T & Record<string, unknown>;
10
- }
package/lib/prompter.js DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2021, salesforce.com, inc.
4
- * All rights reserved.
5
- * Licensed under the BSD 3-Clause license.
6
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.Prompter = void 0;
10
- const inquirer_1 = require("inquirer");
11
- class Prompter {
12
- /**
13
- * Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
14
- */
15
- async prompt(questions, initialAnswers) {
16
- const answers = await inquirer_1.prompt(questions, initialAnswers);
17
- return answers;
18
- }
19
- }
20
- exports.Prompter = Prompter;
21
- //# sourceMappingURL=prompter.js.map