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

fix(deps): use new inquirer #456

Merged
merged 27 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
eac4dbd
feat: use new inquirer (wip)
mshanemc Jan 5, 2024
5e55fe5
test: generated plugin as test fixture
mshanemc Jan 5, 2024
2f88b77
refactor: this.answers because tests use it
mshanemc Jan 8, 2024
730b9d6
test: ut assertions move to nut
mshanemc Jan 8, 2024
0307513
refactor: fewer class members
mshanemc Jan 8, 2024
38128df
test: split audit messages test, use nut for cmd execution
mshanemc Jan 8, 2024
02c7b83
Merge remote-tracking branch 'origin/main' into sm/new-inquirer
mshanemc Jan 8, 2024
5c2ffbc
chore: bump oclif to fix readme
mshanemc Jan 8, 2024
1d2fd8d
chore: pr feedback
mshanemc Jan 9, 2024
ba615cc
chore: deps, exclude fixture nuts
mshanemc Jan 9, 2024
f091a63
refactor: invoke duration prompts properly
mshanemc Jan 9, 2024
3d03b1c
refactor: custom flag is invoked ()
mshanemc Jan 9, 2024
5dcac1a
chore: library prompts work
mshanemc Jan 9, 2024
0b86a5c
fix: integer requires default when min/max
mshanemc Jan 9, 2024
3862f9b
fix: option flag is invoked () + test
mshanemc Jan 9, 2024
ff6d8f4
chore: msg typo
mshanemc Jan 9, 2024
6fd3a60
feat: prompt for choices for options/custom flags
mshanemc Jan 9, 2024
b73fc31
refactor: class => functions, ut test without sinon/stubs
mshanemc Jan 10, 2024
e868b1f
feat: optional summary (use basic flags), options
mshanemc Jan 10, 2024
a903d3f
feat: flag descriptions
mshanemc Jan 10, 2024
f385315
chore: remaining descriptions
mshanemc Jan 10, 2024
4d2e9ce
refactor: as const
mshanemc Jan 10, 2024
b6878a8
chore: don't ask multiple for standard flags
mshanemc Jan 10, 2024
165442b
chore: invoke flags with no properties
mshanemc Jan 10, 2024
8f88928
chore: bump teskit
mshanemc Jan 12, 2024
689ae99
Merge remote-tracking branch 'origin/main' into sm/new-inquirer
mshanemc Jan 16, 2024
1494757
docs: readme
mshanemc Jan 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.cjs/
test/fixtures
77 changes: 7 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ sf plugins
<!-- commands -->

