sfdx-easy-sources 0.5.9 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,10 +21,11 @@ With this plugin you can:
21
21
  - Delete some reference or permission from all the csv of a given metadata type
22
22
  - Minify the csv by removing all the rows that don't increase the value of the file
23
23
  - Clean the csv references to some resources that doesn't exist in the target org
24
+ - Setup a custom git merger to automatically resolve the csv conflicts while cherry picking or merging in git
24
25
 
25
26
  ## Supported metadata types
26
27
 
27
- | Metadata | Action | Available commands |
28
+ | Metadata Label| Metadata api | Available commands |
28
29
  | :---: | :---: | :---: |
29
30
  | All Meta | allmeta | split, upsert, merge, minify, retrieve |
30
31
  | Profiles | profiles | split, upsert, merge, minify, updatekey, delete, clean |
@@ -40,13 +41,15 @@ With this plugin you can:
40
41
 
41
42
  ```sh-session
42
43
  $ npm install -g sfdx-easy-sources
43
- $ sfdx COMMAND
44
- running command...
45
- $ sfdx (--version)
46
- sfdx-easy-sources/0.0.1 darwin-arm64 node-v18.11.0
47
- $ sfdx --help [COMMAND]
48
- USAGE
49
- $ sfdx COMMAND
44
+ or
45
+ $ sfdx plugin:install sfdx-easy-sources
46
+
47
+ GENERAL USAGE
48
+ $ sfdx easysources:<metadataapi>:<command> [...parameters]
49
+ $ sfdx easysources:<metadataapi>:<command> --help // to get help, the list of parameters and some examples
50
+ Examples
51
+ $ sfdx easysources:profiles:split
52
+ $ sfdx easysources:labels:upsert
50
53
  ...
51
54
  ```
52
55
 
@@ -60,6 +63,12 @@ Based on the source type, this plugin provides the following commands:
60
63
  - Minify: Bulk deletes each entry that doesn't add value to the file (example: a permission in a profile xml which has all permissions set to false)
61
64
  - Clean: Bulk deletes all the references that are not present in the target org or in the repository
62
65
 
66
+ # Disclaimer
67
+ - Please experiment at first inside a dummy project!
68
+ - The command allmeta:retrieve --clean performs a delete of all the sources before retrieving them from the org. If something goes wrong while retrieving, you could have lost all the sources if you are not in a git environment. Please be careful!
69
+ - This software is given as-is, without warranty that it is free of bugs. So test the process before implement it in production.
70
+
71
+
63
72
  # Let's start!
64
73
  ## Prerequisites
65
74
  ### Prerequisite 1 - Initialize the settings
@@ -74,6 +83,16 @@ This file contains the directory of:
74
83
  - the csv files (by default the same of the salesforce sources)
75
84
  - the log files.
76
85
 
86
+ Since I prefer to have the csv files near the xml ones, I left the default directories in my project. Consider that, in this case, you should need to:
87
+ - have a .forceignore file to ignore .csv and .part-xml files when running sfdx commands
88
+ - have a .pipelineignore file to ignore .csv and .part-xml files when running other plugins, for example when using sfdx-git-delta.
89
+
90
+ Simply put these lines inside those files
91
+ ```sh-session
92
+ # easysources
93
+ *-part.xml
94
+ *.csv
95
+ ```
77
96
 
78
97
  ### Prerequisite 2 - Retrieve all metadata
79
98
  To deal with Salesforce files all the source code from the org must be downloaded in the repository.
@@ -88,6 +107,9 @@ Some useful parameters are:
88
107
  - --clean: if set to true, automatically deletes al the source folder before performing the retrieve
89
108
  - --split-merge: if set to true, automatically performes a split and then a merge of all the sources, after they are retrieved
90
109
 
110
+ This command actually splits all the resources into various packages, trying to count the resources in every package to not exceed the "resnumb" number. It also creates some little packages, because profiles, permissionsets, translations and other particular metadata types should be retrieved building the package in a given way.
111
+ Suppose the profile packages are more then one, the algorithm should automatically perform a split after retrieving the first profile package, then it should perform an upsert after every other profile package retrieved, and at the end it should perform a merge and delete the created csv. Unfortunately, at this moment I didn't test this scenario!
112
+
91
113
  ### Prerequisite 3 - Create the csv files for the first time
