Skip to content

Commit

Permalink
fix(deps): use new inquirer (#456)
Browse files Browse the repository at this point in the history
* feat: use new inquirer (wip)

* test: generated plugin as test fixture

* refactor: this.answers because tests use it

* test: ut assertions move to nut

* refactor: fewer class members

* test: split audit messages test, use nut for cmd execution

* chore: bump oclif to fix readme

* chore: pr feedback

* chore: deps, exclude fixture nuts

* refactor: invoke duration prompts properly

* refactor: custom flag is invoked ()

* chore: library prompts work

* fix: integer requires default when min/max

* fix: option flag is invoked () + test

* chore: msg typo

* feat: prompt for choices for options/custom flags

* refactor: class => functions, ut test without sinon/stubs

* feat: optional summary (use basic flags), options

* feat: flag descriptions

* chore: remaining descriptions

* refactor: as const

* chore: don't ask multiple for standard flags

* chore: invoke flags with no properties

* chore: bump teskit

* docs: readme
  • Loading branch information
mshanemc authored Jan 16, 2024
1 parent 73fd1ba commit 6a674ee
Show file tree
Hide file tree
Showing 34 changed files with 9,118 additions and 948 deletions.
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

0 comments on commit 6a674ee

Please sign in to comment.