@uniformdev/transformer 1.1.27 → 1.1.29
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 +77 -20
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +76 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -597,8 +597,8 @@ var CompositionConverterService = class {
|
|
|
597
597
|
whatIf,
|
|
598
598
|
strict
|
|
599
599
|
} = options;
|
|
600
|
-
const
|
|
601
|
-
const
|
|
600
|
+
const initialComponentsToReferences = [...new Set(rawComponentsToReferences)];
|
|
601
|
+
const initialComponentsToBlocks = [...new Set(rawComponentsToBlocks)];
|
|
602
602
|
const compositionsDirFull = this.fileSystem.resolvePath(rootDir, compositionsDir);
|
|
603
603
|
const componentsDirFull = this.fileSystem.resolvePath(rootDir, componentsDir);
|
|
604
604
|
const contentTypesDirFull = this.fileSystem.resolvePath(rootDir, contentTypesDir);
|
|
@@ -609,13 +609,13 @@ var CompositionConverterService = class {
|
|
|
609
609
|
let entriesReused = 0;
|
|
610
610
|
let blocksEmbedded = 0;
|
|
611
611
|
this.logger.info(`Composition types: ${compositionTypes.join(", ")}`);
|
|
612
|
-
if (
|
|
613
|
-
this.logger.info(`Components to references: ${
|
|
612
|
+
if (initialComponentsToReferences.length > 0) {
|
|
613
|
+
this.logger.info(`Components to references: ${initialComponentsToReferences.join(", ")}`);
|
|
614
614
|
}
|
|
615
|
-
if (
|
|
616
|
-
this.logger.info(`Components to blocks: ${
|
|
615
|
+
if (initialComponentsToBlocks.length > 0) {
|
|
616
|
+
this.logger.info(`Components to blocks: ${initialComponentsToBlocks.join(", ")}`);
|
|
617
617
|
}
|
|
618
|
-
const sourceItemMap =
|
|
618
|
+
const sourceItemMap = initialComponentsToReferences.length > 0 ? await this.buildSourceItemMap(entriesDirFull) : /* @__PURE__ */ new Map();
|
|
619
619
|
if (sourceItemMap.size > 0) {
|
|
620
620
|
this.logger.info(`Found ${sourceItemMap.size} existing entry(ies) with sourceItem values`);
|
|
621
621
|
}
|
|
@@ -630,19 +630,29 @@ var CompositionConverterService = class {
|
|
|
630
630
|
return { contentTypesWritten: 0, entriesFromCompositions: 0, entriesFromReferences: 0, entriesReused: 0, blocksEmbedded: 0 };
|
|
631
631
|
}
|
|
632
632
|
this.logger.info(`Found ${compositionResults.length} composition(s)`);
|
|
633
|
+
const componentsToReferences = this.expandWildcardTypes(compositionResults, initialComponentsToReferences, strict);
|
|
634
|
+
const componentsToBlocks = this.expandWildcardTypes(compositionResults, initialComponentsToBlocks, strict);
|
|
633
635
|
const rootComponentTypes = /* @__PURE__ */ new Set();
|
|
634
636
|
for (const { composition } of compositionResults) {
|
|
635
637
|
rootComponentTypes.add(composition.composition.type);
|
|
636
638
|
}
|
|
637
639
|
const contentTypeMap = /* @__PURE__ */ new Map();
|
|
638
640
|
for (const rootType of rootComponentTypes) {
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
641
|
+
try {
|
|
642
|
+
const { component } = await this.componentService.loadComponent(
|
|
643
|
+
componentsDirFull,
|
|
644
|
+
rootType,
|
|
645
|
+
{ strict }
|
|
646
|
+
);
|
|
647
|
+
const contentType = this.generateContentType(component);
|
|
648
|
+
contentTypeMap.set(rootType, contentType);
|
|
649
|
+
} catch (error) {
|
|
650
|
+
if (error instanceof ComponentNotFoundError) {
|
|
651
|
+
this.logger.warn(`Component not found: ${rootType} \u2014 skipping content type generation`);
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
throw error;
|
|
655
|
+
}
|
|
646
656
|
}
|
|
647
657
|
const allTargetTypes = [.../* @__PURE__ */ new Set([...componentsToReferences, ...componentsToBlocks])];
|
|
648
658
|
const targetContentTypeMap = /* @__PURE__ */ new Map();
|
|
@@ -724,7 +734,8 @@ var CompositionConverterService = class {
|
|
|
724
734
|
const compositionId = comp._id;
|
|
725
735
|
const compositionName = comp._name ?? compositionId;
|
|
726
736
|
const compositionType = comp.type;
|
|
727
|
-
const
|
|
737
|
+
const compSourceItem = comp.parameters?.sourceItem?.value;
|
|
738
|
+
const existingEntryPath = existingEntryMap.get(compositionId) ?? (compSourceItem != null ? existingEntryMap.get(String(compSourceItem)) : void 0);
|
|
728
739
|
let entry;
|
|
729
740
|
let isExistingEntry = false;
|
|
730
741
|
if (existingEntryPath) {
|
|
@@ -733,7 +744,7 @@ var CompositionConverterService = class {
|
|
|
733
744
|
entry = existingEntry;
|
|
734
745
|
isExistingEntry = true;
|
|
735
746
|
this.logger.info(
|
|
736
|
-
`Found existing entry "${
|
|
747
|
+
`Found existing entry "${existingEntry.entry._id}" \u2014 merging references and blocks`
|
|
737
748
|
);
|
|
738
749
|
} else {
|
|
739
750
|
entry = this.generateEntryFromComposition(composition);
|
|
@@ -1158,11 +1169,57 @@ var CompositionConverterService = class {
|
|
|
1158
1169
|
return sourceItemMap.get(String(sourceItemParam.value));
|
|
1159
1170
|
}
|
|
1160
1171
|
// --- Utilities ---
|
|
1172
|
+
matchesType(instanceType, pattern, strict) {
|
|
1173
|
+
if (!pattern.includes("*")) {
|
|
1174
|
+
return strict ? instanceType === pattern : instanceType.toLowerCase() === pattern.toLowerCase();
|
|
1175
|
+
}
|
|
1176
|
+
const flags = strict ? "" : "i";
|
|
1177
|
+
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
1178
|
+
const regex = new RegExp(`^${escaped}$`, flags);
|
|
1179
|
+
return regex.test(instanceType);
|
|
1180
|
+
}
|
|
1161
1181
|
compareTypes(type1, type2, strict) {
|
|
1162
|
-
if (strict)
|
|
1163
|
-
|
|
1182
|
+
if (type1.includes("*")) return this.matchesType(type2, type1, strict);
|
|
1183
|
+
if (type2.includes("*")) return this.matchesType(type1, type2, strict);
|
|
1184
|
+
return strict ? type1 === type2 : type1.toLowerCase() === type2.toLowerCase();
|
|
1185
|
+
}
|
|
1186
|
+
expandWildcardTypes(compositionResults, patterns, strict) {
|
|
1187
|
+
const expanded = [];
|
|
1188
|
+
for (const pattern of patterns) {
|
|
1189
|
+
if (!pattern.includes("*")) {
|
|
1190
|
+
expanded.push(pattern);
|
|
1191
|
+
continue;
|
|
1192
|
+
}
|
|
1193
|
+
const matched = /* @__PURE__ */ new Set();
|
|
1194
|
+
for (const { composition } of compositionResults) {
|
|
1195
|
+
if (composition.composition.slots) {
|
|
1196
|
+
this.collectMatchingTypes(composition.composition.slots, pattern, strict, matched);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
if (matched.size === 0) {
|
|
1200
|
+
this.logger.warn(`Wildcard pattern "${pattern}" did not match any component types`);
|
|
1201
|
+
} else {
|
|
1202
|
+
this.logger.info(`Wildcard "${pattern}" expanded to: ${[...matched].join(", ")}`);
|
|
1203
|
+
}
|
|
1204
|
+
for (const type of matched) {
|
|
1205
|
+
expanded.push(type);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
return [...new Set(expanded)];
|
|
1209
|
+
}
|
|
1210
|
+
collectMatchingTypes(slots, pattern, strict, matched) {
|
|
1211
|
+
for (const instances of Object.values(slots)) {
|
|
1212
|
+
if (!Array.isArray(instances)) continue;
|
|
1213
|
+
for (const instance of instances) {
|
|
1214
|
+
if (instance._pattern) continue;
|
|
1215
|
+
if (this.matchesType(instance.type, pattern, strict)) {
|
|
1216
|
+
matched.add(instance.type);
|
|
1217
|
+
}
|
|
1218
|
+
if (instance.slots) {
|
|
1219
|
+
this.collectMatchingTypes(instance.slots, pattern, strict, matched);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1164
1222
|
}
|
|
1165
|
-
return type1.toLowerCase() === type2.toLowerCase();
|
|
1166
1223
|
}
|
|
1167
1224
|
truncate(str, maxLength) {
|
|
1168
1225
|
if (str.length <= maxLength) return str;
|
|
@@ -4965,7 +5022,7 @@ function createRemoveFieldCommand() {
|
|
|
4965
5022
|
// package.json
|
|
4966
5023
|
var package_default = {
|
|
4967
5024
|
name: "@uniformdev/transformer",
|
|
4968
|
-
version: "1.1.
|
|
5025
|
+
version: "1.1.29",
|
|
4969
5026
|
description: "CLI tool for transforming Uniform.dev serialization files offline",
|
|
4970
5027
|
type: "module",
|
|
4971
5028
|
bin: {
|