92
114
  Once all the metadata have been downloaded, before to start dealing with the csv files, you should create them the first time.
93
115
  To do this run these commands (but first, please, understand the meaning of each command reading this guide)
@@ -98,31 +120,21 @@ $ sfdx easysources:allmeta:minify
98
120
  $ sfdx easysources:allmeta:merge
99
121
  ```
100
122
 
101
-
102
123
  ## Description of each command
103
124
 
104
125
 
105
126
  ### Split
106
-
107
-
108
127
  The split command creates a folder at the same level of the file that it is splitting, containing various csv files and a part.xml file.
109
128
  Inside the csv files you can find all the rows of a given type: each tag attribute becomes a column; the tags that are not mapped are copied in the part.xml file.
110
- [TODO] This is an example of an admin xml profile splitted in csv.
111
129
 
112
- ```sh-session
113
-
114
- For help
115
- $ sfdx easysources:profiles:split -h
116
- $ sfdx easysources:recordtypes:split -h
117
- $ sfdx easysources:labels:split -h
118
- $ sfdx easysources:permissionsets:split -h
119
- $ sfdx easysources:globalvaluesettranslations:split -h
120
- $ sfdx easysources:globalvaluesets:split -h
121
- $ sfdx easysources:applications:split -h
122
-
123
- $ sfdx easysources:allmeta:split -h
130
+ This is an example of an xml profile splitted in csv.
131
+ Once we run the command
124
132
 
133
+ ```sh-session
134
+ $ sfdx easysources:profiles:split
125
135
  ```
136
+ the plugin generates a folder with all the csv files.
137
+ ![profile_split](.images/profile_split.png)
126
138
 
127
139
  ### Upsert
128
140
  Suppose the developer cretes a new object, he creates some fields, he assigns the fields, the layouts and the object permissions to the various profiles.
@@ -133,20 +145,7 @@ To update the profiles on the repository, he can:
133
145
  4. *Execute the upsert command for profiles. The upsert command will insert the new tags into the csv*
134
146
  5. Then he can merge back to have the profiles to be deployed elsewhere
135
147
 
136
- ```sh-session
137
-
138
- For help
139
- $ sfdx easysources:profiles:upsert -h
140
- $ sfdx easysources:recordtypes:upsert -h
141
- $ sfdx easysources:labels:upsert -h
142
- $ sfdx easysources:permissionsets:upsert -h
143
- $ sfdx easysources:globalvaluesettranslations:upsert -h
144
- $ sfdx easysources:globalvaluesets:upsert -h
145
- $ sfdx easysources:applications:upsert -h
146
-
147
- $ sfdx easysources:allmeta:upsert -h
148
148
 
149
- ```
150
149
  **NOTE: the upsert doesn't delete any unused reference. If the user deletes a field, he should run the delete command**
151
150
 
152
151
 
@@ -154,49 +153,53 @@ For help
154
153
 
155
154
  Suppose the developer makes some modification directly on the csv. With the updatekey command, he can update the tagid column if needed.
156
155
 
157
- ```sh-session
158
-
159
- For help
160
- $ sfdx easysources:profiles:updatekey -h
161
- $ sfdx easysources:recordtypes:updatekey -h
162
- $ sfdx easysources:labels:updatekey -h
163
- $ sfdx easysources:permissionsets:updatekey -h
164
- $ sfdx easysources:globalvaluesettranslations:updatekey -h
165
- $ sfdx easysources:globalvaluesets:updatekey -h
166
- $ sfdx easysources:applications:updatekey -h
167
-
168
- ```
169
156
 
170
157
  ### Merge
171
158
 
