@uniformdev/transformer 1.1.21 → 1.1.22
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 +184 -60
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.js +167 -51
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -130,7 +130,8 @@ interface PropagateRootComponentSlotOptions extends GlobalOptions {
|
|
|
130
130
|
}
|
|
131
131
|
interface ConvertCompositionsToEntriesOptions extends GlobalOptions {
|
|
132
132
|
compositionTypes: string;
|
|
133
|
-
|
|
133
|
+
componentsToReferences?: string;
|
|
134
|
+
componentsToBlocks?: string;
|
|
134
135
|
}
|
|
135
136
|
interface RemoveParameterOptions extends GlobalOptions {
|
|
136
137
|
componentType: string;
|
|
@@ -417,11 +418,13 @@ interface ConvertCompositionsToEntriesInternalOptions {
|
|
|
417
418
|
contentTypesDir: string;
|
|
418
419
|
entriesDir: string;
|
|
419
420
|
compositionTypes: string[];
|
|
420
|
-
|
|
421
|
+
componentsToReferences: string[];
|
|
422
|
+
componentsToBlocks: string[];
|
|
421
423
|
whatIf: boolean;
|
|
422
424
|
strict: boolean;
|
|
423
425
|
}
|
|
424
426
|
interface ContentTypeDefinition {
|
|
427
|
+
type?: string;
|
|
425
428
|
id: string;
|
|
426
429
|
name: string;
|
|
427
430
|
fields: ContentTypeField[];
|
|
@@ -460,8 +463,9 @@ interface FlattenedInstance {
|
|
|
460
463
|
interface ConvertResult {
|
|
461
464
|
contentTypesWritten: number;
|
|
462
465
|
entriesFromCompositions: number;
|
|
463
|
-
|
|
466
|
+
entriesFromReferences: number;
|
|
464
467
|
entriesReused: number;
|
|
468
|
+
blocksEmbedded: number;
|
|
465
469
|
}
|
|
466
470
|
declare class CompositionConverterService {
|
|
467
471
|
private fileSystem;
|
package/dist/index.js
CHANGED
|
@@ -582,7 +582,8 @@ var CompositionConverterService = class {
|
|
|
582
582
|
contentTypesDir,
|
|
583
583
|
entriesDir,
|
|
584
584
|
compositionTypes,
|
|
585
|
-
|
|
585
|
+
componentsToReferences,
|
|
586
|
+
componentsToBlocks,
|
|
586
587
|
whatIf,
|
|
587
588
|
strict
|
|
588
589
|
} = options;
|
|
@@ -592,13 +593,17 @@ var CompositionConverterService = class {
|
|
|
592
593
|
const entriesDirFull = this.fileSystem.resolvePath(rootDir, entriesDir);
|
|
593
594
|
let contentTypesWritten = 0;
|
|
594
595
|
let entriesFromCompositions = 0;
|
|
595
|
-
let
|
|
596
|
+
let entriesFromReferences = 0;
|
|
596
597
|
let entriesReused = 0;
|
|
598
|
+
let blocksEmbedded = 0;
|
|
597
599
|
this.logger.info(`Composition types: ${compositionTypes.join(", ")}`);
|
|
598
|
-
if (
|
|
599
|
-
this.logger.info(`
|
|
600
|
+
if (componentsToReferences.length > 0) {
|
|
601
|
+
this.logger.info(`Components to references: ${componentsToReferences.join(", ")}`);
|
|
600
602
|
}
|
|
601
|
-
|
|
603
|
+
if (componentsToBlocks.length > 0) {
|
|
604
|
+
this.logger.info(`Components to blocks: ${componentsToBlocks.join(", ")}`);
|
|
605
|
+
}
|
|
606
|
+
const sourceItemMap = componentsToReferences.length > 0 ? await this.buildSourceItemMap(entriesDirFull) : /* @__PURE__ */ new Map();
|
|
602
607
|
if (sourceItemMap.size > 0) {
|
|
603
608
|
this.logger.info(`Found ${sourceItemMap.size} existing entry(ies) with sourceItem values`);
|
|
604
609
|
}
|
|
@@ -609,7 +614,7 @@ var CompositionConverterService = class {
|
|
|
609
614
|
);
|
|
610
615
|
if (compositionResults.length === 0) {
|
|
611
616
|
this.logger.warn("No compositions found matching the specified types");
|
|
612
|
-
return { contentTypesWritten: 0, entriesFromCompositions: 0,
|
|
617
|
+
return { contentTypesWritten: 0, entriesFromCompositions: 0, entriesFromReferences: 0, entriesReused: 0, blocksEmbedded: 0 };
|
|
613
618
|
}
|
|
614
619
|
this.logger.info(`Found ${compositionResults.length} composition(s)`);
|
|
615
620
|
const rootComponentTypes = /* @__PURE__ */ new Set();
|
|
@@ -626,28 +631,76 @@ var CompositionConverterService = class {
|
|
|
626
631
|
const contentType = this.generateContentType(component);
|
|
627
632
|
contentTypeMap.set(rootType, contentType);
|
|
628
633
|
}
|
|
629
|
-
const
|
|
630
|
-
const
|
|
631
|
-
const
|
|
632
|
-
|
|
634
|
+
const allTargetTypes = [.../* @__PURE__ */ new Set([...componentsToReferences, ...componentsToBlocks])];
|
|
635
|
+
const targetContentTypeMap = /* @__PURE__ */ new Map();
|
|
636
|
+
const missingTargetTypes = [];
|
|
637
|
+
const foundMissingTargetTypes = /* @__PURE__ */ new Set();
|
|
638
|
+
const blockTypeIdMap = /* @__PURE__ */ new Map();
|
|
639
|
+
for (const targetType of allTargetTypes) {
|
|
633
640
|
const isRootType = [...rootComponentTypes].some(
|
|
634
|
-
(rt) => this.compareTypes(rt,
|
|
641
|
+
(rt) => this.compareTypes(rt, targetType, strict)
|
|
635
642
|
);
|
|
636
643
|
if (isRootType) {
|
|
637
644
|
continue;
|
|
638
645
|
}
|
|
646
|
+
const isBlockType = componentsToBlocks.some(
|
|
647
|
+
(bt) => this.compareTypes(bt, targetType, strict)
|
|
648
|
+
);
|
|
649
|
+
const isRefType = componentsToReferences.some(
|
|
650
|
+
(rt) => this.compareTypes(rt, targetType, strict)
|
|
651
|
+
);
|
|
639
652
|
try {
|
|
640
653
|
const { component } = await this.componentService.loadComponent(
|
|
641
654
|
componentsDirFull,
|
|
642
|
-
|
|
655
|
+
targetType,
|
|
643
656
|
{ strict }
|
|
644
657
|
);
|
|
645
|
-
|
|
646
|
-
|
|
658
|
+
if (isRefType) {
|
|
659
|
+
const contentType = this.generateContentType(component);
|
|
660
|
+
targetContentTypeMap.set(targetType, contentType);
|
|
661
|
+
}
|
|
662
|
+
if (isBlockType) {
|
|
663
|
+
let blockId = targetType;
|
|
664
|
+
let needsRename = false;
|
|
665
|
+
if (isRefType) {
|
|
666
|
+
needsRename = true;
|
|
667
|
+
}
|
|
668
|
+
if (!needsRename) {
|
|
669
|
+
const existingPath = this.fileSystem.joinPath(contentTypesDirFull, `${targetType}.json`);
|
|
670
|
+
if (await this.fileSystem.fileExists(existingPath)) {
|
|
671
|
+
try {
|
|
672
|
+
const existing = await this.fileSystem.readFile(existingPath);
|
|
673
|
+
if (existing?.type !== "block") {
|
|
674
|
+
needsRename = true;
|
|
675
|
+
}
|
|
676
|
+
} catch {
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
if (needsRename) {
|
|
681
|
+
blockId = `${targetType}Block`;
|
|
682
|
+
this.logger.info(`Content type "${targetType}" already exists as non-block, using "${blockId}" for block`);
|
|
683
|
+
}
|
|
684
|
+
blockTypeIdMap.set(targetType, blockId);
|
|
685
|
+
const blockContentType = this.generateContentType(component);
|
|
686
|
+
blockContentType.type = "block";
|
|
687
|
+
blockContentType.id = blockId;
|
|
688
|
+
blockContentType.name = needsRename ? `${blockContentType.name} Block` : blockContentType.name;
|
|
689
|
+
targetContentTypeMap.set(blockId, blockContentType);
|
|
690
|
+
}
|
|
691
|
+
if (!isBlockType) {
|
|
692
|
+
if (!isRefType) {
|
|
693
|
+
const contentType = this.generateContentType(component);
|
|
694
|
+
targetContentTypeMap.set(targetType, contentType);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
647
697
|
} catch (error) {
|
|
648
698
|
if (error instanceof ComponentNotFoundError) {
|
|
649
|
-
this.logger.info(`
|
|
650
|
-
|
|
699
|
+
this.logger.info(`Component type not found: ${targetType}`);
|
|
700
|
+
missingTargetTypes.push(targetType);
|
|
701
|
+
if (isBlockType) {
|
|
702
|
+
blockTypeIdMap.set(targetType, targetType);
|
|
703
|
+
}
|
|
651
704
|
continue;
|
|
652
705
|
}
|
|
653
706
|
throw error;
|
|
@@ -659,48 +712,84 @@ var CompositionConverterService = class {
|
|
|
659
712
|
const compositionName = comp._name ?? compositionId;
|
|
660
713
|
const compositionType = comp.type;
|
|
661
714
|
const entry = this.generateEntryFromComposition(composition);
|
|
662
|
-
const
|
|
663
|
-
if (
|
|
664
|
-
for (const
|
|
665
|
-
if (this.compareTypes(
|
|
715
|
+
const refsByType = /* @__PURE__ */ new Map();
|
|
716
|
+
if (componentsToReferences.length > 0 && comp.slots) {
|
|
717
|
+
for (const refType of componentsToReferences) {
|
|
718
|
+
if (this.compareTypes(refType, compositionType, strict)) {
|
|
666
719
|
this.logger.warn(
|
|
667
|
-
`Skipping
|
|
720
|
+
`Skipping reference of "${refType}" \u2014 same as root component type`
|
|
668
721
|
);
|
|
669
722
|
continue;
|
|
670
723
|
}
|
|
671
724
|
const instances = this.findFlattenTargets(
|
|
672
725
|
comp.slots,
|
|
673
|
-
|
|
726
|
+
refType,
|
|
674
727
|
compositionId,
|
|
675
728
|
compositionName,
|
|
676
729
|
strict
|
|
677
730
|
);
|
|
678
731
|
if (instances.length > 0) {
|
|
679
|
-
|
|
680
|
-
if (
|
|
681
|
-
|
|
732
|
+
refsByType.set(refType, instances);
|
|
733
|
+
if (missingTargetTypes.includes(refType)) {
|
|
734
|
+
foundMissingTargetTypes.add(refType);
|
|
682
735
|
}
|
|
683
736
|
}
|
|
684
737
|
}
|
|
685
738
|
}
|
|
686
739
|
const resolvedRefIds = /* @__PURE__ */ new Map();
|
|
687
|
-
for (const [
|
|
740
|
+
for (const [refType, instances] of refsByType) {
|
|
688
741
|
const refIds = [];
|
|
689
742
|
for (const inst of instances) {
|
|
690
743
|
const existingId = this.findExistingEntryBySourceItem(inst, sourceItemMap);
|
|
691
744
|
refIds.push(existingId ?? inst.determinisiticId);
|
|
692
745
|
}
|
|
693
|
-
resolvedRefIds.set(
|
|
746
|
+
resolvedRefIds.set(refType, refIds);
|
|
694
747
|
}
|
|
695
|
-
for (const [
|
|
696
|
-
entry.entry.fields[
|
|
748
|
+
for (const [refType] of refsByType) {
|
|
749
|
+
entry.entry.fields[refType] = {
|
|
697
750
|
type: "contentReference",
|
|
698
|
-
value: resolvedRefIds.get(
|
|
751
|
+
value: resolvedRefIds.get(refType)
|
|
699
752
|
};
|
|
700
753
|
}
|
|
701
|
-
if (
|
|
754
|
+
if (componentsToReferences.length > 0) {
|
|
702
755
|
this.transformContentReferences(entry);
|
|
703
756
|
}
|
|
757
|
+
const blocksByType = /* @__PURE__ */ new Map();
|
|
758
|
+
if (componentsToBlocks.length > 0 && comp.slots) {
|
|
759
|
+
for (const blockType of componentsToBlocks) {
|
|
760
|
+
if (this.compareTypes(blockType, compositionType, strict)) {
|
|
761
|
+
this.logger.warn(
|
|
762
|
+
`Skipping block of "${blockType}" \u2014 same as root component type`
|
|
763
|
+
);
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
const instances = this.findFlattenTargets(
|
|
767
|
+
comp.slots,
|
|
768
|
+
blockType,
|
|
769
|
+
compositionId,
|
|
770
|
+
compositionName,
|
|
771
|
+
strict
|
|
772
|
+
);
|
|
773
|
+
if (instances.length > 0) {
|
|
774
|
+
blocksByType.set(blockType, instances);
|
|
775
|
+
if (missingTargetTypes.includes(blockType)) {
|
|
776
|
+
foundMissingTargetTypes.add(blockType);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
for (const [blockType, instances] of blocksByType) {
|
|
782
|
+
const resolvedBlockId = blockTypeIdMap.get(blockType) ?? blockType;
|
|
783
|
+
const blockValues = instances.map((inst) => ({
|
|
784
|
+
type: resolvedBlockId,
|
|
785
|
+
fields: { ...inst.instance.parameters ?? {} }
|
|
786
|
+
}));
|
|
787
|
+
entry.entry.fields[resolvedBlockId] = {
|
|
788
|
+
type: "$block",
|
|
789
|
+
value: blockValues
|
|
790
|
+
};
|
|
791
|
+
blocksEmbedded += instances.length;
|
|
792
|
+
}
|
|
704
793
|
const entryId = entry.entry._id;
|
|
705
794
|
const entryFilePath = this.fileSystem.joinPath(entriesDirFull, `${entryId}.json`);
|
|
706
795
|
this.logger.action(
|
|
@@ -712,7 +801,7 @@ var CompositionConverterService = class {
|
|
|
712
801
|
await this.fileSystem.writeFile(entryFilePath, entry);
|
|
713
802
|
}
|
|
714
803
|
entriesFromCompositions++;
|
|
715
|
-
for (const [
|
|
804
|
+
for (const [refType, instances] of refsByType) {
|
|
716
805
|
for (const inst of instances) {
|
|
717
806
|
const existingId = this.findExistingEntryBySourceItem(inst, sourceItemMap);
|
|
718
807
|
if (existingId) {
|
|
@@ -723,7 +812,7 @@ var CompositionConverterService = class {
|
|
|
723
812
|
this.logger.action(
|
|
724
813
|
whatIf,
|
|
725
814
|
"UPDATE",
|
|
726
|
-
`${entriesDir}/${existingId}.json (${
|
|
815
|
+
`${entriesDir}/${existingId}.json (${refType}, merged fields from "${this.truncate(compositionName, 50)}")`
|
|
727
816
|
);
|
|
728
817
|
if (!whatIf) {
|
|
729
818
|
const existingEntry = await this.fileSystem.readFile(existingEntryPath);
|
|
@@ -747,31 +836,53 @@ var CompositionConverterService = class {
|
|
|
747
836
|
this.logger.action(
|
|
748
837
|
whatIf,
|
|
749
838
|
"WRITE",
|
|
750
|
-
`${entriesDir}/${inst.determinisiticId}.json (${
|
|
839
|
+
`${entriesDir}/${inst.determinisiticId}.json (${refType} from "${this.truncate(compositionName, 50)}")`
|
|
751
840
|
);
|
|
752
841
|
if (!whatIf) {
|
|
753
842
|
await this.fileSystem.writeFile(flatEntryPath, flatEntry);
|
|
754
843
|
}
|
|
755
|
-
|
|
844
|
+
entriesFromReferences++;
|
|
756
845
|
}
|
|
757
846
|
}
|
|
758
847
|
}
|
|
759
|
-
if (
|
|
848
|
+
if (componentsToReferences.length > 0) {
|
|
760
849
|
for (const contentType of contentTypeMap.values()) {
|
|
761
|
-
for (const
|
|
762
|
-
if (this.compareTypes(
|
|
850
|
+
for (const refType of componentsToReferences) {
|
|
851
|
+
if (this.compareTypes(refType, contentType.id, strict)) {
|
|
763
852
|
continue;
|
|
764
853
|
}
|
|
765
|
-
if (
|
|
854
|
+
if (missingTargetTypes.includes(refType) && !foundMissingTargetTypes.has(refType)) {
|
|
766
855
|
continue;
|
|
767
856
|
}
|
|
768
857
|
contentType.fields.push({
|
|
769
|
-
id:
|
|
770
|
-
name:
|
|
858
|
+
id: refType,
|
|
859
|
+
name: refType,
|
|
771
860
|
type: "contentReference",
|
|
772
861
|
typeConfig: {
|
|
773
862
|
isMulti: true,
|
|
774
|
-
allowedContentTypes: [
|
|
863
|
+
allowedContentTypes: [refType]
|
|
864
|
+
},
|
|
865
|
+
localizable: false
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
if (componentsToBlocks.length > 0) {
|
|
871
|
+
for (const contentType of contentTypeMap.values()) {
|
|
872
|
+
for (const blockType of componentsToBlocks) {
|
|
873
|
+
if (this.compareTypes(blockType, contentType.id, strict)) {
|
|
874
|
+
continue;
|
|
875
|
+
}
|
|
876
|
+
if (missingTargetTypes.includes(blockType) && !foundMissingTargetTypes.has(blockType)) {
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
const resolvedBlockId = blockTypeIdMap.get(blockType) ?? blockType;
|
|
880
|
+
contentType.fields.push({
|
|
881
|
+
id: resolvedBlockId,
|
|
882
|
+
name: resolvedBlockId,
|
|
883
|
+
type: "$block",
|
|
884
|
+
typeConfig: {
|
|
885
|
+
allowedContentTypes: [resolvedBlockId]
|
|
775
886
|
},
|
|
776
887
|
localizable: false
|
|
777
888
|
});
|
|
@@ -781,25 +892,30 @@ var CompositionConverterService = class {
|
|
|
781
892
|
for (const contentType of contentTypeMap.values()) {
|
|
782
893
|
contentType.fields = this.componentService.sortParametersByGroup(contentType.fields);
|
|
783
894
|
}
|
|
784
|
-
for (const contentType of
|
|
895
|
+
for (const contentType of targetContentTypeMap.values()) {
|
|
785
896
|
contentType.fields = this.componentService.sortParametersByGroup(contentType.fields);
|
|
786
897
|
}
|
|
787
898
|
for (const [typeName, contentType] of contentTypeMap) {
|
|
788
899
|
const filePath = this.fileSystem.joinPath(contentTypesDirFull, `${typeName}.json`);
|
|
789
|
-
const
|
|
900
|
+
const baseFieldCount = contentType.fields.filter((f) => f.type !== "contentReference" && f.type !== "$block").length;
|
|
790
901
|
const refCount = contentType.fields.filter((f) => f.type === "contentReference").length;
|
|
791
|
-
const
|
|
902
|
+
const blockCount = contentType.fields.filter((f) => f.type === "$block").length;
|
|
903
|
+
const extras = [
|
|
904
|
+
refCount > 0 ? `${refCount} reference(s)` : "",
|
|
905
|
+
blockCount > 0 ? `${blockCount} block(s)` : ""
|
|
906
|
+
].filter(Boolean).join(", ");
|
|
907
|
+
const extrasInfo = extras ? ` + ${extras}` : "";
|
|
792
908
|
this.logger.action(
|
|
793
909
|
whatIf,
|
|
794
910
|
"WRITE",
|
|
795
|
-
`${contentTypesDir}/${typeName}.json (${
|
|
911
|
+
`${contentTypesDir}/${typeName}.json (${baseFieldCount} fields${extrasInfo})`
|
|
796
912
|
);
|
|
797
913
|
if (!whatIf) {
|
|
798
914
|
await this.fileSystem.writeFile(filePath, contentType);
|
|
799
915
|
}
|
|
800
916
|
contentTypesWritten++;
|
|
801
917
|
}
|
|
802
|
-
for (const [typeName, contentType] of
|
|
918
|
+
for (const [typeName, contentType] of targetContentTypeMap) {
|
|
803
919
|
const filePath = this.fileSystem.joinPath(contentTypesDirFull, `${typeName}.json`);
|
|
804
920
|
this.logger.action(
|
|
805
921
|
whatIf,
|
|
@@ -811,15 +927,15 @@ var CompositionConverterService = class {
|
|
|
811
927
|
}
|
|
812
928
|
contentTypesWritten++;
|
|
813
929
|
}
|
|
814
|
-
const neverFoundMissingTypes =
|
|
815
|
-
(type) => !
|
|
930
|
+
const neverFoundMissingTypes = missingTargetTypes.filter(
|
|
931
|
+
(type) => !foundMissingTargetTypes.has(type)
|
|
816
932
|
);
|
|
817
933
|
if (neverFoundMissingTypes.length > 0) {
|
|
818
934
|
this.logger.warn(
|
|
819
|
-
`
|
|
935
|
+
`Component type(s) not found in any composition: ${neverFoundMissingTypes.join(", ")}`
|
|
820
936
|
);
|
|
821
937
|
}
|
|
822
|
-
return { contentTypesWritten, entriesFromCompositions,
|
|
938
|
+
return { contentTypesWritten, entriesFromCompositions, entriesFromReferences, entriesReused, blocksEmbedded };
|
|
823
939
|
}
|
|
824
940
|
// --- Content Type Generation ---
|
|
825
941
|
generateContentType(component) {
|