@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/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,6 +630,8 @@ 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);
|
|
@@ -724,7 +726,8 @@ var CompositionConverterService = class {
|
|
|
724
726
|
const compositionId = comp._id;
|
|
725
727
|
const compositionName = comp._name ?? compositionId;
|
|
726
728
|
const compositionType = comp.type;
|
|
727
|
-
const
|
|
729
|
+
const compSourceItem = comp.parameters?.sourceItem?.value;
|
|
730
|
+
const existingEntryPath = existingEntryMap.get(compositionId) ?? (compSourceItem != null ? existingEntryMap.get(String(compSourceItem)) : void 0);
|
|
728
731
|
let entry;
|
|
729
732
|
let isExistingEntry = false;
|
|
730
733
|
if (existingEntryPath) {
|
|
@@ -733,7 +736,7 @@ var CompositionConverterService = class {
|
|
|
733
736
|
entry = existingEntry;
|
|
734
737
|
isExistingEntry = true;
|
|
735
738
|
this.logger.info(
|
|
736
|
-
`Found existing entry "${
|
|
739
|
+
`Found existing entry "${existingEntry.entry._id}" \u2014 merging references and blocks`
|
|
737
740
|
);
|
|
738
741
|
} else {
|
|
739
742
|
entry = this.generateEntryFromComposition(composition);
|
|
@@ -1158,11 +1161,57 @@ var CompositionConverterService = class {
|
|
|
1158
1161
|
return sourceItemMap.get(String(sourceItemParam.value));
|
|
1159
1162
|
}
|
|
1160
1163
|
// --- Utilities ---
|
|
1164
|
+
matchesType(instanceType, pattern, strict) {
|
|
1165
|
+
if (!pattern.includes("*")) {
|
|
1166
|
+
return strict ? instanceType === pattern : instanceType.toLowerCase() === pattern.toLowerCase();
|
|
1167
|
+
}
|
|
1168
|
+
const flags = strict ? "" : "i";
|
|
1169
|
+
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
1170
|
+
const regex = new RegExp(`^${escaped}$`, flags);
|
|
1171
|
+
return regex.test(instanceType);
|
|
1172
|
+
}
|
|
1161
1173
|
compareTypes(type1, type2, strict) {
|
|
1162
|
-
if (strict)
|
|
1163
|
-
|
|
1174
|
+
if (type1.includes("*")) return this.matchesType(type2, type1, strict);
|
|
1175
|
+
if (type2.includes("*")) return this.matchesType(type1, type2, strict);
|
|
1176
|
+
return strict ? type1 === type2 : type1.toLowerCase() === type2.toLowerCase();
|
|
1177
|
+
}
|
|
1178
|
+
expandWildcardTypes(compositionResults, patterns, strict) {
|
|
1179
|
+
const expanded = [];
|
|
1180
|
+
for (const pattern of patterns) {
|
|
1181
|
+
if (!pattern.includes("*")) {
|
|
1182
|
+
expanded.push(pattern);
|
|
1183
|
+
continue;
|
|
1184
|
+
}
|
|
1185
|
+
const matched = /* @__PURE__ */ new Set();
|
|
1186
|
+
for (const { composition } of compositionResults) {
|
|
1187
|
+
if (composition.composition.slots) {
|
|
1188
|
+
this.collectMatchingTypes(composition.composition.slots, pattern, strict, matched);
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
if (matched.size === 0) {
|
|
1192
|
+
this.logger.warn(`Wildcard pattern "${pattern}" did not match any component types`);
|
|
1193
|
+
} else {
|
|
1194
|
+
this.logger.info(`Wildcard "${pattern}" expanded to: ${[...matched].join(", ")}`);
|
|
1195
|
+
}
|
|
1196
|
+
for (const type of matched) {
|
|
1197
|
+
expanded.push(type);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
return [...new Set(expanded)];
|
|
1201
|
+
}
|
|
1202
|
+
collectMatchingTypes(slots, pattern, strict, matched) {
|
|
1203
|
+
for (const instances of Object.values(slots)) {
|
|
1204
|
+
if (!Array.isArray(instances)) continue;
|
|
1205
|
+
for (const instance of instances) {
|
|
1206
|
+
if (instance._pattern) continue;
|
|
1207
|
+
if (this.matchesType(instance.type, pattern, strict)) {
|
|
1208
|
+
matched.add(instance.type);
|
|
1209
|
+
}
|
|
1210
|
+
if (instance.slots) {
|
|
1211
|
+
this.collectMatchingTypes(instance.slots, pattern, strict, matched);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1164
1214
|
}
|
|
1165
|
-
return type1.toLowerCase() === type2.toLowerCase();
|
|
1166
1215
|
}
|
|
1167
1216
|
truncate(str, maxLength) {
|
|
1168
1217
|
if (str.length <= maxLength) return str;
|
|
@@ -1279,8 +1328,16 @@ var PropertyPropagatorService = class {
|
|
|
1279
1328
|
const sourceComponents = [];
|
|
1280
1329
|
for (const sourceType of compositionTypes) {
|
|
1281
1330
|
this.logger.info(`Loading component: ${sourceType}`);
|
|
1282
|
-
|
|
1283
|
-
|
|
1331
|
+
try {
|
|
1332
|
+
const { component: sourceComponent, filePath: sourceFilePath } = await this.componentService.loadComponent(fullComponentsDir, sourceType, findOptions);
|
|
1333
|
+
sourceComponents.push({ sourceType, sourceFilePath, sourceComponent });
|
|
1334
|
+
} catch (error) {
|
|
1335
|
+
if (error instanceof ComponentNotFoundError) {
|
|
1336
|
+
this.logger.warn(`Component not found: ${sourceType} (searched: ${fullComponentsDir})`);
|
|
1337
|
+
continue;
|
|
1338
|
+
}
|
|
1339
|
+
throw error;
|
|
1340
|
+
}
|
|
1284
1341
|
}
|
|
1285
1342
|
this.logger.info(`Loading component: ${targetComponentType}`);
|
|
1286
1343
|
const { component: targetComponent, filePath: targetFilePath } = await this.componentService.loadComponent(fullComponentsDir, targetComponentType, findOptions);
|
|
@@ -4060,8 +4117,16 @@ var SlotPropagatorService = class {
|
|
|
4060
4117
|
const sourceComponents = [];
|
|
4061
4118
|
for (const sourceType of compositionTypes) {
|
|
4062
4119
|
this.logger.info(`Loading component: ${sourceType}`);
|
|
4063
|
-
|
|
4064
|
-
|
|
4120
|
+
try {
|
|
4121
|
+
const { component: sourceComponent, filePath: sourceFilePath } = await this.componentService.loadComponent(fullComponentsDir, sourceType, findOptions);
|
|
4122
|
+
sourceComponents.push({ sourceType, sourceFilePath, sourceComponent });
|
|
4123
|
+
} catch (error) {
|
|
4124
|
+
if (error instanceof ComponentNotFoundError) {
|
|
4125
|
+
this.logger.warn(`Component not found: ${sourceType} (searched: ${fullComponentsDir})`);
|
|
4126
|
+
continue;
|
|
4127
|
+
}
|
|
4128
|
+
throw error;
|
|
4129
|
+
}
|
|
4065
4130
|
}
|
|
4066
4131
|
this.logger.info(`Loading component: ${targetComponentType}`);
|
|
4067
4132
|
const { component: targetComponent, filePath: targetFilePath } = await this.componentService.loadComponent(fullComponentsDir, targetComponentType, findOptions);
|
|
@@ -4949,7 +5014,7 @@ function createRemoveFieldCommand() {
|
|
|
4949
5014
|
// package.json
|
|
4950
5015
|
var package_default = {
|
|
4951
5016
|
name: "@uniformdev/transformer",
|
|
4952
|
-
version: "1.1.
|
|
5017
|
+
version: "1.1.28",
|
|
4953
5018
|
description: "CLI tool for transforming Uniform.dev serialization files offline",
|
|
4954
5019
|
type: "module",
|
|
4955
5020
|
bin: {
|