@uniformdev/transformer 1.1.19 → 1.1.21

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/dist/cli/index.js CHANGED
@@ -189,7 +189,59 @@ var ComponentService = class {
189
189
  throw new ComponentNotFoundError(componentType, componentsDir);
190
190
  }
191
191
  async saveComponent(filePath, component) {
192
- await this.fileSystem.writeFile(filePath, component);
192
+ const sorted = this.sortComponentArrays(component);
193
+ await this.fileSystem.writeFile(filePath, sorted);
194
+ }
195
+ sortComponentArrays(component) {
196
+ const result = { ...component };
197
+ if (result.parameters) {
198
+ result.parameters = this.sortParametersByGroup(result.parameters);
199
+ }
200
+ if (result.slots) {
201
+ result.slots = [...result.slots].sort((a, b) => a.id.localeCompare(b.id, void 0, { sensitivity: "base" })).map((slot) => {
202
+ if (slot.allowedComponents) {
203
+ return { ...slot, allowedComponents: [...slot.allowedComponents].sort((a, b) => a.localeCompare(b, void 0, { sensitivity: "base" })) };
204
+ }
205
+ return slot;
206
+ });
207
+ }
208
+ const variants = result.variants;
209
+ if (Array.isArray(variants)) {
210
+ result.variants = [...variants].sort((a, b) => a.id.localeCompare(b.id, void 0, { sensitivity: "base" }));
211
+ }
212
+ return result;
213
+ }
214
+ sortParametersByGroup(parameters) {
215
+ const compare = (a, b) => a.localeCompare(b, void 0, { sensitivity: "base" });
216
+ const groups = [];
217
+ const childToGroup = /* @__PURE__ */ new Set();
218
+ for (const param of parameters) {
219
+ if (param.type === "group") {
220
+ groups.push(param);
221
+ if (param.typeConfig?.childrenParams) {
222
+ param.typeConfig.childrenParams = [...param.typeConfig.childrenParams].sort(compare);
223
+ }
224
+ for (const childId of param.typeConfig?.childrenParams ?? []) {
225
+ childToGroup.add(childId.toLowerCase());
226
+ }
227
+ }
228
+ }
229
+ const ungrouped = parameters.filter(
230
+ (p) => p.type !== "group" && !childToGroup.has(p.id.toLowerCase())
231
+ );
232
+ const sortedGroups = [...groups].sort((a, b) => compare(a.id, b.id));
233
+ const result = [];
234
+ result.push(...[...ungrouped].sort((a, b) => compare(a.id, b.id)));
235
+ for (const group of sortedGroups) {
236
+ result.push(group);
237
+ for (const childId of group.typeConfig?.childrenParams ?? []) {
238
+ const child = parameters.find((p) => p.id.toLowerCase() === childId.toLowerCase());
239
+ if (child) {
240
+ result.push(child);
241
+ }
242
+ }
243
+ }
244
+ return result;
193
245
  }
194
246
  findParameter(component, parameterName, options = {}) {
195
247
  const { strict = false } = options;
@@ -736,6 +788,12 @@ var CompositionConverterService = class {
736
788
  }
737
789
  }
738
790
  }
791
+ for (const contentType of contentTypeMap.values()) {
792
+ contentType.fields = this.componentService.sortParametersByGroup(contentType.fields);
793
+ }
794
+ for (const contentType of flattenContentTypeMap.values()) {
795
+ contentType.fields = this.componentService.sortParametersByGroup(contentType.fields);
796
+ }
739
797
  for (const [typeName, contentType] of contentTypeMap) {
740
798
  const filePath = this.fileSystem.joinPath(contentTypesDirFull, `${typeName}.json`);
741
799
  const fieldCount = contentType.fields.filter((f) => f.type !== "contentReference").length;
@@ -1021,7 +1079,7 @@ function walkAndRegenerate(value, currentPath) {
1021
1079
  for (const [key, val] of Object.entries(obj)) {
1022
1080
  const childPath = `${currentPath}.${key}`;
1023
1081
  if (key === "_id" && typeof val === "string" && UUID_PATTERN.test(val)) {
1024
- result[key] = computeGuidHash(val + childPath);
1082
+ result[key] = computeGuidHash(childPath);
1025
1083
  } else {
1026
1084
  result[key] = walkAndRegenerate(val, childPath);
1027
1085
  }
@@ -4721,7 +4779,7 @@ function createRemoveFieldCommand() {
4721
4779
  // package.json
4722
4780
  var package_default = {
4723
4781
  name: "@uniformdev/transformer",
4724
- version: "1.1.19",
4782
+ version: "1.1.21",
4725
4783
  description: "CLI tool for transforming Uniform.dev serialization files offline",
4726
4784
  type: "module",
4727
4785
  bin: {