@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 +61 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +60 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -198,6 +198,15 @@ declare class ComponentService {
|
|
|
198
198
|
filePath: string;
|
|
199
199
|
}>;
|
|
200
200
|
saveComponent(filePath: string, component: ComponentDefinition): Promise<void>;
|
|
201
|
+
private sortComponentArrays;
|
|
202
|
+
sortParametersByGroup<T extends {
|
|
203
|
+
id: string;
|
|
204
|
+
type: string;
|
|
205
|
+
typeConfig?: {
|
|
206
|
+
childrenParams?: string[];
|
|
207
|
+
[key: string]: unknown;
|
|
208
|
+
};
|
|
209
|
+
}>(parameters: T[]): T[];
|
|
201
210
|
findParameter(component: ComponentDefinition, parameterName: string, options?: FindOptions$1): Parameter | undefined;
|
|
202
211
|
isGroupParameter(parameter: Parameter): boolean;
|
|
203
212
|
resolveGroupParameters(component: ComponentDefinition, groupParameter: Parameter, options?: FindOptions$1): Parameter[];
|
|
@@ -488,7 +497,7 @@ declare function computeGuidHash(guidOrSeed: string): string;
|
|
|
488
497
|
|
|
489
498
|
/**
|
|
490
499
|
* Recursively walks through a value and regenerates all `_id` properties that contain UUIDs.
|
|
491
|
-
* Uses computeGuidHash(
|
|
500
|
+
* Uses computeGuidHash(jsonPath) to produce deterministic new IDs based purely on position.
|
|
492
501
|
* Also creates a deep clone of the value — the original is not modified.
|
|
493
502
|
*/
|
|
494
503
|
declare function regenerateIds<T>(value: T, basePath: string): T;
|
package/dist/index.js
CHANGED
|
@@ -179,7 +179,59 @@ var ComponentService = class {
|
|
|
179
179
|
throw new ComponentNotFoundError(componentType, componentsDir);
|
|
180
180
|
}
|
|
181
181
|
async saveComponent(filePath, component) {
|
|
182
|
-
|
|
182
|
+
const sorted = this.sortComponentArrays(component);
|
|
183
|
+
await this.fileSystem.writeFile(filePath, sorted);
|
|
184
|
+
}
|
|
185
|
+
sortComponentArrays(component) {
|
|
186
|
+
const result = { ...component };
|
|
187
|
+
if (result.parameters) {
|
|
188
|
+
result.parameters = this.sortParametersByGroup(result.parameters);
|
|
189
|
+
}
|
|
190
|
+
if (result.slots) {
|
|
191
|
+
result.slots = [...result.slots].sort((a, b) => a.id.localeCompare(b.id, void 0, { sensitivity: "base" })).map((slot) => {
|
|
192
|
+
if (slot.allowedComponents) {
|
|
193
|
+
return { ...slot, allowedComponents: [...slot.allowedComponents].sort((a, b) => a.localeCompare(b, void 0, { sensitivity: "base" })) };
|
|
194
|
+
}
|
|
195
|
+
return slot;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
const variants = result.variants;
|
|
199
|
+
if (Array.isArray(variants)) {
|
|
200
|
+
result.variants = [...variants].sort((a, b) => a.id.localeCompare(b.id, void 0, { sensitivity: "base" }));
|
|
201
|
+
}
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
sortParametersByGroup(parameters) {
|
|
205
|
+
const compare = (a, b) => a.localeCompare(b, void 0, { sensitivity: "base" });
|
|
206
|
+
const groups = [];
|
|
207
|
+
const childToGroup = /* @__PURE__ */ new Set();
|
|
208
|
+
for (const param of parameters) {
|
|
209
|
+
if (param.type === "group") {
|
|
210
|
+
groups.push(param);
|
|
211
|
+
if (param.typeConfig?.childrenParams) {
|
|
212
|
+
param.typeConfig.childrenParams = [...param.typeConfig.childrenParams].sort(compare);
|
|
213
|
+
}
|
|
214
|
+
for (const childId of param.typeConfig?.childrenParams ?? []) {
|
|
215
|
+
childToGroup.add(childId.toLowerCase());
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
const ungrouped = parameters.filter(
|
|
220
|
+
(p) => p.type !== "group" && !childToGroup.has(p.id.toLowerCase())
|
|
221
|
+
);
|
|
222
|
+
const sortedGroups = [...groups].sort((a, b) => compare(a.id, b.id));
|
|
223
|
+
const result = [];
|
|
224
|
+
result.push(...[...ungrouped].sort((a, b) => compare(a.id, b.id)));
|
|
225
|
+
for (const group of sortedGroups) {
|
|
226
|
+
result.push(group);
|
|
227
|
+
for (const childId of group.typeConfig?.childrenParams ?? []) {
|
|
228
|
+
const child = parameters.find((p) => p.id.toLowerCase() === childId.toLowerCase());
|
|
229
|
+
if (child) {
|
|
230
|
+
result.push(child);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return result;
|
|
183
235
|
}
|
|
184
236
|
findParameter(component, parameterName, options = {}) {
|
|
185
237
|
const { strict = false } = options;
|
|
@@ -726,6 +778,12 @@ var CompositionConverterService = class {
|
|
|
726
778
|
}
|
|
727
779
|
}
|
|
728
780
|
}
|
|
781
|
+
for (const contentType of contentTypeMap.values()) {
|
|
782
|
+
contentType.fields = this.componentService.sortParametersByGroup(contentType.fields);
|
|
783
|
+
}
|
|
784
|
+
for (const contentType of flattenContentTypeMap.values()) {
|
|
785
|
+
contentType.fields = this.componentService.sortParametersByGroup(contentType.fields);
|
|
786
|
+
}
|
|
729
787
|
for (const [typeName, contentType] of contentTypeMap) {
|
|
730
788
|
const filePath = this.fileSystem.joinPath(contentTypesDirFull, `${typeName}.json`);
|
|
731
789
|
const fieldCount = contentType.fields.filter((f) => f.type !== "contentReference").length;
|
|
@@ -1011,7 +1069,7 @@ function walkAndRegenerate(value, currentPath) {
|
|
|
1011
1069
|
for (const [key, val] of Object.entries(obj)) {
|
|
1012
1070
|
const childPath = `${currentPath}.${key}`;
|
|
1013
1071
|
if (key === "_id" && typeof val === "string" && UUID_PATTERN.test(val)) {
|
|
1014
|
-
result[key] = computeGuidHash(
|
|
1072
|
+
result[key] = computeGuidHash(childPath);
|
|
1015
1073
|
} else {
|
|
1016
1074
|
result[key] = walkAndRegenerate(val, childPath);
|
|
1017
1075
|
}
|