@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/cli/index.js CHANGED
@@ -592,11 +592,13 @@ var CompositionConverterService = class {
592
592
  contentTypesDir,
593
593
  entriesDir,
594
594
  compositionTypes,
595
- componentsToReferences,
596
- componentsToBlocks,
595
+ componentsToReferences: rawComponentsToReferences,
596
+ componentsToBlocks: rawComponentsToBlocks,
597
597
  whatIf,
598
598
  strict
599
599
  } = options;
600
+ const componentsToReferences = [...new Set(rawComponentsToReferences)];
601
+ const componentsToBlocks = [...new Set(rawComponentsToBlocks)];
600
602
  const compositionsDirFull = this.fileSystem.resolvePath(rootDir, compositionsDir);
601
603
  const componentsDirFull = this.fileSystem.resolvePath(rootDir, componentsDir);
602
604
  const contentTypesDirFull = this.fileSystem.resolvePath(rootDir, contentTypesDir);
@@ -617,6 +619,7 @@ var CompositionConverterService = class {
617
619
  if (sourceItemMap.size > 0) {
618
620
  this.logger.info(`Found ${sourceItemMap.size} existing entry(ies) with sourceItem values`);
619
621
  }
622
+ const existingEntryMap = await this.buildEntryIdMap(entriesDirFull);
620
623
  const compositionResults = await this.compositionService.findCompositionsByTypes(
621
624
  compositionsDirFull,
622
625
  compositionTypes,
@@ -721,7 +724,23 @@ var CompositionConverterService = class {
721
724
  const compositionId = comp._id;
722
725
  const compositionName = comp._name ?? compositionId;
723
726
  const compositionType = comp.type;
724
- const entry = this.generateEntryFromComposition(composition);
727
+ const existingEntryPath = existingEntryMap.get(compositionId);
728
+ let entry;
729
+ let isExistingEntry = false;
730
+ if (existingEntryPath) {
731
+ const existingEntry = await this.fileSystem.readFile(existingEntryPath);
732
+ if (existingEntry?.entry) {
733
+ entry = existingEntry;
734
+ isExistingEntry = true;
735
+ this.logger.info(
736
+ `Found existing entry "${compositionId}" \u2014 merging references and blocks`
737
+ );
738
+ } else {
739
+ entry = this.generateEntryFromComposition(composition);
740
+ }
741
+ } else {
742
+ entry = this.generateEntryFromComposition(composition);
743
+ }
725
744
  const refsByType = /* @__PURE__ */ new Map();
726
745
  if (componentsToReferences.length > 0 && comp.slots) {
727
746
  for (const refType of componentsToReferences) {
@@ -801,21 +820,33 @@ var CompositionConverterService = class {
801
820
  blocksEmbedded += instances.length;
802
821
  }
803
822
  const entryId = entry.entry._id;
804
- const entryFilePath = this.fileSystem.joinPath(entriesDirFull, `${entryId}.json`);
805
- this.logger.action(
806
- whatIf,
807
- "WRITE",
808
- `${entriesDir}/${entryId}.json (${compositionType}, "${this.truncate(compositionName, 50)}")`
809
- );
810
- if (!whatIf) {
811
- await this.fileSystem.writeFile(entryFilePath, entry);
823
+ if (isExistingEntry) {
824
+ this.logger.action(
825
+ whatIf,
826
+ "UPDATE",
827
+ `${entriesDir}/${entryId}.json (${compositionType}, merged refs/blocks from "${this.truncate(compositionName, 50)}")`
828
+ );
829
+ if (!whatIf) {
830
+ await this.fileSystem.writeFile(existingEntryPath, entry);
831
+ }
832
+ entriesReused++;
833
+ } else {
834
+ const entryFilePath = this.fileSystem.joinPath(entriesDirFull, `${entryId}.json`);
835
+ this.logger.action(
836
+ whatIf,
837
+ "WRITE",
838
+ `${entriesDir}/${entryId}.json (${compositionType}, "${this.truncate(compositionName, 50)}")`
839
+ );
840
+ if (!whatIf) {
841
+ await this.fileSystem.writeFile(entryFilePath, entry);
842
+ }
843
+ entriesFromCompositions++;
812
844
  }
813
- entriesFromCompositions++;
814
845
  for (const [refType, instances] of refsByType) {
815
846
  for (const inst of instances) {
816
847
  const existingId = this.findExistingEntryBySourceItem(inst, sourceItemMap);
817
848
  if (existingId) {
818
- const existingEntryPath = this.fileSystem.joinPath(
849
+ const existingEntryPath2 = this.fileSystem.joinPath(
819
850
  entriesDirFull,
820
851
  `${existingId}.json`
821
852
  );
@@ -825,14 +856,14 @@ var CompositionConverterService = class {
825
856
  `${entriesDir}/${existingId}.json (${refType}, merged fields from "${this.truncate(compositionName, 50)}")`
826
857
  );
827
858
  if (!whatIf) {
828
- const existingEntry = await this.fileSystem.readFile(existingEntryPath);
859
+ const existingEntry = await this.fileSystem.readFile(existingEntryPath2);
829
860
  if (existingEntry?.entry) {
830
861
  const instanceFields = inst.instance.parameters ?? {};
831
862
  existingEntry.entry.fields = {
832
863
  ...existingEntry.entry.fields,
833
864
  ...instanceFields
834
865
  };
835
- await this.fileSystem.writeFile(existingEntryPath, existingEntry);
866
+ await this.fileSystem.writeFile(existingEntryPath2, existingEntry);
836
867
  }
837
868
  }
838
869
  entriesReused++;
@@ -1088,6 +1119,21 @@ var CompositionConverterService = class {
1088
1119
  }
1089
1120
  }
1090
1121
  // --- Source Item Matching ---
1122
+ async buildEntryIdMap(entriesDirFull) {
1123
+ const entryIdMap = /* @__PURE__ */ new Map();
1124
+ const entryFiles = await this.fileSystem.findFiles(entriesDirFull, "*.json");
1125
+ for (const filePath of entryFiles) {
1126
+ try {
1127
+ const entryData = await this.fileSystem.readFile(filePath);
1128
+ if (entryData?.entry?._id) {
1129
+ entryIdMap.set(entryData.entry._id, filePath);
1130
+ }
1131
+ } catch {
1132
+ continue;
1133
+ }
1134
+ }
1135
+ return entryIdMap;
1136
+ }
1091
1137
  async buildSourceItemMap(entriesDirFull) {
1092
1138
  const sourceItemMap = /* @__PURE__ */ new Map();
1093
1139
  const entryFiles = await this.fileSystem.findFiles(entriesDirFull, "*.json");
@@ -4330,7 +4376,7 @@ function createConvertCompositionsToEntriesCommand() {
4330
4376
  );
4331
4377
  try {
4332
4378
  const compositionTypes = options.compositionTypes.split("|").map((t) => t.trim()).filter((t) => t.length > 0);
4333
- const parsePipeSeparated = (value) => value ? value.split("|").map((t) => t.trim()).filter((t) => t.length > 0) : [];
4379
+ const parsePipeSeparated = (value) => value ? [...new Set(value.split("|").map((t) => t.trim()).filter((t) => t.length > 0))] : [];
4334
4380
  const componentsToReferences = parsePipeSeparated(options.componentsToReferences);
4335
4381
  const componentsToBlocks = parsePipeSeparated(options.componentsToBlocks);
4336
4382
  const result = await converter.convert({
@@ -4903,7 +4949,7 @@ function createRemoveFieldCommand() {
4903
4949
  // package.json
4904
4950
  var package_default = {
4905
4951
  name: "@uniformdev/transformer",
4906
- version: "1.1.24",
4952
+ version: "1.1.26",
4907
4953
  description: "CLI tool for transforming Uniform.dev serialization files offline",
4908
4954
  type: "module",
4909
4955
  bin: {