@uniformdev/transformer 1.1.3 → 1.1.4

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
@@ -2422,6 +2422,12 @@ var ComponentAdderService = class {
2422
2422
  }
2423
2423
  return id1.toLowerCase() === id2.toLowerCase();
2424
2424
  }
2425
+ parseParentComponentTypes(parentComponentType) {
2426
+ return parentComponentType.split("|").map((t) => t.trim()).filter((t) => t.length > 0);
2427
+ }
2428
+ matchesAnyParentType(instanceType, parentTypes, strict) {
2429
+ return parentTypes.some((pt) => this.compareIds(instanceType, pt, strict));
2430
+ }
2425
2431
  parseParameters(parameterString) {
2426
2432
  const result = {};
2427
2433
  if (!parameterString) return result;
@@ -2495,18 +2501,9 @@ var ComponentAdderService = class {
2495
2501
  const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
2496
2502
  const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
2497
2503
  const findOptions = { strict };
2498
- this.logger.info(`Loading parent component: ${parentComponentType}`);
2499
- const { component: parentComponent, filePath: parentComponentFilePath } = await this.componentService.loadComponent(fullComponentsDir, parentComponentType, findOptions);
2500
- if (!parentComponent.slots) {
2501
- parentComponent.slots = [];
2502
- }
2503
- let slotDef = parentComponent.slots.find(
2504
- (s) => this.compareIds(s.id, slot, strict)
2505
- );
2506
- if (!slotDef) {
2507
- this.logger.info(`Slot "${slot}" not found on component "${parentComponentType}", creating it`);
2508
- slotDef = { id: slot, name: slot, allowedComponents: [] };
2509
- parentComponent.slots.push(slotDef);
2504
+ const parentTypes = this.parseParentComponentTypes(parentComponentType);
2505
+ if (parentTypes.length === 0) {
2506
+ throw new TransformError("parentComponentType cannot be empty");
2510
2507
  }
2511
2508
  this.logger.info(`Validating new component: ${newComponentType}`);
2512
2509
  try {
@@ -2520,35 +2517,50 @@ var ComponentAdderService = class {
2520
2517
  throw error;
2521
2518
  }
2522
2519
  let allowedComponentsUpdated = false;
2523
- const slotIndex = parentComponent.slots?.findIndex(
2524
- (s) => this.compareIds(s.id, slotDef.id, strict)
2525
- );
2526
- if (slotIndex !== void 0 && slotIndex >= 0) {
2527
- const actualSlot = parentComponent.slots[slotIndex];
2528
- if (!actualSlot.allowedComponents) {
2529
- actualSlot.allowedComponents = [];
2520
+ for (const parentType of parentTypes) {
2521
+ this.logger.info(`Loading parent component: ${parentType}`);
2522
+ const { component: parentComponent, filePath: parentComponentFilePath } = await this.componentService.loadComponent(fullComponentsDir, parentType, findOptions);
2523
+ if (!parentComponent.slots) {
2524
+ parentComponent.slots = [];
2525
+ }
2526
+ let slotDef = parentComponent.slots.find(
2527
+ (s) => this.compareIds(s.id, slot, strict)
2528
+ );
2529
+ if (!slotDef) {
2530
+ this.logger.info(`Slot "${slot}" not found on component "${parentType}", creating it`);
2531
+ slotDef = { id: slot, name: slot, allowedComponents: [] };
2532
+ parentComponent.slots.push(slotDef);
2530
2533
  }
2531
- const isAlreadyAllowed = actualSlot.allowedComponents.some(
2532
- (c) => this.compareIds(c, newComponentType, strict)
2534
+ const slotIndex = parentComponent.slots?.findIndex(
2535
+ (s) => this.compareIds(s.id, slotDef.id, strict)
2533
2536
  );
2534
- if (!isAlreadyAllowed) {
2535
- this.logger.action(
2536
- whatIf,
2537
- "UPDATE",
2538
- `Adding "${newComponentType}" to allowedComponents for slot "${slot}" on component "${parentComponentType}"`
2537
+ if (slotIndex !== void 0 && slotIndex >= 0) {
2538
+ const actualSlot = parentComponent.slots[slotIndex];
2539
+ if (!actualSlot.allowedComponents) {
2540
+ actualSlot.allowedComponents = [];
2541
+ }
2542
+ const isAlreadyAllowed = actualSlot.allowedComponents.some(
2543
+ (c) => this.compareIds(c, newComponentType, strict)
2539
2544
  );
2540
- actualSlot.allowedComponents.push(newComponentType);
2541
- if (!whatIf) {
2542
- await this.componentService.saveComponent(parentComponentFilePath, parentComponent);
2545
+ if (!isAlreadyAllowed) {
2546
+ this.logger.action(
2547
+ whatIf,
2548
+ "UPDATE",
2549
+ `Adding "${newComponentType}" to allowedComponents for slot "${slot}" on component "${parentType}"`
2550
+ );
2551
+ actualSlot.allowedComponents.push(newComponentType);
2552
+ if (!whatIf) {
2553
+ await this.componentService.saveComponent(parentComponentFilePath, parentComponent);
2554
+ }
2555
+ allowedComponentsUpdated = true;
2543
2556
  }
2544
- allowedComponentsUpdated = true;
2545
2557
  }
2546
2558
  }
2547
2559
  const parsedParams = this.parseParameters(paramString);
2548
2560
  const newInstance = this.createComponentInstance(newComponentType, parsedParams);
2549
2561
  const compositionsResult = await this.addComponentToDirectory(
2550
2562
  fullCompositionsDir,
2551
- parentComponentType,
2563
+ parentTypes,
2552
2564
  slot,
2553
2565
  newInstance,
2554
2566
  whatIf,
@@ -2557,7 +2569,7 @@ var ComponentAdderService = class {
2557
2569
  );
2558
2570
  const compositionPatternsResult = await this.addComponentToDirectory(
2559
2571
  fullCompositionPatternsDir,
2560
- parentComponentType,
2572
+ parentTypes,
2561
2573
  slot,
2562
2574
  newInstance,
2563
2575
  whatIf,
@@ -2566,7 +2578,7 @@ var ComponentAdderService = class {
2566
2578
  );
2567
2579
  const componentPatternsResult = await this.addComponentToDirectory(
2568
2580
  fullComponentPatternsDir,
2569
- parentComponentType,
2581
+ parentTypes,
2570
2582
  slot,
2571
2583
  newInstance,
2572
2584
  whatIf,
@@ -2575,7 +2587,7 @@ var ComponentAdderService = class {
2575
2587
  );
2576
2588
  this.logger.info("");
2577
2589
  this.logger.info(
2578
- `Summary: ${allowedComponentsUpdated ? "1 component definition updated, " : ""}${compositionsResult} composition(s), ${compositionPatternsResult} composition pattern(s), ${componentPatternsResult} component pattern(s) updated. ${compositionsResult + compositionPatternsResult + componentPatternsResult} instance(s) added.`
2590
+ `Summary: ${allowedComponentsUpdated ? `${parentTypes.length} component definition(s) updated, ` : ""}${compositionsResult} composition(s), ${compositionPatternsResult} composition pattern(s), ${componentPatternsResult} component pattern(s) updated. ${compositionsResult + compositionPatternsResult + componentPatternsResult} instance(s) added.`
2579
2591
  );
2580
2592
  return {
2581
2593
  allowedComponentsUpdated,
@@ -2606,18 +2618,9 @@ var ComponentAdderService = class {
2606
2618
  const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
2607
2619
  const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
2608
2620
  const findOptions = { strict };
2609
- this.logger.info(`Loading parent component: ${parentComponentType}`);
2610
- const { component: parentComponent } = await this.componentService.loadComponent(fullComponentsDir, parentComponentType, findOptions);
2611
- if (!parentComponent.slots) {
2612
- parentComponent.slots = [];
2613
- }
2614
- let slotDef = parentComponent.slots.find(
2615
- (s) => this.compareIds(s.id, slot, strict)
2616
- );
2617
- if (!slotDef) {
2618
- this.logger.info(`Slot "${slot}" not found on component "${parentComponentType}", creating it`);
2619
- slotDef = { id: slot, name: slot, allowedComponents: [] };
2620
- parentComponent.slots.push(slotDef);
2621
+ const parentTypes = this.parseParentComponentTypes(parentComponentType);
2622
+ if (parentTypes.length === 0) {
2623
+ throw new TransformError("parentComponentType cannot be empty");
2621
2624
  }
2622
2625
  this.logger.info(`Loading component pattern: ${componentPatternId}`);
2623
2626
  const pattern = await this.loadComponentPattern(
@@ -2631,32 +2634,45 @@ var ComponentAdderService = class {
2631
2634
  `Component pattern "${componentPatternId}" has no valid definition or missing type`
2632
2635
  );
2633
2636
  }
2634
- let allowedComponentsUpdated = false;
2635
2637
  const componentTypeInPattern = patternDefinition.type;
2636
- const slotIndex = parentComponent.slots?.findIndex(
2637
- (s) => this.compareIds(s.id, slotDef.id, strict)
2638
- );
2639
- if (slotIndex !== void 0 && slotIndex >= 0) {
2640
- const actualSlot = parentComponent.slots[slotIndex];
2641
- if (!actualSlot.allowedComponents) {
2642
- actualSlot.allowedComponents = [];
2638
+ let allowedComponentsUpdated = false;
2639
+ for (const parentType of parentTypes) {
2640
+ this.logger.info(`Loading parent component: ${parentType}`);
2641
+ const { component: parentComponent, filePath: parentComponentFilePath } = await this.componentService.loadComponent(fullComponentsDir, parentType, findOptions);
2642
+ if (!parentComponent.slots) {
2643
+ parentComponent.slots = [];
2644
+ }
2645
+ let slotDef = parentComponent.slots.find(
2646
+ (s) => this.compareIds(s.id, slot, strict)
2647
+ );
2648
+ if (!slotDef) {
2649
+ this.logger.info(`Slot "${slot}" not found on component "${parentType}", creating it`);
2650
+ slotDef = { id: slot, name: slot, allowedComponents: [] };
2651
+ parentComponent.slots.push(slotDef);
2643
2652
  }
2644
- const isAlreadyAllowed = actualSlot.allowedComponents.some(
2645
- (c) => this.compareIds(c, componentTypeInPattern, strict)
2653
+ const slotIndex = parentComponent.slots?.findIndex(
2654
+ (s) => this.compareIds(s.id, slotDef.id, strict)
2646
2655
  );
2647
- if (!isAlreadyAllowed) {
2648
- this.logger.action(
2649
- whatIf,
2650
- "UPDATE",
2651
- `Adding "${componentTypeInPattern}" to allowedComponents for slot "${slot}" on component "${parentComponentType}"`
2656
+ if (slotIndex !== void 0 && slotIndex >= 0) {
2657
+ const actualSlot = parentComponent.slots[slotIndex];
2658
+ if (!actualSlot.allowedComponents) {
2659
+ actualSlot.allowedComponents = [];
2660
+ }
2661
+ const isAlreadyAllowed = actualSlot.allowedComponents.some(
2662
+ (c) => this.compareIds(c, componentTypeInPattern, strict)
2652
2663
  );
2653
- actualSlot.allowedComponents.push(componentTypeInPattern);
2654
- if (!whatIf) {
2655
- await this.componentService.loadComponent(fullComponentsDir, parentComponentType, findOptions).then(
2656
- ({ filePath }) => this.componentService.saveComponent(filePath, parentComponent)
2664
+ if (!isAlreadyAllowed) {
2665
+ this.logger.action(
2666
+ whatIf,
2667
+ "UPDATE",
2668
+ `Adding "${componentTypeInPattern}" to allowedComponents for slot "${slot}" on component "${parentType}"`
2657
2669
  );
2670
+ actualSlot.allowedComponents.push(componentTypeInPattern);
2671
+ if (!whatIf) {
2672
+ await this.componentService.saveComponent(parentComponentFilePath, parentComponent);
2673
+ }
2674
+ allowedComponentsUpdated = true;
2658
2675
  }
2659
- allowedComponentsUpdated = true;
2660
2676
  }
2661
2677
  }
2662
2678
  const newInstance = {
@@ -2666,7 +2682,7 @@ var ComponentAdderService = class {
2666
2682
  };
2667
2683
  const compositionsResult = await this.addComponentToDirectory(
2668
2684
  fullCompositionsDir,
2669
- parentComponentType,
2685
+ parentTypes,
2670
2686
  slot,
2671
2687
  newInstance,
2672
2688
  whatIf,
@@ -2675,7 +2691,7 @@ var ComponentAdderService = class {
2675
2691
  );
2676
2692
  const compositionPatternsResult = await this.addComponentToDirectory(
2677
2693
  fullCompositionPatternsDir,
2678
- parentComponentType,
2694
+ parentTypes,
2679
2695
  slot,
2680
2696
  newInstance,
2681
2697
  whatIf,
@@ -2684,7 +2700,7 @@ var ComponentAdderService = class {
2684
2700
  );
2685
2701
  const componentPatternsResult = await this.addComponentToDirectory(
2686
2702
  fullComponentPatternsDir,
2687
- parentComponentType,
2703
+ parentTypes,
2688
2704
  slot,
2689
2705
  newInstance,
2690
2706
  whatIf,
@@ -2693,7 +2709,7 @@ var ComponentAdderService = class {
2693
2709
  );
2694
2710
  this.logger.info("");
2695
2711
  this.logger.info(
2696
- `Summary: ${allowedComponentsUpdated ? "1 component definition updated, " : ""}${compositionsResult} composition(s), ${compositionPatternsResult} composition pattern(s), ${componentPatternsResult} component pattern(s) updated. ${compositionsResult + compositionPatternsResult + componentPatternsResult} instance(s) added.`
2712
+ `Summary: ${allowedComponentsUpdated ? `${parentTypes.length} component definition(s) updated, ` : ""}${compositionsResult} composition(s), ${compositionPatternsResult} composition pattern(s), ${componentPatternsResult} component pattern(s) updated. ${compositionsResult + compositionPatternsResult + componentPatternsResult} instance(s) added.`
2697
2713
  );
2698
2714
  return {
2699
2715
  allowedComponentsUpdated,
@@ -2744,7 +2760,7 @@ var ComponentAdderService = class {
2744
2760
  }
2745
2761
  return raw;
2746
2762
  }
2747
- async addComponentToDirectory(directory, parentComponentType, slot, newInstance, whatIf, strict, dirType) {
2763
+ async addComponentToDirectory(directory, parentTypes, slot, newInstance, whatIf, strict, dirType) {
2748
2764
  const exists = await this.fileSystem.fileExists(directory);
2749
2765
  if (!exists) {
2750
2766
  this.logger.detail(`${dirType} directory does not exist, skipping`);
@@ -2777,7 +2793,7 @@ var ComponentAdderService = class {
2777
2793
  }
2778
2794
  const rootInstance = composition.composition;
2779
2795
  let modified = false;
2780
- if (this.compareIds(rootInstance.type, parentComponentType, strict)) {
2796
+ if (this.matchesAnyParentType(rootInstance.type, parentTypes, strict)) {
2781
2797
  if (!rootInstance.slots) {
2782
2798
  rootInstance.slots = {};
2783
2799
  }
@@ -2789,7 +2805,7 @@ var ComponentAdderService = class {
2789
2805
  if (rootInstance.slots) {
2790
2806
  const nestedModified = this.addComponentToNestedSlots(
2791
2807
  rootInstance.slots,
2792
- parentComponentType,
2808
+ parentTypes,
2793
2809
  slot,
2794
2810
  newInstance,
2795
2811
  strict
@@ -2823,12 +2839,12 @@ var ComponentAdderService = class {
2823
2839
  }
2824
2840
  return filesModified;
2825
2841
  }
2826
- addComponentToNestedSlots(slots, parentComponentType, slot, newInstance, strict) {
2842
+ addComponentToNestedSlots(slots, parentTypes, slot, newInstance, strict) {
2827
2843
  let modified = false;
2828
2844
  for (const slotInstances of Object.values(slots)) {
2829
2845
  if (!Array.isArray(slotInstances)) continue;
2830
2846
  for (const instance of slotInstances) {
2831
- if (this.compareIds(instance.type, parentComponentType, strict)) {
2847
+ if (this.matchesAnyParentType(instance.type, parentTypes, strict)) {
2832
2848
  if (!instance.slots) {
2833
2849
  instance.slots = {};
2834
2850
  }
@@ -2840,7 +2856,7 @@ var ComponentAdderService = class {
2840
2856
  if (instance.slots) {
2841
2857
  const nestedModified = this.addComponentToNestedSlots(
2842
2858
  instance.slots,
2843
- parentComponentType,
2859
+ parentTypes,
2844
2860
  slot,
2845
2861
  newInstance,
2846
2862
  strict