npm package: @mavens/sfdx-commands
Description: Miscellaneous collection of handy SFDX commands, brought to you by Mavens (っ▀¯▀)つ
Author: Jean-Philippe Monette @jpmonette
Latest version: 1.3.0

<h1 align="center">@mavens/sfdx-commands</h1>
<p align="center">
<a href="https://www.npmjs.com/package/@mavens/sfdx-commands"><img src="https://badge.fury.io/js/%40mavens%2Fsfdx-commands.svg" alt="npm version" height="18"></a>
    <img src="https://img.shields.io/npm/dt/@mavens/sfdx-commands"/>
</p>

<p align="center">Miscellaneous collection of handy SFDX commands</p>

## Getting Started

```sh-session
$ sfdx plugins:install @mavens/sfdx-commands
```

## Usage

### `mavens:ci:lcov`

Generating an `lcov.info` file based on sfdx test results, consumeable by tools like [Coveralls](https://coveralls.io/).

```bash
$ sfdx mavens:ci:lcov --rootdir="." --targetusername rene-levesque@example.com
Generating the lcov.info file... done
```

Here's a sample `.travis.yaml` configuration file, when used alongside Travis CI:

```yaml
node_js: "7"

before_script:
  # [insert here sfdx installation & login]
  - npm install coveralls -g
  - echo y | sfdx plugins:install @mavens/sfdx-commands

script:
  - sfdx force:org:create --setdefaultusername --definitionfile scratchdef.json --setalias ci
  - sfdx force:source:push
  - mkdir coverage
  - sfdx force:apex:test:run --codecoverage --testlevel=RunLocalTests --resultformat=json --outputdir=coverage
  - sfdx mavens:ci:lcov
  - sfdx force:org:delete --noprompt
  - cat ./coverage/lcov.info | coveralls
```

### `mavens:ci:replace`

Used to find and replace files within a directory and sub directories, using pre-defined environment variables.

These can be exported from your resource file, a `.env` file (refer to [dotenv](https://github.com/motdotla/dotenv) documentation), via your CI configuration...

```bash
$ sfdx mavens:ci:replace --rootdir=packages --targetusername celine-dion@example.com
1 files updated... done
```

You must have a `.mavens.yaml` configuration file, with the `replace` key defined:

```yaml
replace:
  - VAULT_ENDPOINT
  - VAULT_USERNANE
  - VAULT_PASSWORD
```

Any metadata containing (such as this sample `packages/force-app/main/default/namedCredentials/Vault_MVN.namedCredential-meta.xml`) containing `${VAULT_ENDPOINT}`:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<NamedCredential xmlns="http://soap.sforce.com/2006/04/metadata">
    <allowMergeFieldsInBody>true</allowMergeFieldsInBody>
    <allowMergeFieldsInHeader>true</allowMergeFieldsInHeader>
    <endpoint>${VAULT_ENDPOINT}</endpoint>
    <generateAuthorizationHeader>false</generateAuthorizationHeader>
    <label>Vault</label>
    <principalType>NamedUser</principalType>
    <protocol>Password</protocol>
    <username>${VAULT_USERNANE}</username>
    <password>${VAULT_PASSWORD}</password>
</NamedCredential>
```

Will be replaced to look like the following:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<NamedCredential xmlns="http://soap.sforce.com/2006/04/metadata">
    <allowMergeFieldsInBody>true</allowMergeFieldsInBody>
    <allowMergeFieldsInHeader>true</allowMergeFieldsInHeader>
    <endpoint>https://sb-customer-medcomms.veevavault.com</endpoint>
    <generateAuthorizationHeader>false</generateAuthorizationHeader>
    <label>Vault</label>
    <principalType>NamedUser</principalType>
    <protocol>Password</protocol>
    <username>integration@mavens.com</username>
    <password>[placeholder]</password>
</NamedCredential>
```

### `mavens:manifest:generate`

```bash
$ sfdx mavens:manifest:generate --targetusername celine-dion@example.com

Describing metadata types... 103 types retrieved.
Listing metadata members... done

Metadata Type               | Count
─────────────────────────── | ─────
ActionLinkGroupTemplate     | 0
AnalyticSnapshot            | 0
AnimationRule               | 0
ApexClass                   | 1076
...
TopicsForObjects            | 338
Translations                | 30
Workflow                    | 32

Generating package.xml... done
```

### `mavens:schema:dictionaries`

Generates field dictionaries from Salesforce objects, using the Metadata API.

```bash
$ sfdx mavens:schema:dictionaries --outputdir=packages --targetusername celine-dion@example.com
=== Retrieving Salesforce Object fields from Metadata API
Querying objects from 4/4... done
=== Salesforce Object Fields Retrieved
OBJECT                            FIELD COUNT
────────────────────────────────  ───────────
Account                           66
Case                              125
Congres_MVN__c                    10
PersonAccount                     0
User                              10
=== Salesforce Object Fields Retrieved
Generating Field Dictionaries... 4 files written.
```

You must have a `.mavens.yaml` configuration file, with the `schema.dictionaries.sobjects` key defined:

```yaml
schema:
  dictionaries:
    sobjects:
      - Account
      - Case
      - Congress_MVN__c
      - PersonAccount
      - User
    file_format: split # options: split | unique (default: split)
```

CSV files will be created in your `--outputdir`.

```
dictionaries
├── Account.csv
├── Case.csv
├── Congress_MVN__c.csv
├── PersonAccount.csv
└── User.md
.mavens.yaml
```

Here's an example `Account.csv`:

| Label       | Field API Name       | Data Type |                                                     Picklist Values                                                      | Required | Description                                                                                                         |
| ----------- | -------------------- | --------- | :----------------------------------------------------------------------------------------------------------------------: | :------: | ------------------------------------------------------------------------------------------------------------------- |
| Company     | `MED_Company__c`     | Picklist  |                                                         Servier                                                          |  false   | The company associated with the Employee Account.                                                                   |
| Country     | `MED_Country__c`     | Picklist  |                                               GlobalValueSet (MED_Country)                                               |  false   | The primary country for the account.                                                                                |
| Credentials | `MED_Credentials__c` | Picklist  | DO<br>MD<br>PharmD<br>RN<br>NP<br>PHAR<br>HBP<br>PA<br>PHT<br>PHARM<br>PVN<br>SW<br>MA<br>NA<br>MD-S<br>PSY<br>OD<br>PHD |  false   | Picklist of the professional's (Person Account) credentials. Edit the picklist to change the available credentials. |
| ...         | ...                  | ...       |                                                           ...                                                            |   ...    | ...                                                                                                                 |

### `mavens:typings:generate`

```bash
$ sfdx mavens:typings:generate --targetusername celine-dion@example.com --outputdir=.typescript

Querying Custom Labels... done
Writing 641 labels to .typescript/salesforce/customlabels.d.ts... done
Querying Custom Permissions... done
Writing 10 custom permissions to .typescript/salesforce/custom-permissions.d.ts... done
```