@uniformdev/transformer 1.1.26 → 1.1.28
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 +82 -17
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +71 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -484,7 +484,10 @@ declare class CompositionConverterService {
|
|
|
484
484
|
buildEntryIdMap(entriesDirFull: string): Promise<Map<string, string>>;
|
|
485
485
|
buildSourceItemMap(entriesDirFull: string): Promise<Map<string, string>>;
|
|
486
486
|
private findExistingEntryBySourceItem;
|
|
487
|
+
private matchesType;
|
|
487
488
|
private compareTypes;
|
|
489
|
+
private expandWildcardTypes;
|
|
490
|
+
private collectMatchingTypes;
|
|
488
491
|
private truncate;
|
|
489
492
|
private truncateName;
|
|
490
493
|
}
|
package/dist/index.js
CHANGED
|
@@ -587,8 +587,8 @@ var CompositionConverterService = class {
|
|
|
587
587
|
whatIf,
|
|
588
588
|
strict
|
|
589
589
|
} = options;
|
|
590
|
-
const
|
|
591
|
-
const
|
|
590
|
+
const initialComponentsToReferences = [...new Set(rawComponentsToReferences)];
|
|
591
|
+
const initialComponentsToBlocks = [...new Set(rawComponentsToBlocks)];
|
|
592
592
|
const compositionsDirFull = this.fileSystem.resolvePath(rootDir, compositionsDir);
|
|
593
593
|
const componentsDirFull = this.fileSystem.resolvePath(rootDir, componentsDir);
|
|
594
594
|
const contentTypesDirFull = this.fileSystem.resolvePath(rootDir, contentTypesDir);
|
|
@@ -599,13 +599,13 @@ var CompositionConverterService = class {
|
|
|
599
599
|
let entriesReused = 0;
|
|
600
600
|
let blocksEmbedded = 0;
|
|
601
601
|
this.logger.info(`Composition types: ${compositionTypes.join(", ")}`);
|
|
602
|
-
if (
|
|
603
|
-
this.logger.info(`Components to references: ${
|
|
602
|
+
if (initialComponentsToReferences.length > 0) {
|
|
603
|
+
this.logger.info(`Components to references: ${initialComponentsToReferences.join(", ")}`);
|
|
604
604
|
}
|
|
605
|
-
if (
|
|
606
|
-
this.logger.info(`Components to blocks: ${
|
|
605
|
+
if (initialComponentsToBlocks.length > 0) {
|
|
606
|
+
this.logger.info(`Components to blocks: ${initialComponentsToBlocks.join(", ")}`);
|
|
607
607
|
}
|
|
608
|
-
const sourceItemMap =
|
|
608
|
+
const sourceItemMap = initialComponentsToReferences.length > 0 ? await this.buildSourceItemMap(entriesDirFull) : /* @__PURE__ */ new Map();
|
|
609
609
|
if (sourceItemMap.size > 0) {
|
|
610
610
|
this.logger.info(`Found ${sourceItemMap.size} existing entry(ies) with sourceItem values`);
|
|
611
611
|
}
|
|
@@ -620,6 +620,8 @@ var CompositionConverterService = class {
|
|
|
620
620
|
return { contentTypesWritten: 0, entriesFromCompositions: 0, entriesFromReferences: 0, entriesReused: 0, blocksEmbedded: 0 };
|
|
621
621
|
}
|
|
622
622
|
this.logger.info(`Found ${compositionResults.length} composition(s)`);
|
|
623
|
+
const componentsToReferences = this.expandWildcardTypes(compositionResults, initialComponentsToReferences, strict);
|
|
624
|
+
const componentsToBlocks = this.expandWildcardTypes(compositionResults, initialComponentsToBlocks, strict);
|
|
623
625
|
const rootComponentTypes = /* @__PURE__ */ new Set();
|
|
624
626
|
for (const { composition } of compositionResults) {
|
|
625
627
|
rootComponentTypes.add(composition.composition.type);
|
|
@@ -714,7 +716,8 @@ var CompositionConverterService = class {
|
|
|
714
716
|
const compositionId = comp._id;
|
|
715
717
|
const compositionName = comp._name ?? compositionId;
|
|
716
718
|
const compositionType = comp.type;
|
|
717
|
-
const
|
|
719
|
+
const compSourceItem = comp.parameters?.sourceItem?.value;
|
|
720
|
+
const existingEntryPath = existingEntryMap.get(compositionId) ?? (compSourceItem != null ? existingEntryMap.get(String(compSourceItem)) : void 0);
|
|
718
721
|
let entry;
|
|
719
722
|
let isExistingEntry = false;
|
|
720
723
|
if (existingEntryPath) {
|
|
@@ -723,7 +726,7 @@ var CompositionConverterService = class {
|
|
|
723
726
|
entry = existingEntry;
|
|
724
727
|
isExistingEntry = true;
|
|
725
728
|
this.logger.info(
|
|
726
|
-
`Found existing entry "${
|
|
729
|
+
`Found existing entry "${existingEntry.entry._id}" \u2014 merging references and blocks`
|
|
727
730
|
);
|
|
728
731
|
} else {
|
|
729
732
|
entry = this.generateEntryFromComposition(composition);
|
|
@@ -1148,11 +1151,57 @@ var CompositionConverterService = class {
|
|
|
1148
1151
|
return sourceItemMap.get(String(sourceItemParam.value));
|
|
1149
1152
|
}
|
|
1150
1153
|
// --- Utilities ---
|
|
1154
|
+
matchesType(instanceType, pattern, strict) {
|
|
1155
|
+
if (!pattern.includes("*")) {
|
|
1156
|
+
return strict ? instanceType === pattern : instanceType.toLowerCase() === pattern.toLowerCase();
|
|
1157
|
+
}
|
|
1158
|
+
const flags = strict ? "" : "i";
|
|
1159
|
+
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
1160
|
+
const regex = new RegExp(`^${escaped}$`, flags);
|
|
1161
|
+
return regex.test(instanceType);
|
|
1162
|
+
}
|
|
1151
1163
|
compareTypes(type1, type2, strict) {
|
|
1152
|
-
if (strict)
|
|
1153
|
-
|
|
1164
|
+
if (type1.includes("*")) return this.matchesType(type2, type1, strict);
|
|
1165
|
+
if (type2.includes("*")) return this.matchesType(type1, type2, strict);
|
|
1166
|
+
return strict ? type1 === type2 : type1.toLowerCase() === type2.toLowerCase();
|
|
1167
|
+
}
|
|
1168
|
+
expandWildcardTypes(compositionResults, patterns, strict) {
|
|
1169
|
+
const expanded = [];
|
|
1170
|
+
for (const pattern of patterns) {
|
|
1171
|
+
if (!pattern.includes("*")) {
|
|
1172
|
+
expanded.push(pattern);
|
|
1173
|
+
continue;
|
|
1174
|
+
}
|
|
1175
|
+
const matched = /* @__PURE__ */ new Set();
|
|
1176
|
+
for (const { composition } of compositionResults) {
|
|
1177
|
+
if (composition.composition.slots) {
|
|
1178
|
+
this.collectMatchingTypes(composition.composition.slots, pattern, strict, matched);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
if (matched.size === 0) {
|
|
1182
|
+
this.logger.warn(`Wildcard pattern "${pattern}" did not match any component types`);
|
|
1183
|
+
} else {
|
|
1184
|
+
this.logger.info(`Wildcard "${pattern}" expanded to: ${[...matched].join(", ")}`);
|
|
1185
|
+
}
|
|
1186
|
+
for (const type of matched) {
|
|
1187
|
+
expanded.push(type);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
return [...new Set(expanded)];
|
|
1191
|
+
}
|
|
1192
|
+
collectMatchingTypes(slots, pattern, strict, matched) {
|
|
1193
|
+
for (const instances of Object.values(slots)) {
|
|
1194
|
+
if (!Array.isArray(instances)) continue;
|
|
1195
|
+
for (const instance of instances) {
|
|
1196
|
+
if (instance._pattern) continue;
|
|
1197
|
+
if (this.matchesType(instance.type, pattern, strict)) {
|
|
1198
|
+
matched.add(instance.type);
|
|
1199
|
+
}
|
|
1200
|
+
if (instance.slots) {
|
|
1201
|
+
this.collectMatchingTypes(instance.slots, pattern, strict, matched);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1154
1204
|
}
|
|
1155
|
-
return type1.toLowerCase() === type2.toLowerCase();
|
|
1156
1205
|
}
|
|
1157
1206
|
truncate(str, maxLength) {
|
|
1158
1207
|
if (str.length <= maxLength) return str;
|
|
@@ -1269,8 +1318,16 @@ var PropertyPropagatorService = class {
|
|
|
1269
1318
|
const sourceComponents = [];
|
|
1270
1319
|
for (const sourceType of compositionTypes) {
|
|
1271
1320
|
this.logger.info(`Loading component: ${sourceType}`);
|
|
1272
|
-
|
|
1273
|
-
|
|
1321
|
+
try {
|
|
1322
|
+
const { component: sourceComponent, filePath: sourceFilePath } = await this.componentService.loadComponent(fullComponentsDir, sourceType, findOptions);
|
|
1323
|
+
sourceComponents.push({ sourceType, sourceFilePath, sourceComponent });
|
|
1324
|
+
} catch (error) {
|
|
1325
|
+
if (error instanceof ComponentNotFoundError) {
|
|
1326
|
+
this.logger.warn(`Component not found: ${sourceType} (searched: ${fullComponentsDir})`);
|
|
1327
|
+
continue;
|
|
1328
|
+
}
|
|
1329
|
+
throw error;
|
|
1330
|
+
}
|
|
1274
1331
|
}
|
|
1275
1332
|
this.logger.info(`Loading component: ${targetComponentType}`);
|
|
1276
1333
|
const { component: targetComponent, filePath: targetFilePath } = await this.componentService.loadComponent(fullComponentsDir, targetComponentType, findOptions);
|