Skip to content

Commit

Permalink
Merge pull request #144 from amtrack/fix/sf-plugin-style
Browse files Browse the repository at this point in the history
fix: use sf plugin style
  • Loading branch information
amtrack authored Oct 27, 2023
2 parents c33c8c5 + 35ce13b commit 2eca5c4
Show file tree
Hide file tree
Showing 40 changed files with 2,354 additions and 2,545 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,28 @@ jobs:
default:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Install dependencies
run: |
yarn install
yarn global add sfdx-cli
yarn global add @salesforce/cli
- name: Run unit tests
run: yarn test
- name: Authenticate DevHub and create scratch org
env:
SFDX_AUTH_URL_DEVHUB: ${{ secrets.SFDX_AUTH_URL_DEVHUB }}
run: |
sfdx auth:sfdxurl:store -d -a devhub -f /dev/stdin <<< "${SFDX_AUTH_URL_DEVHUB}"
sf org login sfdx-url -d -a devhub -f /dev/stdin <<< "${SFDX_AUTH_URL_DEVHUB}"
yarn develop
- name: Run end-to-end tests
run: yarn test:e2e
- name: Delete scratch org
if: always()
run: |
sfdx force:org:delete -p
sf org delete scratch -p
- name: Release package
run: npx semantic-release
env:
Expand Down
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,50 @@
>
> Please submit issues with your feedback about errors, usability and feature requests.
> sfdx plugin for generating a package.xml manifest
> sfdx/sf plugin for generating a package.xml manifest
[![Actions Status](https://github.com/amtrack/sfdx-plugin-package-xml/workflows/Test%20and%20Release/badge.svg)](https://github.com/amtrack/sfdx-plugin-package-xml/actions)

## Installation

```console
sfdx plugins:install sfdx-plugin-package-xml@beta
sf plugins install sfdx-plugin-package-xml@beta
```

## Usage

Commands

```console
sfdx force:mdapi:listallmetadata -h
sfdx package.xml:generate -h
sf force mdapi listallmetadata -h
sf package.xml generate -h
```

> :warning: Note: The first command is similar to the official (`force:mdapi:listmetadata`) command.
> :warning: Note: The first command is similar to the official (`sf force mdapi listmetadata`) command.
>
> However our command lists Metadata for **ALL** Metadata Types.
>
> ```diff
> -force:mdapi:listmetadata
> +force:mdapi:listallmetadata
> -force mdapi listmetadata
> +force mdapi listallmetadata
> ```
## Use Cases
Retrieve all Metadata from an org named `acme-dev` (a.k.a "Metadata Backup", a.k.a. "sfdx force:org:pull")
Retrieve all Metadata from an org named `acme-dev` (a.k.a "Metadata Backup", a.k.a. "sf force org pull")
```console
sfdx force:mdapi:listallmetadata -f /tmp/fileproperties.json -u acme-dev
sfdx package.xml:generate -j /tmp/fileproperties.json -f package.xml --apiversion 54.0
sfdx force:source:retrieve -x package.xml -u acme-dev
sf force mdapi listallmetadata -f /tmp/fileproperties.json -o acme-dev
sfdx package.xml:generate -j /tmp/fileproperties.json -f package.xml --api-version 54.0
sf force source retrieve -x package.xml -o acme-dev
```
Explore Metadata in an org named `acme-dev`

```console
sfdx force:mdapi:listallmetadata --names -u acme-dev
sf force mdapi listallmetadata --names -o acme-dev
# include child Metadata such as CustomField and filter for CustomFields on Account
sfdx force:mdapi:listallmetadata --children --names -u acme-dev | grep "CustomField:Account."
sf force mdapi listallmetadata --children --names -o acme-dev | grep "CustomField:Account."
```

## Concept and Implementation
Expand Down Expand Up @@ -93,9 +93,9 @@ For convenience you can also write `CustomField` instead of `CustomField:*`.

They are used throughout this plugin, e.g. in the

- output of `sfdx force:mdapi:listallmetadata --names`
- component names (allow rules) in `sfdx force:mdapi:listallmetadata --metadata`
- ignore rules in `sfdx force:mdapi:listallmetadata --ignore` and `sfdx package.xml:generate --ignore`
- output of `sf force mdapi listallmetadata --names`
- component names (allow rules) in `sf force mdapi listallmetadata --metadata`
- ignore rules in `sf force mdapi listallmetadata --ignore` and `sfdx package.xml:generate --ignore`

### Filtering Metadata

Expand All @@ -112,15 +112,15 @@ Examples:
1. To **only** list CustomObjects belonging to a Managed Package Unlocked Package:

```console
sfdx force:mdapi:listallmetadata -m "CustomObject" --managed --unlocked --names
sfdx force:mdapi:listallmetadata -m "CustomObject" --no-unmanaged --names
sf force mdapi listallmetadata -m "CustomObject" --managed --unlocked --names
sf force mdapi listallmetadata -m "CustomObject" --no-unmanaged --names
```

2. To list CustomObjects **except** the ones belonging to a Managed Package OR Unlocked Package:

```console
sfdx force:mdapi:listallmetadata -m "CustomObject" --unmanaged --names
sfdx force:mdapi:listallmetadata -m "CustomObject" --no-managed --no-unlocked --names
sf force mdapi listallmetadata -m "CustomObject" --unmanaged --names
sf force mdapi listallmetadata -m "CustomObject" --no-managed --no-unlocked --names
```

### Package.xml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<Report xmlns="http://soap.sforce.com/2006/04/metadata">
<columns>
<field>USERS.NAME</field>
</columns>
<columns>
<field>ACCOUNT.NAME</field>
</columns>
<columns>
<field>TYPE</field>
</columns>
<columns>
<field>RATING</field>
</columns>
<columns>
<field>DUE_DATE</field>
</columns>
<columns>
<field>LAST_UPDATE</field>
</columns>
<columns>
<field>ADDRESS1_STATE</field>
</columns>
<format>Tabular</format>
<name>FooAccountsClassicReport</name>
<params>
<name>co</name>
<value>1</value>
</params>
<reportType>AccountList</reportType>
<scope>user</scope>
<showDetails>true</showDetails>
<showGrandTotal>true</showGrandTotal>
<showSubTotals>true</showSubTotals>
<timeFrameFilter>
<dateColumn>CREATED_DATE</dateColumn>
<interval>INTERVAL_CUSTOM</interval>
<startDate>2020-11-11</startDate>
</timeFrameFilter>
</Report>
26 changes: 15 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@
"@mdapi-issues/listmetadata-recordtype-personaccount": "2.0.2",
"@mdapi-issues/listmetadata-standardvalueset": "2.0.3",
"@mdapi-issues/listmetadata-standardvaluesettranslation-type": "2.0.2",
"@salesforce/command": "5.2.16",
"@salesforce/sf-plugins-core": "4.0.0",
"get-stdin": "8.0.0",
"lodash": "4.17.21",
"picomatch": "2.3.1",
"tslib": "2.4.0"
"picomatch": "2.3.1"
},
"devDependencies": {
"@types/chai": "4.3.5",
"@types/mocha": "10.0.1",
"chai": "4.3.7",
"@salesforce/cli-plugins-testkit": "4.4.10",
"@salesforce/dev-config": "4.1.0",
"@salesforce/prettier-config": "0.0.3",
"@types/chai": "4.3.9",
"@types/mocha": "10.0.3",
"chai": "4.3.10",
"mocha": "10.2.0",
"nyc": "15.1.0",
"oclif": "3.2.24",
"oclif": "4.0.3",
"prettier": "3.0.3",
"ts-node": "10.9.1",
"typescript": "5.0.4"
"typescript": "5.2.2"
},
"engines": {
"node": ">=14.16"
Expand All @@ -49,7 +52,8 @@
"license": "MIT",
"oclif": {
"commands": "./lib/commands",
"bin": "sfdx",
"bin": "sf",
"topicSeparator": " ",
"topics": {
"package.xml": {
"description": "explore metadata in an org and generate a package.xml manifest"
Expand All @@ -76,7 +80,7 @@
"develop": "bash scripts/develop.sh",
"prepack": "yarn build",
"prepare": "yarn build",
"test": "nyc --reporter=lcov --reporter=text mocha --require ts-node/register \"test/**/*.test.ts\"",
"test:e2e": "mocha --require ts-node/register \"test/**/*.e2e-spec.ts\""
"test": "tsc -p test && nyc --reporter=lcov --reporter=text mocha --require ts-node/register \"test/**/*.test.ts\"",
"test:e2e": "tsc -p test && mocha --require ts-node/register \"test/**/*.e2e-spec.ts\""
}
}
6 changes: 6 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const salesforcePrettierConfig = require("@salesforce/prettier-config");

module.exports = {
...salesforcePrettierConfig,
singleQuote: false,
};
5 changes: 1 addition & 4 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"extends": [
"config:base",
":semanticCommits"
]
"extends": ["config:base", ":semanticCommits"]
}
54 changes: 5 additions & 49 deletions scripts/develop.sh
Original file line number Diff line number Diff line change
@@ -1,52 +1,8 @@
#!/usr/bin/env bash

set -e
set -eo pipefail

CLI_NAME="$(basename "${BASH_SOURCE[0]}")"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
REPO_NAME="$(basename "$(dirname "${DIR}")")"
DEFAULT_ALIAS="${REPO_NAME}-dev"

_help() {
echo "${CLI_NAME}."
echo ""
echo "> Setup an environment for development."
echo ""
echo "Usage:"
echo " ${CLI_NAME} [-a SETALIAS]"
echo ""
echo "Options:"
echo " -h --help show help"
echo " -a --setalias SETALIAS set an alias for for the created scratch org (default: ${DEFAULT_ALIAS})"
echo ""
echo "Examples:"
echo " View this help text"
echo " $ ${CLI_NAME} -h"
echo ""
echo " Spin up and configure a scratch org"
echo " $ ${CLI_NAME}"
echo ""
echo " Spin up and configure a scratch org with the given alias (one alphanumerical word, may contain '-_')"
echo " $ ${CLI_NAME} -a myfeature"
}

_main() {
alias="${alias:-${DEFAULT_ALIAS}}"
# shellcheck disable=SC2068
sfdx force:org:create -f config/project-scratch-def.json \
-a "$alias" \
-s \
description="${alias}" ${POSITIONAL_ARGS[@]}
sfdx force:source:push -u "$alias"
}

if [[ "$0" == "${BASH_SOURCE[0]}" ]]; then
set -eo pipefail
POSITIONAL_ARGS=()
while [[ "$#" -gt 0 ]]; do case $1 in
-h|--help) _help; exit 0;;
-a|--setalias) alias="$2"; shift 2;;
*) POSITIONAL_ARGS+=("$1"); shift;;
esac; done
_main "${POSITIONAL_ARGS[@]}"
fi
sf org create scratch -f config/project-scratch-def.json \
-a sfdx-plugin-package-xml-dev \
-d
sf project deploy start
2 changes: 1 addition & 1 deletion sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "57.0"
"sourceApiVersion": "59.0"
}
23 changes: 6 additions & 17 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,24 @@ import { readFile } from "fs/promises";
import type { FileProperties } from "jsforce/api/metadata";
import { toMetadataComponentName } from "./metadata-component";