- [`sf dev audit messages`](#sf-dev-audit-messages)
- [`sf dev configure repo`](#sf-dev-configure-repo)
- [`sf dev configure secrets`](#sf-dev-configure-secrets)
- [`sf dev convert messages`](#sf-dev-convert-messages)
- [`sf dev convert script`](#sf-dev-convert-script)
- [`sf dev generate command`](#sf-dev-generate-command)
Expand Down Expand Up @@ -158,68 +156,7 @@ FLAG DESCRIPTIONS
The default is the "src" directory in the current working directory.
```

_See code: [lib/commands/dev/audit/messages.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.5/lib/commands/dev/audit/messages.ts)_

## `sf dev configure repo`

Configure a GitHub repo for the GitHub Actions pipeline.

```
USAGE
$ sf dev configure repo -r <value> [--json] [-d] [-b <value>]

FLAGS
-b, --bot=<value> [default: SF-CLI-BOT] GitHub login/username for the bot.
-d, --dry-run Make no changes.
-r, --repository=<value> (required) GitHub owner/repo for which you want to configure GitHub Actions.

GLOBAL FLAGS
--json Format output as json.

DESCRIPTION
Configure a GitHub repo for the GitHub Actions pipeline.

Sets up labels and exempts the CLI bot for branch protection and PR rules.

EXAMPLES
Configure the repo "testPackageRelease", with owner "salesforcecli", for GitHub Actions.

$ sf dev configure repo --repository salesforcecli/testPackageRelease
```

_See code: [lib/commands/dev/configure/repo.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.5/lib/commands/dev/configure/repo.ts)_

## `sf dev configure secrets`

Ensures a GitHub repo has correct access to secrets based on its workflows.

```
USAGE
$ sf dev configure secrets -r <value> [--json] [-d]

FLAGS
-d, --dry-run Make no changes.
-r, --repository=<value> (required) Github owner/repo.

GLOBAL FLAGS
--json Format output as json.

DESCRIPTION
Ensures a GitHub repo has correct access to secrets based on its workflows.

Inspects a repo's yaml files and verifies that secrets required are available for the repo (either set at the repo
level or shared via organization-level secrets).

This command requires scope:admin permissions to inspect the org secrets and admin access to the repo to inspect the
repo secrets.

EXAMPLES
Ensure secrets access for the repo "testPackageRelease", with owner "salesforcecli":

$ sf dev configure secrets --repository salesforcecli/testPackageRelease
```

_See code: [lib/commands/dev/configure/secrets.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.5/lib/commands/dev/configure/secrets.ts)_
_See code: [src/commands/dev/audit/messages.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.4/src/commands/dev/audit/messages.ts)_

## `sf dev convert messages`

Expand Down Expand Up @@ -253,7 +190,7 @@ EXAMPLES
$ sf dev convert messages --project-dir ./path/to/plugin --filename my-command.json
```

_See code: [lib/commands/dev/convert/messages.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.5/lib/commands/dev/convert/messages.ts)_
_See code: [src/commands/dev/convert/messages.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.4/src/commands/dev/convert/messages.ts)_

## `sf dev convert script`

Expand Down Expand Up @@ -296,7 +233,7 @@ EXAMPLES
$ sf dev convert script --script ./myScript.yml
```

_See code: [lib/commands/dev/convert/script.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.5/lib/commands/dev/convert/script.ts)_
_See code: [src/commands/dev/convert/script.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.4/src/commands/dev/convert/script.ts)_

## `sf dev generate command`

Expand Down Expand Up @@ -333,7 +270,7 @@ EXAMPLES
$ sf dev generate command --name my:exciting:command
```

_See code: [lib/commands/dev/generate/command.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.5/lib/commands/dev/generate/command.ts)_
_See code: [src/commands/dev/generate/command.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.4/src/commands/dev/generate/command.ts)_

## `sf dev generate flag`

Expand Down Expand Up @@ -370,7 +307,7 @@ EXAMPLES
$ sf dev generate flag --dry-run
```

_See code: [lib/commands/dev/generate/flag.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.5/lib/commands/dev/generate/flag.ts)_
_See code: [src/commands/dev/generate/flag.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.4/src/commands/dev/generate/flag.ts)_

## `sf dev generate library`

Expand All @@ -394,7 +331,7 @@ EXAMPLES
$ sf dev generate library
```

_See code: [lib/commands/dev/generate/library.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.5/lib/commands/dev/generate/library.ts)_
_See code: [src/commands/dev/generate/library.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.4/src/commands/dev/generate/library.ts)_

## `sf dev generate plugin`

Expand Down Expand Up @@ -422,6 +359,6 @@ EXAMPLES
$ sf dev generate plugin
```

_See code: [lib/commands/dev/generate/plugin.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.5/lib/commands/dev/generate/plugin.ts)_
_See code: [src/commands/dev/generate/plugin.ts](https://github.com/salesforcecli/plugin-dev/blob/2.1.4/src/commands/dev/generate/plugin.ts)_

<!-- commandsstop -->
74 changes: 73 additions & 1 deletion messages/dev.generate.flag.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You must run this command from within a plugin directory, such as the directory

This command is interactive. It first discovers all the commands currently implemented in the plugin, and asks you which you want to create a new flag for. It then prompts for other flag properties, such as its long name, optional short name, type, whether it's required, and so on. Long flag names must be kebab-case and not camelCase. The command doesn't let you use an existing long or short flag name. When the command completes, the Typescript file for the command is updated with the code for the new flag.

Use the --dry-run flag to review new code for the command file without actually udpating it.
Use the --dry-run flag to review new code for the command file without actually updating it.

# flags.dry-run.summary

Expand Down Expand Up @@ -88,6 +88,10 @@ Must be an integer.

Maximum must be greater than minimum.

# error.RequiredIntegerDefault

An integer flag requires a default when it has a min and/or max value.

# error.InvalidDefaultInteger

Default integer must be between the specified minimum and maximum.
Expand Down Expand Up @@ -143,3 +147,71 @@ Enter the maximum integer value (optional):
# question.Integer.Default

Enter the default integer value (required if setting a minimum or maximum):

# question.Options

Enter an option, or hit enter if you are done entering options

# question.UseStandard

Do you want to use the standard definition (character, summary, description, default) for this flag type

# flagDescriptions.duration

a unit and quantity of time (example: X minutes, 4 days). You can specify min/max/default.

# flagDescriptions.option

a choice from a defined list of string options. You can set the allowed values.

# flagDescriptions.integer

an integer with built-in validation of optional min/max/default values.

# flagDescriptions.custom

a flag with a custom typescript type. You'll need to add some code after the scaffolding is complete.

# flagDescriptions.salesforceId

a valid salesforce record ID. You can specify the 3-character prefix and/or the length of the ID.

# flagDescriptions.file

a local file path. You can specify whether the file must exist.

# flagDescriptions.directory

a local directory path. You can specify whether the file must exist.

# flagDescriptions.orgApiVersion

a valid salesforce API version number. The code checks for minimal non-retired values.

# flagDescriptions.requiredOrg

a Salesforce org, entered by username/alias and aware of default org.

# flagDescriptions.optionalOrg

a Salesforce org, entered by username/alias and aware of default org.

# flagDescriptions.requiredHub

a Salesforce org, entered by username/alias and aware of default dev hub. Must be a dev hub.

# flagDescriptions.optionalHub

a Salesforce org, entered by username/alias and aware of default dev hub. Must be a dev hub.

# flagDescriptions.url

Validates that input matches URL spec. Returns the NodeJS Url class for simplified parsing.

# flagDescriptions.string

Any valid string

# flagDescriptions.boolean

Take no value, has value of `true` if provided and `false` otherwise
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^3.14.1",
"@inquirer/confirm": "^2.0.15",
"@inquirer/input": "^1.2.14",
"@inquirer/select": "^1.3.1",
"@oclif/core": "^3.16.0",
"@octokit/rest": "^19.0.13",
"@salesforce/core": "^6.4.4",
"@salesforce/kit": "^3.0.15",
"@salesforce/sf-plugins-core": "^5.0.13",
"@salesforce/sf-plugins-core": "^7.0.0",
"@salesforce/ts-types": "^2.0.9",
"change-case": "^5.4.1",
"fast-glob": "^3.3.2",
Expand All @@ -31,13 +34,11 @@
"@types/lodash.defaultsdeep": "^4.6.9",
"@types/shelljs": "^0.8.14",
"@types/yeoman-generator": "^5.2.14",
"@types/yeoman-test": "^4.0.3",
"eslint-plugin-sf-plugin": "^1.17.0",
"oclif": "^4.3.2",
"shx": "^0.3.3",
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"yeoman-test": "^6.3.0"
"typescript": "^5.3.3"
},
"config": {
"commitizen": {
Expand Down Expand Up @@ -111,7 +112,7 @@
"prepack": "sf-prepack",
"prepare": "sf-install",
"test": "wireit",
"test:nuts": "nyc mocha \"test/**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel --jobs 10",
"test:nuts": "nyc mocha \"test/**/*.nut.ts\" --exclude \"test/fixtures/**\" --slow 4500 --timeout 600000 --parallel --jobs 10",
"test:only": "wireit",
"version": "oclif readme"
},
Expand Down
22 changes: 11 additions & 11 deletions src/commands/dev/audit/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type MessageRefNode = NodeType & {

type Node = FileNode | BundleNode | MessageNode | MessageRefNode | BundleRefNode;

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-dev', 'audit.messages');

export default class AuditMessages extends SfCommand<AuditResults> {
Expand Down Expand Up @@ -83,9 +83,7 @@ export default class AuditMessages extends SfCommand<AuditResults> {
private flags!: Interfaces.InferredFlags<typeof AuditMessages.flags>;
private logger!: Logger;

private messagesDirPath?: string;
private bundles: string[] = [];
private sourceDirPath?: string;
private source: Map<string, string> = new Map();
private auditResults: AuditResults = {
unusedBundles: [],
Expand Down Expand Up @@ -122,10 +120,10 @@ export default class AuditMessages extends SfCommand<AuditResults> {
}

private async loadMessages(): Promise<void> {
this.messagesDirPath = resolve(ensureString(this.projectDir), this.flags['messages-dir']);
this.logger.debug(`Loading messages from ${this.messagesDirPath}`);
const messagesDir = await fs.promises.readdir(this.messagesDirPath, { withFileTypes: true });
Messages.importMessagesDirectory(this.messagesDirPath);
const messagesDirPath = resolve(ensureString(this.projectDir), this.flags['messages-dir']);
this.logger.debug(`Loading messages from ${messagesDirPath}`);
const messagesDir = await fs.promises.readdir(messagesDirPath, { withFileTypes: true });
Messages.importMessagesDirectory(messagesDirPath);
this.bundles = messagesDir.filter((entry) => entry.isFile()).map((entry) => entry.name);
this.logger.debug(`Loaded ${this.bundles.length} bundles with names ${this.bundles.toString()}`);
const bundleMap = this.bundles.reduce((m, bundle) => {
Expand All @@ -142,10 +140,10 @@ export default class AuditMessages extends SfCommand<AuditResults> {
}

private async loadSource(): Promise<void> {
this.sourceDirPath = resolve(ensureString(this.projectDir), this.flags['source-dir']);
this.logger.debug(`Loading source from ${this.sourceDirPath}`);
const sourceDirPath = resolve(ensureString(this.projectDir), this.flags['source-dir']);
this.logger.debug(`Loading source from ${sourceDirPath}`);

(await Promise.all((await fileReader(this.sourceDirPath)).map(resolveFileContents))).map((i) => {
(await Promise.all((await fileReader(sourceDirPath)).map(resolveFileContents))).map((i) => {
this.source.set(relative(ensureString(this.projectDir), i.path), i.contents);
});
}
Expand Down Expand Up @@ -449,7 +447,7 @@ export const fileReader = async (dir: string): Promise<FileReaderOutput[]> => {
const contents = await fs.promises.readdir(dir, { withFileTypes: true });

return contents
.filter((entry) => entry.isFile() && entry.name.match(/\.(?:ts|js)$/))
.filter(isJsOrTs)
.map(toPath)
.map(fileHandler)
.concat(
Expand All @@ -464,6 +462,8 @@ export const fileReader = async (dir: string): Promise<FileReaderOutput[]> => {
);
};

const isJsOrTs = (file: fs.Dirent): boolean => file.isFile() && Boolean(file.name.match(/\.(?:ts|js)$/));

const fileHandler = (file: string): FileReaderOutput => ({
path: file,
contents: fs.promises.readFile(file, 'utf8'),
Expand Down
5 changes: 2 additions & 3 deletions src/commands/dev/configure/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
// because github api isn't camelcased
/* eslint-disable camelcase */


import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { Octokit } from '@octokit/rest';
import { OctokitError } from '../../../types.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-dev', 'configure.repo');

export type ConfigureRepoResult = {
Expand All @@ -28,7 +27,7 @@ export default class ConfigureRepo extends SfCommand<ConfigureRepoResult> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');

public static readonly hidden = true;
public static readonly flags = {
repository: Flags.string({
summary: messages.getMessage('flags.repository.summary'),
Expand Down
5 changes: 2 additions & 3 deletions src/commands/dev/configure/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// because github api isn't camelcased
/* eslint-disable camelcase */



import fs from 'node:fs';
import { ux } from '@oclif/core';

Expand All @@ -21,7 +19,7 @@ import shelljs from 'shelljs';
import yaml from 'js-yaml';
import { OctokitError } from '../../../types.js';

Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-dev', 'configure.secrets');

type SecretClassification =
Expand Down Expand Up @@ -52,6 +50,7 @@ export default class ConfigureSecrets extends SfCommand<SecretsResult> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
public static readonly examples = messages.getMessages('examples');
public static readonly hidden = true;

public static readonly flags = {
repository: Flags.string({
Expand Down
Loading
Loading