@uniformdev/transformer 1.1.25 → 1.1.26
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 +58 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +57 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -481,6 +481,7 @@ declare class CompositionConverterService {
|
|
|
481
481
|
findFlattenTargets(slots: Record<string, ComponentInstance[]>, targetType: string, compositionId: string, compositionName: string, strict: boolean): FlattenedInstance[];
|
|
482
482
|
private walkSlots;
|
|
483
483
|
private transformContentReferences;
|
|
484
|
+
buildEntryIdMap(entriesDirFull: string): Promise<Map<string, string>>;
|
|
484
485
|
buildSourceItemMap(entriesDirFull: string): Promise<Map<string, string>>;
|
|
485
486
|
private findExistingEntryBySourceItem;
|
|
486
487
|
private compareTypes;
|
package/dist/index.js
CHANGED
|
@@ -609,6 +609,7 @@ var CompositionConverterService = class {
|
|
|
609
609
|
if (sourceItemMap.size > 0) {
|
|
610
610
|
this.logger.info(`Found ${sourceItemMap.size} existing entry(ies) with sourceItem values`);
|
|
611
611
|
}
|
|
612
|
+
const existingEntryMap = await this.buildEntryIdMap(entriesDirFull);
|
|
612
613
|
const compositionResults = await this.compositionService.findCompositionsByTypes(
|
|
613
614
|
compositionsDirFull,
|
|
614
615
|
compositionTypes,
|
|
@@ -713,7 +714,23 @@ var CompositionConverterService = class {
|
|
|
713
714
|
const compositionId = comp._id;
|
|
714
715
|
const compositionName = comp._name ?? compositionId;
|
|
715
716
|
const compositionType = comp.type;
|
|
716
|
-
const
|
|
717
|
+
const existingEntryPath = existingEntryMap.get(compositionId);
|
|
718
|
+
let entry;
|
|
719
|
+
let isExistingEntry = false;
|
|
720
|
+
if (existingEntryPath) {
|
|
721
|
+
const existingEntry = await this.fileSystem.readFile(existingEntryPath);
|
|
722
|
+
if (existingEntry?.entry) {
|
|
723
|
+
entry = existingEntry;
|
|
724
|
+
isExistingEntry = true;
|
|
725
|
+
this.logger.info(
|
|
726
|
+
`Found existing entry "${compositionId}" \u2014 merging references and blocks`
|
|
727
|
+
);
|
|
728
|
+
} else {
|
|
729
|
+
entry = this.generateEntryFromComposition(composition);
|
|
730
|
+
}
|
|
731
|
+
} else {
|
|
732
|
+
entry = this.generateEntryFromComposition(composition);
|
|
733
|
+
}
|
|
717
734
|
const refsByType = /* @__PURE__ */ new Map();
|
|
718
735
|
if (componentsToReferences.length > 0 && comp.slots) {
|
|
719
736
|
for (const refType of componentsToReferences) {
|
|
@@ -793,21 +810,33 @@ var CompositionConverterService = class {
|
|
|
793
810
|
blocksEmbedded += instances.length;
|
|
794
811
|
}
|
|
795
812
|
const entryId = entry.entry._id;
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
813
|
+
if (isExistingEntry) {
|
|
814
|
+
this.logger.action(
|
|
815
|
+
whatIf,
|
|
816
|
+
"UPDATE",
|
|
817
|
+
`${entriesDir}/${entryId}.json (${compositionType}, merged refs/blocks from "${this.truncate(compositionName, 50)}")`
|
|
818
|
+
);
|
|
819
|
+
if (!whatIf) {
|
|
820
|
+
await this.fileSystem.writeFile(existingEntryPath, entry);
|
|
821
|
+
}
|
|
822
|
+
entriesReused++;
|
|
823
|
+
} else {
|
|
824
|
+
const entryFilePath = this.fileSystem.joinPath(entriesDirFull, `${entryId}.json`);
|
|
825
|
+
this.logger.action(
|
|
826
|
+
whatIf,
|
|
827
|
+
"WRITE",
|
|
828
|
+
`${entriesDir}/${entryId}.json (${compositionType}, "${this.truncate(compositionName, 50)}")`
|
|
829
|
+
);
|
|
830
|
+
if (!whatIf) {
|
|
831
|
+
await this.fileSystem.writeFile(entryFilePath, entry);
|
|
832
|
+
}
|
|
833
|
+
entriesFromCompositions++;
|
|
804
834
|
}
|
|
805
|
-
entriesFromCompositions++;
|
|
806
835
|
for (const [refType, instances] of refsByType) {
|
|
807
836
|
for (const inst of instances) {
|
|
808
837
|
const existingId = this.findExistingEntryBySourceItem(inst, sourceItemMap);
|
|
809
838
|
if (existingId) {
|
|
810
|
-
const
|
|
839
|
+
const existingEntryPath2 = this.fileSystem.joinPath(
|
|
811
840
|
entriesDirFull,
|
|
812
841
|
`${existingId}.json`
|
|
813
842
|
);
|
|
@@ -817,14 +846,14 @@ var CompositionConverterService = class {
|
|
|
817
846
|
`${entriesDir}/${existingId}.json (${refType}, merged fields from "${this.truncate(compositionName, 50)}")`
|
|
818
847
|
);
|
|
819
848
|
if (!whatIf) {
|
|
820
|
-
const existingEntry = await this.fileSystem.readFile(
|
|
849
|
+
const existingEntry = await this.fileSystem.readFile(existingEntryPath2);
|
|
821
850
|
if (existingEntry?.entry) {
|
|
822
851
|
const instanceFields = inst.instance.parameters ?? {};
|
|
823
852
|
existingEntry.entry.fields = {
|
|
824
853
|
...existingEntry.entry.fields,
|
|
825
854
|
...instanceFields
|
|
826
855
|
};
|
|
827
|
-
await this.fileSystem.writeFile(
|
|
856
|
+
await this.fileSystem.writeFile(existingEntryPath2, existingEntry);
|
|
828
857
|
}
|
|
829
858
|
}
|
|
830
859
|
entriesReused++;
|
|
@@ -1080,6 +1109,21 @@ var CompositionConverterService = class {
|
|
|
1080
1109
|
}
|
|
1081
1110
|
}
|
|
1082
1111
|
// --- Source Item Matching ---
|
|
1112
|
+
async buildEntryIdMap(entriesDirFull) {
|
|
1113
|
+
const entryIdMap = /* @__PURE__ */ new Map();
|
|
1114
|
+
const entryFiles = await this.fileSystem.findFiles(entriesDirFull, "*.json");
|
|
1115
|
+
for (const filePath of entryFiles) {
|
|
1116
|
+
try {
|
|
1117
|
+
const entryData = await this.fileSystem.readFile(filePath);
|
|
1118
|
+
if (entryData?.entry?._id) {
|
|
1119
|
+
entryIdMap.set(entryData.entry._id, filePath);
|
|
1120
|
+
}
|
|
1121
|
+
} catch {
|
|
1122
|
+
continue;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
return entryIdMap;
|
|
1126
|
+
}
|
|
1083
1127
|
async buildSourceItemMap(entriesDirFull) {
|
|
1084
1128
|
const sourceItemMap = /* @__PURE__ */ new Map();
|
|
1085
1129
|
const entryFiles = await this.fileSystem.findFiles(entriesDirFull, "*.json");
|