@uniformdev/transformer 1.1.24 → 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/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
@@ -582,11 +582,13 @@ var CompositionConverterService = class {
582
582
  contentTypesDir,
583
583
  entriesDir,
584
584
  compositionTypes,
585
- componentsToReferences,
586
- componentsToBlocks,
585
+ componentsToReferences: rawComponentsToReferences,
586
+ componentsToBlocks: rawComponentsToBlocks,
587
587
  whatIf,
588
588
  strict
589
589
  } = options;
590
+ const componentsToReferences = [...new Set(rawComponentsToReferences)];
591
+ const componentsToBlocks = [...new Set(rawComponentsToBlocks)];
590
592
  const compositionsDirFull = this.fileSystem.resolvePath(rootDir, compositionsDir);
591
593
  const componentsDirFull = this.fileSystem.resolvePath(rootDir, componentsDir);
592
594
  const contentTypesDirFull = this.fileSystem.resolvePath(rootDir, contentTypesDir);
@@ -607,6 +609,7 @@ var CompositionConverterService = class {
607
609
  if (sourceItemMap.size > 0) {
608
610
  this.logger.info(`Found ${sourceItemMap.size} existing entry(ies) with sourceItem values`);
609
611
  }
612
+ const existingEntryMap = await this.buildEntryIdMap(entriesDirFull);
610
613
  const compositionResults = await this.compositionService.findCompositionsByTypes(
611
614
  compositionsDirFull,
612
615
  compositionTypes,
@@ -711,7 +714,23 @@ var CompositionConverterService = class {
711
714
  const compositionId = comp._id;
712
715
  const compositionName = comp._name ?? compositionId;
713
716
  const compositionType = comp.type;
714
- const entry = this.generateEntryFromComposition(composition);
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
+ }
715
734
  const refsByType = /* @__PURE__ */ new Map();
716
735
  if (componentsToReferences.length > 0 && comp.slots) {
717
736
  for (const refType of componentsToReferences) {
@@ -791,21 +810,33 @@ var CompositionConverterService = class {
791
810
  blocksEmbedded += instances.length;
792
811
  }
793
812
  const entryId = entry.entry._id;
794
- const entryFilePath = this.fileSystem.joinPath(entriesDirFull, `${entryId}.json`);
795
- this.logger.action(
796
- whatIf,
797
- "WRITE",
798
- `${entriesDir}/${entryId}.json (${compositionType}, "${this.truncate(compositionName, 50)}")`
799
- );
800
- if (!whatIf) {
801
- await this.fileSystem.writeFile(entryFilePath, entry);
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++;
802
834
  }
803
- entriesFromCompositions++;
804
835
  for (const [refType, instances] of refsByType) {
805
836
  for (const inst of instances) {
806
837
  const existingId = this.findExistingEntryBySourceItem(inst, sourceItemMap);
807
838
  if (existingId) {
808
- const existingEntryPath = this.fileSystem.joinPath(
839
+ const existingEntryPath2 = this.fileSystem.joinPath(
809
840
  entriesDirFull,
810
841
  `${existingId}.json`
811
842
  );
@@ -815,14 +846,14 @@ var CompositionConverterService = class {
815
846
  `${entriesDir}/${existingId}.json (${refType}, merged fields from "${this.truncate(compositionName, 50)}")`
816
847
  );
817
848
  if (!whatIf) {
818
- const existingEntry = await this.fileSystem.readFile(existingEntryPath);
849
+ const existingEntry = await this.fileSystem.readFile(existingEntryPath2);
819
850
  if (existingEntry?.entry) {
820
851
  const instanceFields = inst.instance.parameters ?? {};
821
852
  existingEntry.entry.fields = {
822
853
  ...existingEntry.entry.fields,
823
854
  ...instanceFields
824
855
  };
825
- await this.fileSystem.writeFile(existingEntryPath, existingEntry);
856
+ await this.fileSystem.writeFile(existingEntryPath2, existingEntry);
826
857
  }
827
858
  }
828
859
  entriesReused++;
@@ -1078,6 +1109,21 @@ var CompositionConverterService = class {
1078
1109
  }
1079
1110
  }
1080
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
+ }
1081
1127
  async buildSourceItemMap(entriesDirFull) {
1082
1128
  const sourceItemMap = /* @__PURE__ */ new Map();
1083
1129
  const entryFiles = await this.fileSystem.findFiles(entriesDirFull, "*.json");