172
- When the user needs to deploy the code, he needs to merge back the csv files to restore and update the original xml file.
173
-
174
- ```sh-session
175
-
176
- For help
177
- $ sfdx easysources:profiles:merge -h
178
- $ sfdx easysources:recordtypes:merge -h
179
- $ sfdx easysources:labels:merge -h
180
- $ sfdx easysources:permissionsets:merge -h
181
- $ sfdx easysources:globalvaluesettranslations:merge -h
182
- $ sfdx easysources:globalvaluesets:merge -h
183
- $ sfdx easysources:applications:merge -h
184
-
185
- $ sfdx easysources:allmeta:merge -h
159
+ When the user needs to deploy the code, he first needs to merge back the csv files to restore and update the original xml file starting from the content of the csv files.
186
160
 
187
- ```
161
+ Another scenario could be during a cherry pick or a merge conflict. Suppose a developer has created a custom field and he retrieves the package with the field and the profiles. Then he performs the upsert to insert the field into the csv, and then he merges the profiles to have again the full xml files. He commits and all is OK in the dev environment. If the profiles are not aligned between the sandboxes, the cherry pick or the merge through the UAT branch could raise a conflict on the xml files. If you configured a git merger for the csv files, you probably will not have conflicts on the csv. So you can simply run the merge command again, to restore the correct version of the xml files automatically and without any effort!
188
162
 
189
163
  ### Delete
190
164
  **Note: only applies to Profiles, PermissionSets and RecordTypes**
191
165
 
192
166
  Suppose the developer deletes a field on the org, he needs to delete all the references for that field for all Profiles, PermissionSets and RecordTypes.
193
- This command is intended to delete references, and it has flags to specify the name of the field. Run with -h flag to get a better description of the possible flags for each metadata type.
167
+ This command is intended to delete references, and it has flags to specify the name of the field. Run with --help flag to get a better description of the possible flags for each metadata type.
194
168
 
195
- ```sh-session
169
+ ### Minify
196
170
 
197
- For help
198
- $ sfdx easysources:profiles:delete -h
199
- $ sfdx easysources:recordtypes:delete -h
200
- $ sfdx easysources:permissionsets:delete -h
171
+ This command is very useful if you don't want to have the in your csv files all the lines that not add value to the file.
201
172
 
173
+ For example, in the following image, the lines in red don't specify any permission so they could be removed.
174
+
175
+ ```sh-session
176
+ $ sfdx easysources:profiles:minify
202
177
  ```
178
+
179
+ ![profile_minify](.images/profile_minify.png)
180
+
181
+ If you want a permission to be ignored even if it is false you can write FALSE instead of false: when I tested this feature, it was work correctly in Salesforce.
182
+
183
+ ## A special note on object translations
184
+ The object translation metadata is a little different, because when you download all custom objects with all object translations, salesforce retrieves an xml file for each field of the objects.
185
+
186
+ The split command will create the usual folder with all the csv, but for the fieldTranslations all the little xml files will become a row on the field translation csv file.
187
+ The merge command will first delete all the field translation xml files and then recreate them by "merging" the csv rows into the various little field translation files.
188
+ I know that the name of the commands is counterintuitive but I already developed these commands on the other metadata types so I left these names.
189
+ Remember that the split command performs a xml2csv conversion, and the merge commands perfors a csv2xml conversion.
190
+ The minify command in this case is very useful because many times we don't have a translation for each field, so we will simply delete all the empty fieldTranslation xml files (in my project we could delete almost 14k files from the repository)
191
+
192
+ ## A special note on translations
193
+ Due to complexity of converting xml2csv on the flow translations, this part is totally copied in the part.xml file when splitting. In this file, the upsert doesn't work.
194
+
195
+ ## Git Considerations
196
+ In my experience, merging or cherry picking csv files is much better then doing it on xml files. But this is not enough.
197
+ To build a better experience to developers and release manager, one can configure a custom git merger to automatically resolve conflicts on csv files.
198
+ For this reason, the csv files have the _tagid column, that is a key on which the automatic resolution of conflicts can be done.
199
+ I built a custom csv git merger that in my mind should work well, but at the moment there is no ETA to publish it. In my project I configured [this open source git merger](https://github.com/sctweedie/csvdiff3).
200
+
201
+ ## Other considerations
202
+ In my project I still have the xml files even if they are supported by csv.
203
+ It could be a great idea and it could avoid many conflicts and waste of time if the release manager removes the xml files from the repository, and the pipeline merges automatically the csv into the xml at runtime while deploying.
204
+
205
+ I know that the commands parameters can easily lead to misunderstanding or can be forgotten. I'm developing a vscode extension to easily launch the commands, get the parameters, select the resources on which a command must be run. But at the moment there is no ETA to finish it.