Skip to content

Commit

Permalink
feat: convert project to use a new source behavior (#1015)
Browse files Browse the repository at this point in the history
* feat(wip): decompose command

* feat: convert a project to use a new sourceBehaviorOption

* chore: snapshot/schema

* feat: error for behavior change with no matching types

* refactor: rename the command from design

* chore: ut a function

* test: add a nut, fix bugs that uncovers

* chore: bump sdr for renamed prop

* feat: normalize paths for consistency

* test: more nut for preset conversion

* test: remove redundant nut

* test: win ut only

* refactor: calc preset dir once

* test: windows ut again

* test: restore full test suite

* fix: edit the messages for "project convert source-behavior" (#1018)

* fix: change behavior shortchar

* chore: snapshot/schema

* Update messages/convert.source-behavior.md

Co-authored-by: Willhoit <[email protected]>

* chore: pr suggestions

Co-authored-by: Willhoit <[email protected]>

---------

Co-authored-by: Juliet Shackell <[email protected]>
Co-authored-by: Eric Willhoit <[email protected]>
Co-authored-by: Willhoit <[email protected]>
  • Loading branch information
4 people authored May 29, 2024
1 parent bb8db15 commit 014500e
Show file tree
Hide file tree
Showing 17 changed files with 622 additions and 62 deletions.
8 changes: 8 additions & 0 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
],
"plugin": "@salesforce/plugin-deploy-retrieve"
},
{
"alias": [],
"command": "project:convert:source-behavior",
"flagAliases": [],
"flagChars": ["b", "o"],
"flags": ["behavior", "dry-run", "flags-dir", "json", "preserve-temp-dir", "target-org"],
"plugin": "@salesforce/plugin-deploy-retrieve"
},
{
"alias": ["force:source:delete"],
"command": "project:delete:source",
Expand Down
70 changes: 70 additions & 0 deletions messages/convert.source-behavior.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# summary

Enable a behavior of your project source files, and then update your Salesforce DX project to implement the behavior.

# description

Specifically, this command updates the "sourceBehaviorOption" option in the "sfdx-project.json" file and then converts the associated local source files in your project as needed.

For example, run this command with the "--behavior decomposePermissionSetBeta" flag to start decomposing permission sets when you deploy or retrieve them. Decomposing means breaking up the monolithic metadata API format XML file that corresponds to a metadata component into smaller XML files and directories based on its subtypes. Permission sets are not decomposed by default; you must opt-in to start decomposing them by using this command. When the command finishes, your "sfdx-project.json" file is updated to always decompose permission sets, and the existing permission set files in your local package directories are converted into the new decomposed format. You run this command only once for a given behavior change.

For more information about the possible values for the --behavior flag, see the "sourceBehaviorOptions" section in the https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_config.htm topic.

# flags.behavior.summary

Behavior to enable; the values correspond to the possible values of the "sourceBehaviorOption" option in the "sfdx-project.json" file.

# examples

- Update your Salesforce DX project to decompose custom labels:

<%= config.bin %> <%= command.id %> --behavior decomposeCustomLabelsBeta

- Display what the command would do, but don't change any existing files:

<%= config.bin %> <%= command.id %> --behavior decomposeCustomLabelsBeta --dry-run

- Keep the temporary directory that contains the interim metadata API formatted files:

<%= config.bin %> <%= command.id %> --behavior decomposeCustomLabelsBeta --dry-run --preserve-temp-dir

# flags.dry-run.summary

Display what the command would do, but don't make any actual changes.

# flags.dry-run.description

Doesn't modify the existing files in your project, including the "sfdx-project.json" file. Instead, the command lists the files that would be deleted, explains the modifications to the "sfdx-project.json" file, and outputs the resulting modifications to a new directory named `DRY-RUN-RESULTS` for review.

# flags.preserve-temp-dir.summary

Don't delete the metadata API format temporary directory that this command creates. Useful for debugging.

# error.trackingNotSupported

Your project has a default org (target-org) that uses source tracking. This operation will cause changes to the local project source files that can't be properly tracked.

# error.trackingNotSupported.actions

- Retrieve any changes or data you need from the org that you haven't already retrieved.
- Delete the org ("sf org delete scratch" or "sf org delete sandbox").
- Run this command again.
- Create a new org ("sf org create scratch" or "sf org create sandbox") and deploy the modified source.

# error.packageDirectoryNeedsMainDefault

The package directory %s doesn't have a main/default structure.
This command moves metadata into a main/default structure, but your package directories aren't ready for it.

# error.packageDirectoryNeedsMainDefault.actions

- Update %s to have all its metadata inside a main/default directory structure.
- Run the command again.

# success.dryRun

Files were created in %s outside your package directories for you to inspect.

# error.noTargetTypes

The project doesn't contain any package directories with metadata that matches the specified behavior %s.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@salesforce/cli-plugins-testkit": "^5.3.6",
"@salesforce/dev-scripts": "^9.1.2",
"@salesforce/plugin-command-reference": "^3.0.86",
"@salesforce/schemas": "^1.9.0",
"@salesforce/source-testkit": "^2.2.10",
"@salesforce/ts-sinon": "^1.4.19",
"cross-env": "^7.0.3",
Expand Down Expand Up @@ -75,7 +76,7 @@
"description": "Commands to retrieve metadata from a Salesforce org"
},
"convert": {
"description": "Commands to convert metadata from one format to another."
"description": "Commands to change the format of your project source files."
},
"delete": {
"description": "Commands to delete metadata from a Salesforce org."
Expand Down
31 changes: 31 additions & 0 deletions schemas/project-convert-source__behavior.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/SourceBehaviorResult",
"definitions": {
"SourceBehaviorResult": {
"type": "object",
"properties": {
"sourceBehaviorOptions": {
"type": "array",
"items": {
"type": "string"
}
},
"deletedFiles": {
"type": "array",
"items": {
"type": "string"
}
},
"createdFiles": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": ["sourceBehaviorOptions", "deletedFiles", "createdFiles"],
"additionalProperties": false
}
}
}
10 changes: 5 additions & 5 deletions schemas/project-delete-source.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@
},
"FileResponseSuccess": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand All @@ -459,11 +460,11 @@
"enum": ["Created", "Changed", "Unchanged", "Deleted"]
}
},
"required": ["fullName", "state", "type"],
"additionalProperties": false
"required": ["fullName", "state", "type"]
},
"FileResponseFailure": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand Down Expand Up @@ -492,11 +493,11 @@
"enum": ["Warning", "Error"]
}
},
"required": ["error", "fullName", "problemType", "state", "type"],
"additionalProperties": false
"required": ["error", "fullName", "problemType", "state", "type"]
},
"MetadataApiDeployStatus": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string"
Expand Down Expand Up @@ -598,7 +599,6 @@
"status",
"success"
],
"additionalProperties": false,
"description": "Raw response returned from a checkDeployStatus call to the Metadata API"
},
"CoverageResultsFileInfo": {
Expand Down
8 changes: 4 additions & 4 deletions schemas/project-deploy-cancel.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
},
"FileResponseSuccess": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand All @@ -157,11 +158,11 @@
"enum": ["Created", "Changed", "Unchanged", "Deleted"]
}
},
"required": ["fullName", "state", "type"],
"additionalProperties": false
"required": ["fullName", "state", "type"]
},
"FileResponseFailure": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand Down Expand Up @@ -190,8 +191,7 @@
"enum": ["Warning", "Error"]
}
},
"required": ["error", "fullName", "problemType", "state", "type"],
"additionalProperties": false
"required": ["error", "fullName", "problemType", "state", "type"]
},
"RequestStatus": {
"type": "string",
Expand Down
8 changes: 4 additions & 4 deletions schemas/project-deploy-quick.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
},
"FileResponseSuccess": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand All @@ -157,11 +158,11 @@
"enum": ["Created", "Changed", "Unchanged", "Deleted"]
}
},
"required": ["fullName", "state", "type"],
"additionalProperties": false
"required": ["fullName", "state", "type"]
},
"FileResponseFailure": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand Down Expand Up @@ -190,8 +191,7 @@
"enum": ["Warning", "Error"]
}
},
"required": ["error", "fullName", "problemType", "state", "type"],
"additionalProperties": false
"required": ["error", "fullName", "problemType", "state", "type"]
},
"RequestStatus": {
"type": "string",
Expand Down
8 changes: 4 additions & 4 deletions schemas/project-deploy-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
},
"FileResponseSuccess": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand All @@ -157,11 +158,11 @@
"enum": ["Created", "Changed", "Unchanged", "Deleted"]
}
},
"required": ["fullName", "state", "type"],
"additionalProperties": false
"required": ["fullName", "state", "type"]
},
"FileResponseFailure": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand Down Expand Up @@ -190,8 +191,7 @@
"enum": ["Warning", "Error"]
}
},
"required": ["error", "fullName", "problemType", "state", "type"],
"additionalProperties": false
"required": ["error", "fullName", "problemType", "state", "type"]
},
"RequestStatus": {
"type": "string",
Expand Down
8 changes: 4 additions & 4 deletions schemas/project-deploy-resume.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
},
"FileResponseSuccess": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand All @@ -157,11 +158,11 @@
"enum": ["Created", "Changed", "Unchanged", "Deleted"]
}
},
"required": ["fullName", "state", "type"],
"additionalProperties": false
"required": ["fullName", "state", "type"]
},
"FileResponseFailure": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand Down Expand Up @@ -190,8 +191,7 @@
"enum": ["Warning", "Error"]
}
},
"required": ["error", "fullName", "problemType", "state", "type"],
"additionalProperties": false
"required": ["error", "fullName", "problemType", "state", "type"]
},
"RequestStatus": {
"type": "string",
Expand Down
8 changes: 4 additions & 4 deletions schemas/project-deploy-start.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
},
"FileResponseSuccess": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand All @@ -157,11 +158,11 @@
"enum": ["Created", "Changed", "Unchanged", "Deleted"]
}
},
"required": ["fullName", "state", "type"],
"additionalProperties": false
"required": ["fullName", "state", "type"]
},
"FileResponseFailure": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand Down Expand Up @@ -190,8 +191,7 @@
"enum": ["Warning", "Error"]
}
},
"required": ["error", "fullName", "problemType", "state", "type"],
"additionalProperties": false
"required": ["error", "fullName", "problemType", "state", "type"]
},
"RequestStatus": {
"type": "string",
Expand Down
8 changes: 4 additions & 4 deletions schemas/project-deploy-validate.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
},
"FileResponseSuccess": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand All @@ -157,11 +158,11 @@
"enum": ["Created", "Changed", "Unchanged", "Deleted"]
}
},
"required": ["fullName", "state", "type"],
"additionalProperties": false
"required": ["fullName", "state", "type"]
},
"FileResponseFailure": {
"type": "object",
"additionalProperties": false,
"properties": {
"fullName": {
"type": "string"
Expand Down Expand Up @@ -190,8 +191,7 @@
"enum": ["Warning", "Error"]
}
},
"required": ["error", "fullName", "problemType", "state", "type"],
"additionalProperties": false
"required": ["error", "fullName", "problemType", "state", "type"]
},
"RequestStatus": {
"type": "string",
Expand Down
Loading

0 comments on commit 014500e

Please sign in to comment.