@salesforce/sf-plugins-core 1.4.0 → 1.5.1

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,20 @@
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.5.1](https://github.com/salesforcecli/sf-plugins-core/compare/v1.5.0...v1.5.1) (2022-03-07)
6
+
7
+ ## [1.5.0](https://github.com/salesforcecli/sf-plugins-core/compare/v1.4.1...v1.5.0) (2022-03-03)
8
+
9
+ ### Features
10
+
11
+ - friendly default help for org flags ([f4d55b3](https://github.com/salesforcecli/sf-plugins-core/commit/f4d55b30c08e988c0231b97acce8ba2bc9733a06))
12
+
13
+ ### [1.4.1](https://github.com/salesforcecli/sf-plugins-core/compare/v1.4.0...v1.4.1) (2022-03-02)
14
+
15
+ ### Bug Fixes
16
+
17
+ - make toHelpSection types more friendly ([add364b](https://github.com/salesforcecli/sf-plugins-core/commit/add364b6be532dae6fb49f62164dad486b186347))
18
+
5
19
  ## [1.4.0](https://github.com/salesforcecli/sf-plugins-core/compare/v1.3.0...v1.4.0) (2022-03-02)
6
20
 
7
21
  ### Features
package/lib/exported.js CHANGED
@@ -7,7 +7,11 @@
7
7
  */
8
8
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
9
  if (k2 === undefined) k2 = k;
10
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
11
15
  }) : (function(o, m, k, k2) {
12
16
  if (k2 === undefined) k2 = k;
13
17
  o[k2] = m[k];
@@ -58,6 +58,7 @@ exports.optionalOrgFlag = core_1.Flags.build({
58
58
  char: 'e',
59
59
  parse: async (input) => await maybeGetOrg(input),
60
60
  default: async () => await maybeGetOrg(),
61
+ defaultHelp: async () => { var _a; return (_a = (await maybeGetOrg(undefined))) === null || _a === void 0 ? void 0 : _a.getUsername(); },
61
62
  });
62
63
  /**
63
64
  * An required org, specified by username or alias
@@ -82,6 +83,7 @@ exports.requiredOrgFlag = core_1.Flags.build({
82
83
  char: 'e',
83
84
  parse: async (input) => await getOrgOrThrow(input),
84
85
  default: async () => await getOrgOrThrow(undefined),
86
+ defaultHelp: async () => { var _a; return (_a = (await getOrgOrThrow(undefined))) === null || _a === void 0 ? void 0 : _a.getUsername(); },
85
87
  });
86
88
  /**
87
89
  * An required org that is a devHub
@@ -106,5 +108,6 @@ exports.requiredHubFlag = core_1.Flags.build({
106
108
  char: 'v',
107
109
  parse: async (input) => await getHubOrThrow(input),
108
110
  default: async () => await getHubOrThrow(undefined),
111
+ defaultHelp: async () => { var _a; return (_a = (await getHubOrThrow(undefined))) === null || _a === void 0 ? void 0 : _a.getUsername(); },
109
112
  });
110
113
  //# sourceMappingURL=orgFlags.js.map
@@ -1,5 +1,5 @@
1
1
  import { CliUx, Command, Config, HelpSection, Interfaces } from '@oclif/core';
2
- import { SfdxProject } from '@salesforce/core';
2
+ import { SfProject, StructuredMessage } from '@salesforce/core';
3
3
  import { AnyJson } from '@salesforce/ts-types';
4
4
  import { Progress, Prompter, Spinner, Ux } from './ux';
5
5
  export interface SfCommandInterface extends Interfaces.Command {
@@ -16,6 +16,7 @@ export interface SfCommandInterface extends Interfaces.Command {
16
16
  * @see https://github.com/oclif/core/blob/main/src/command.ts
17
17
  */
18
18
  export declare abstract class SfCommand<T> extends Command {
19
+ static SF_ENV: string;
19
20
  static enableJsonFlag: boolean;
20
21
  static configurationVariablesSection?: HelpSection;
21
22
  static envVariablesSection?: HelpSection;
@@ -24,7 +25,7 @@ export declare abstract class SfCommand<T> extends Command {
24
25
  static requiresProject: boolean;
25
26
  spinner: Spinner;
26
27
  progress: Progress;
27
- project: SfdxProject;
28
+ project: SfProject;
28
29
  private warnings;
29
30
  private ux;
30
31
  private prompter;
@@ -36,6 +37,10 @@ export declare abstract class SfCommand<T> extends Command {
36
37
  * will be added to the json output under the warnings property.
37
38
  */
38
39
  warn(input: SfCommand.Warning): SfCommand.Warning;
40
+ /**
41
+ * Log info message to users.
42
+ */
43
+ info(input: SfCommand.Info): void;
39
44
  /**
40
45
  * Warn user about sensitive information (access tokens, etc...) before
41
46
  * logging to the console.
@@ -80,11 +85,30 @@ export declare abstract class SfCommand<T> extends Command {
80
85
  * Wrap the command error into the standardized JSON structure.
81
86
  */
82
87
  protected toErrorJson(error: Error): SfCommand.Error;
83
- protected assignProject(): Promise<SfdxProject>;
88
+ protected assignProject(): Promise<SfProject>;
89
+ protected catch(error: SfCommand.Error): Promise<SfCommand.Error>;
90
+ /**
91
+ * Format errors and actions for human consumption. Adds 'Error:',
92
+ * When there are actions, we add 'Try this:' in blue
93
+ * followed by each action in red on its own line.
94
+ * If Error.code is present it is output last in parentheses
95
+ *
96
+ * @returns {string} Returns decorated messages.
97
+ */
98
+ protected formatError(error: SfCommand.Error): string;
99
+ /**
100
+ * Utility function to format actions lines
101
+ *
102
+ * @param actions
103
+ * @param options
104
+ * @private
105
+ */
106
+ private formatActions;
84
107
  abstract run(): Promise<T>;
85
108
  }
86
109
  export declare namespace SfCommand {
87
- type Warning = string | Error;
110
+ type Info = StructuredMessage | string;
111
+ type Warning = StructuredMessage | string;
88
112
  interface Json<T> {
89
113
  status: number;
90
114
  result: T;
@@ -96,6 +120,9 @@ export declare namespace SfCommand {
96
120
  message: string;
97
121
  stack: string | undefined;
98
122
  warnings?: Warning[];
123
+ actions?: string[];
124
+ code?: unknown;
125
+ exitCode?: number;
99
126
  }
100
127
  }
101
128
  //# sourceMappingURL=sfCommand.d.ts.map
package/lib/sfCommand.js CHANGED
@@ -7,8 +7,10 @@ exports.SfCommand = void 0;
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
9
9
  */
10
+ const os = require("os");
10
11
  const core_1 = require("@oclif/core");
11
12
  const core_2 = require("@salesforce/core");
13
+ const chalk_1 = require("chalk");
12
14
  const ux_1 = require("./ux");
13
15
  core_2.Messages.importMessagesDirectory(__dirname);
14
16
  const messages = core_2.Messages.loadMessages('@salesforce/sf-plugins-core', 'messages');
@@ -39,10 +41,24 @@ class SfCommand extends core_1.Command {
39
41
  * will be added to the json output under the warnings property.
40
42
  */
41
43
  warn(input) {
42
- const warning = super.warn(input);
43
- this.warnings.push(warning);
44
+ const colorizedArgs = [];
45
+ this.warnings.push(input);
46
+ const message = typeof input === 'string' ? input : input.message;
47
+ colorizedArgs.push(`${chalk_1.default.bold.yellow(messages.getMessage('warning.prefix'))} ${message}`);
48
+ colorizedArgs.push(...this.formatActions(typeof input === 'string' ? [] : input.actions || [], { actionColor: chalk_1.default.reset }));
49
+ this.log(colorizedArgs.join(os.EOL));
44
50
  return input;
45
51
  }
52
+ /**
53
+ * Log info message to users.
54
+ */
55
+ info(input) {
56
+ const colorizedArgs = [];
57
+ const message = typeof input === 'string' ? input : input.message;
58
+ colorizedArgs.push(`${chalk_1.default.bold(messages.getMessage('info.prefix'))} ${message}`);
59
+ colorizedArgs.push(...this.formatActions(typeof input === 'string' ? [] : input.actions || [], { actionColor: chalk_1.default.reset }));
60
+ this.log(colorizedArgs.join(os.EOL));
61
+ }
46
62
  /**
47
63
  * Warn user about sensitive information (access tokens, etc...) before
48
64
  * logging to the console.
@@ -126,7 +142,7 @@ class SfCommand extends core_1.Command {
126
142
  }
127
143
  async assignProject() {
128
144
  try {
129
- return await core_2.SfdxProject.resolve();
145
+ return await core_2.SfProject.resolve();
130
146
  }
131
147
  catch (err) {
132
148
  if (err instanceof Error && err.name === 'InvalidProjectWorkspaceError') {
@@ -135,8 +151,56 @@ class SfCommand extends core_1.Command {
135
151
  throw err;
136
152
  }
137
153
  }
154
+ async catch(error) {
155
+ var _a, _b;
156
+ process.exitCode = (_b = (_a = process.exitCode) !== null && _a !== void 0 ? _a : error.exitCode) !== null && _b !== void 0 ? _b : 1;
157
+ this.log(this.formatError(error));
158
+ if (this.jsonEnabled()) {
159
+ core_1.CliUx.ux.styledJSON(this.toErrorJson(error));
160
+ }
161
+ return error;
162
+ }
163
+ /**
164
+ * Format errors and actions for human consumption. Adds 'Error:',
165
+ * When there are actions, we add 'Try this:' in blue
166
+ * followed by each action in red on its own line.
167
+ * If Error.code is present it is output last in parentheses
168
+ *
169
+ * @returns {string} Returns decorated messages.
170
+ */
171
+ formatError(error) {
172
+ const colorizedArgs = [];
173
+ colorizedArgs.push(`${chalk_1.default.bold.red(messages.getMessage('error.prefix'))} ${error.message}`);
174
+ colorizedArgs.push(...this.formatActions(error.actions || []));
175
+ if (error.stack && core_2.envVars.getString(SfCommand.SF_ENV) === core_2.Mode.DEVELOPMENT) {
176
+ colorizedArgs.push(chalk_1.default.red(`\n*** Internal Diagnostic ***\n\n${error.stack}\n******\n`));
177
+ }
178
+ if (error.code) {
179
+ colorizedArgs.push(chalk_1.default.bold(`\n(${error.code})`));
180
+ }
181
+ return colorizedArgs.join('\n');
182
+ }
183
+ /**
184
+ * Utility function to format actions lines
185
+ *
186
+ * @param actions
187
+ * @param options
188
+ * @private
189
+ */
190
+ formatActions(actions, options = { actionColor: chalk_1.default.red }) {
191
+ const colorizedArgs = [];
192
+ // Format any actions.
193
+ if (actions === null || actions === void 0 ? void 0 : actions.length) {
194
+ colorizedArgs.push(`\n${chalk_1.default.blue.bold(messages.getMessage('actions.tryThis'))}\n`);
195
+ actions.forEach((action) => {
196
+ colorizedArgs.push(`${options.actionColor(action)}`);
197
+ });
198
+ }
199
+ return colorizedArgs;
200
+ }
138
201
  }
139
202
  exports.SfCommand = SfCommand;
203
+ SfCommand.SF_ENV = 'SF_ENV';
140
204
  SfCommand.enableJsonFlag = true;
141
205
  SfCommand.tableFlags = core_1.CliUx.ux.table.flags;
142
206
  //# sourceMappingURL=sfCommand.js.map
package/lib/util.d.ts CHANGED
@@ -1,5 +1,11 @@
1
- import { HelpSection } from '@oclif/core';
2
- import { OrgConfigProperties, SfdxPropertyKeys, EnvironmentVariable } from '@salesforce/core';
1
+ import { EnvironmentVariable, OrgConfigProperties, SfdxPropertyKeys } from '@salesforce/core';
2
+ export declare type HelpSection = {
3
+ header: string;
4
+ body: Array<{
5
+ name: string;
6
+ description: string;
7
+ } | undefined>;
8
+ };
3
9
  /**
4
10
  * Function to build a help section for command help.
5
11
  * Takes a string to be used as section header text and an array of enums
@@ -9,5 +15,5 @@ import { OrgConfigProperties, SfdxPropertyKeys, EnvironmentVariable } from '@sal
9
15
  * @param header
10
16
  * @param vars
11
17
  */
12
- export declare function toHelpSection(header: string, ...vars: Array<OrgConfigProperties | SfdxPropertyKeys | EnvironmentVariable>): HelpSection;
18
+ export declare function toHelpSection(header: string, ...vars: Array<OrgConfigProperties | SfdxPropertyKeys | EnvironmentVariable | string>): HelpSection;
13
19
  //# sourceMappingURL=util.d.ts.map
@@ -67,7 +67,7 @@ class Progress extends _1.UxBase {
67
67
  this.bar.stop();
68
68
  }
69
69
  _start(total, payload = {}) {
70
- const start = kit_1.once((bar, t, p = {}) => {
70
+ const start = (0, kit_1.once)((bar, t, p = {}) => {
71
71
  bar.start(t);
72
72
  if (Object.keys(p).length) {
73
73
  bar.update(0, p);
@@ -14,7 +14,7 @@ class Prompter {
14
14
  * Prompt user for information. See https://www.npmjs.com/package/inquirer for more.
15
15
  */
16
16
  async prompt(questions, initialAnswers) {
17
- const answers = await inquirer_1.prompt(questions, initialAnswers);
17
+ const answers = await (0, inquirer_1.prompt)(questions, initialAnswers);
18
18
  return answers;
19
19
  }
20
20
  }
@@ -32,7 +32,7 @@ function generateTableChoices(columns, choices,
32
32
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
33
  padForCheckbox = true) {
34
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(', ')}`)
35
+ const columnLengths = columnEntries.map(([key, value]) => Math.max((0, ts_types_1.ensureString)(value).length, ...choices.map((option) => (0, ts_types_1.ensureString)(option[key], `Type ${typeof option[key]} for ${key} in ${Object.keys(option).join(', ')}`)
36
36
  .length)) + 1);
37
37
  const choicesOptions = [
38
38
  new inquirer_1.Separator(`${padForCheckbox ? ' '.repeat(2) : ''}${columnEntries
@@ -41,9 +41,9 @@ padForCheckbox = true) {
41
41
  ];
42
42
  for (const meta of choices) {
43
43
  const name = columnEntries
44
- .map(([key], index) => ts_types_1.ensureString(meta[key]).padEnd(columnLengths[index], ' '))
44
+ .map(([key], index) => (0, ts_types_1.ensureString)(meta[key]).padEnd(columnLengths[index], ' '))
45
45
  .join('');
46
- const choice = { name, value: meta.value, short: ts_types_1.ensureString(meta.name) };
46
+ const choice = { name, value: meta.value, short: (0, ts_types_1.ensureString)(meta.name) };
47
47
  choicesOptions.push(choice);
48
48
  }
49
49
  return choicesOptions;
@@ -1,3 +1,7 @@
1
+ # error.prefix
2
+
3
+ Error:
4
+
1
5
  # warning.security
2
6
 
3
7
  This command will expose sensitive information that allows for subsequent activity using your current authenticated session. Sharing this information is equivalent to logging someone in under the current credential, resulting in unintended access and escalation of privilege. For additional information, please review the authorization section of the <https://developer.salesforce.com/docs/atlas.en-us.234.0.sfdx_dev.meta/sfdx_dev/sfdx_dev_auth_web_flow.htm>
@@ -57,3 +61,15 @@ The value must be an integer.
57
61
  # errors.DurationBounds
58
62
 
59
63
  The value must be between %s and %s (inclusive).
64
+
65
+ # warning.prefix
66
+
67
+ Warning:
68
+
69
+ # info.prefix
70
+
71
+ Info:
72
+
73
+ # actions.tryThis
74
+
75
+ Try this:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/sf-plugins-core",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "Utils for writing deploy and retrieve plugins",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -32,40 +32,42 @@
32
32
  "/messages"
33
33
  ],
34
34
  "dependencies": {
35
- "@oclif/core": "^1.5.0",
36
- "@salesforce/core": "^3.7.6",
37
- "@salesforce/kit": "^1.5.17",
35
+ "@oclif/core": "^1.5.1",
36
+ "@salesforce/core": "^3.7.8",
37
+ "@salesforce/kit": "^1.5.34",
38
38
  "@salesforce/ts-types": "^1.5.20",
39
+ "chalk": "^2.4.2",
39
40
  "inquirer": "^8.2.0"
40
41
  },
41
42
  "devDependencies": {
42
- "@salesforce/dev-config": "^2.1.2",
43
- "@salesforce/dev-scripts": "^1.0.2",
43
+ "@oclif/test": "^2.1.0",
44
+ "@salesforce/dev-config": "^2.1.3",
45
+ "@salesforce/dev-scripts": "^1.0.4",
44
46
  "@salesforce/prettier-config": "^0.0.2",
45
- "@salesforce/ts-sinon": "^1.2.3",
46
- "@types/inquirer": "^8.1.3",
47
- "@typescript-eslint/eslint-plugin": "^4.2.0",
48
- "@typescript-eslint/parser": "^4.2.0",
49
- "chai": "^4.2.0",
47
+ "@salesforce/ts-sinon": "^1.3.21",
48
+ "@types/inquirer": "^8.2.0",
49
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
50
+ "@typescript-eslint/parser": "^4.33.0",
51
+ "chai": "^4.3.6",
50
52
  "eslint": "^6.8.0",
51
- "eslint-config-prettier": "^6.11.0",
53
+ "eslint-config-prettier": "^6.15.0",
52
54
  "eslint-config-salesforce": "^0.1.6",
53
55
  "eslint-config-salesforce-license": "^0.1.6",
54
- "eslint-config-salesforce-typescript": "^0.2.7",
55
- "eslint-plugin-header": "^3.0.0",
56
- "eslint-plugin-import": "^2.20.2",
57
- "eslint-plugin-jsdoc": "^27.0.3",
58
- "eslint-plugin-prettier": "^3.1.3",
56
+ "eslint-config-salesforce-typescript": "^0.2.8",
57
+ "eslint-plugin-header": "^3.1.1",
58
+ "eslint-plugin-import": "^2.25.4",
59
+ "eslint-plugin-jsdoc": "^27.1.2",
60
+ "eslint-plugin-prettier": "^3.4.1",
59
61
  "husky": "^7.0.4",
60
62
  "mocha": "^8.4.0",
61
63
  "nyc": "^15.1.0",
62
- "prettier": "^2.0.5",
63
- "pretty-quick": "^3.1.0",
64
+ "prettier": "^2.5.1",
65
+ "pretty-quick": "^3.1.3",
64
66
  "shelljs": "0.8.5",
65
- "sinon": "10.0.0",
66
- "strip-ansi": "6.0.0",
67
- "ts-node": "^10.4.0",
68
- "typescript": "^4.1.3"
67
+ "sinon": "10.0.1",
68
+ "strip-ansi": "6.0.1",
69
+ "ts-node": "^10.6.0",
70
+ "typescript": "^4.5.5"
69
71
  },
70
72
  "publishConfig": {
71
73
  "access": "public"