export function parseCommaSeparatedValues(
commaSeparatedMetadataComponentNames: string
): Array<string> {
export function parseCommaSeparatedValues(commaSeparatedMetadataComponentNames?: string): string[] {
if (!commaSeparatedMetadataComponentNames) {
return [];
}
return clean(commaSeparatedMetadataComponentNames.split(","));
}
export function parseNewLineSeparatedValues(
newLineSeparatedValues: string
): Array<string> {
export function parseNewLineSeparatedValues(newLineSeparatedValues: string): string[] {
if (!newLineSeparatedValues) {
return [];
}
return clean(newLineSeparatedValues.split(/\r?\n/));
}

function clean(values: Array<string>) {
function clean(values: string[]) {
return values.map((x) => x.trim()).filter(Boolean);
}

export function formatFileProperties(
fileProperties: Array<FileProperties>,
outputType: string
): string {
export function formatFileProperties(fileProperties: FileProperties[], outputType: string): string {
let mapFn;
if (outputType.startsWith("name")) {
mapFn = toMetadataComponentName;
Expand All @@ -37,9 +30,7 @@ export function formatFileProperties(
return outputType.endsWith("-csv") ? entries.join(",") : entries.join("\n");
}

export async function getNonEmptyLinesFromFile(
filePath: string
): Promise<string[]> {
export async function getNonEmptyLinesFromFile(filePath: string): Promise<string[]> {
if (!filePath) {
return [];
}
Expand All @@ -51,9 +42,7 @@ export async function getNonEmptyLinesFromFile(
);
}

export async function getNonEmptyLinesFromFiles(
filePaths: string[]
): Promise<string[]> {
export async function getNonEmptyLinesFromFiles(filePaths?: string[]): Promise<string[]> {
if (!filePaths) {
return [];
}
Expand Down
Loading

0 comments on commit 2eca5c4

Please sign in to comment.