Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: use current inquirer #479

Merged
merged 17 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"require": "test/init.js, ts-node/register, source-map-support/register",
"require": "ts-node/register",
"watch-extensions": ["ts", "md"],
"watch-files": ["src", "test", "messages"],
"recursive": true,
"reporter": "spec",
"timeout": 5000
"timeout": 5000,
"node-option": ["loader=ts-node/esm"]
}
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2023, Salesforce.com, Inc.
Copyright (c) 2024, Salesforce.com, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ The SfCommand abstract class extends [@oclif/core's Command class](https://githu
- Enables additional help sections to the standard oclif command help output
- Provides access to the [cli-ux cli actions](https://github.com/oclif/cli-ux#cliaction). This avoids having to import that interface from cli-ux and manually handling the `--json` flag.

## Prompter Class

A general purpose class that prompts a user for information. See [inquirer NPM Module](https://www.npmjs.com/package/inquirer) for more information.
## Prompts
mshanemc marked this conversation as resolved.
Show resolved Hide resolved

## Flags

Expand All @@ -29,7 +27,7 @@ Flags is a convenience reference to [@oclif/core#Flags](https://github.com/oclif

These flags can be imported into a command and used like any other flag. See code examples in the links

- [orgApiVersionFlag](src/flags/apiVersion.ts)
- [orgApiVersionFlag](src/flags/orgApiVersion.ts)
- specifies a Salesforce API version.
- reads from Config (if available)
- validates version is still active
Expand Down
39 changes: 28 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Utils for writing Salesforce CLI plugins",
"main": "lib/exported",
"types": "lib/exported.d.ts",
"type": "module",
"license": "BSD-3-Clause",
"scripts": {
"build": "wireit",
Expand All @@ -12,6 +13,7 @@
"compile": "wireit",
"docs": "sf-docs",
"format": "wireit",
"link-check": "wireit",
"lint": "wireit",
"lint-fix": "yarn sf-lint --fix",
"postcompile": "tsc -p test",
Expand All @@ -20,6 +22,13 @@
"test": "wireit",
"test:only": "wireit"
},
"exports": {
"./SfCommand": "./lib/SfCommand.js",
"./Flags": "./lib/flags/flags.js",
"./Ux": "./lib/ux/ux.js",
"./StandardColors": "./lib/ux/standardColors.js",
".": "./lib/exported.js"
},
"repository": "salesforcecli/sf-plugins-core",
"bugs": {
"url": "https://github.com/salesforcecli/sf-plugins-core/issues"
Expand All @@ -34,22 +43,20 @@
"node": ">=18.0.0"
},
"dependencies": {
"@inquirer/confirm": "^2.0.15",
"@inquirer/password": "^1.1.14",
"@oclif/core": "^3.14.1",
"@salesforce/core": "^6.2.2",
"@salesforce/core": "^6.4.1",
"@salesforce/kit": "^3.0.15",
"@salesforce/ts-types": "^2.0.9",
"@types/inquirer": "^8.2.3",
"chalk": "^4",
"inquirer": "^8.2.5"
"chalk": "^5.3.0"
},
"devDependencies": {
"@oclif/test": "^3.1.3",
"@salesforce/dev-scripts": "^7.1.1",
"eslint-plugin-sf-plugin": "^1.16.15",
"shelljs": "0.8.5",
"strip-ansi": "6.0.1",
"@inquirer/type": "^1.1.5",
"@salesforce/dev-scripts": "^8.1.2",
"eslint-plugin-sf-plugin": "^1.17.0",
"ts-node": "^10.9.2",
"typescript": "^4.9.5"
"typescript": "^5.3.3"
},
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -107,7 +114,8 @@
"test": {
"dependencies": [
"test:only",
"test:compile"
"test:compile",
"link-check"
]
},
"test:only": {
Expand All @@ -124,6 +132,15 @@
".nycrc"
],
"output": []
},
"link-check": {
"command": "node -e \"process.exit(process.env.CI ? 0 : 1)\" || linkinator \"**/*.md\" --skip \"CHANGELOG.md|node_modules|test/|confluence.internal.salesforce.com|%s\" --markdown --retry --directory-listing --verbosity error",
"files": [
"./*.md",
"./!(CHANGELOG).md",
"messages/**/*.md"
],
"output": []
}
}
}
6 changes: 3 additions & 3 deletions src/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import { Flags } from '@oclif/core';
import { Lifecycle, Messages } from '@salesforce/core';
import { orgApiVersionFlag } from './flags/orgApiVersion';
import { optionalHubFlag, optionalOrgFlag, requiredHubFlag, requiredOrgFlag } from './flags/orgFlags';
import { orgApiVersionFlag } from './flags/orgApiVersion.js';
import { optionalHubFlag, optionalOrgFlag, requiredHubFlag, requiredOrgFlag } from './flags/orgFlags.js';

/**
* Adds an alias for the deprecated sfdx-style "apiversion" and provides a warning if it is used
Expand All @@ -31,7 +31,7 @@ export const orgApiVersionFlagWithDeprecations = orgApiVersionFlag({
deprecateAliases: true,
});

Messages.importMessagesDirectory(__dirname);
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/sf-plugins-core', 'messages');
/**
* Use only for commands that maintain sfdx compatibility.
Expand Down
50 changes: 0 additions & 50 deletions src/deauthorizer.ts

This file was deleted.

110 changes: 0 additions & 110 deletions src/deployer.ts

This file was deleted.

56 changes: 56 additions & 0 deletions src/errorFormatting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { Mode, Messages, envVars } from '@salesforce/core';
import chalk from 'chalk';
import { StandardColors } from './exported.js';
import { SfCommand } from './sfCommandNamespace.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/sf-plugins-core', 'messages');

/**
* Format errors and actions for human consumption. Adds 'Error (<ErrorCode>):',
* When there are actions, we add 'Try this:' in blue
* followed by each action in red on its own line.
* If Error.code is present it is output last in parentheses
*
* @returns {string} Returns decorated messages.
*/

/**
* Utility function to format actions lines
*
* @param actions
* @param options
* @private
*/
export const formatActions = (
actions: string[],
options: { actionColor: typeof chalk } = { actionColor: StandardColors.info }
): string[] =>
actions.length
? [
`\n${StandardColors.info(messages.getMessage('actions.tryThis'))}\n`,
...actions.map((a) => `${options.actionColor(a)}`),
]
: [];

export const formatError = (error: SfCommand.Error): string =>
[
`${formatErrorPrefix(error)} ${error.message}`,
...formatActions(error.actions ?? []),
error.stack && envVars.getString('SF_ENV') === Mode.DEVELOPMENT
? StandardColors.info(`\n*** Internal Diagnostic ***\n\n${error.stack}\n******\n`)
: [],
].join('\n');

const formatErrorPrefix = (error: SfCommand.Error): string =>
`${StandardColors.error(messages.getMessage('error.prefix', [formatErrorCode(error)]))}`;

const formatErrorCode = (error: SfCommand.Error): string =>
typeof error.code === 'string' || typeof error.code === 'number' ? ` (${error.code})` : '';