@uniformdev/transformer 1.1.4 → 1.1.6
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 +261 -72
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +117 -43
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -221,6 +221,11 @@ declare class CompositionService {
|
|
|
221
221
|
composition: Composition;
|
|
222
222
|
filePath: string;
|
|
223
223
|
}[]>;
|
|
224
|
+
findCompositionsByTypes(compositionsDir: string, compositionTypes: string[], options?: FindOptions): Promise<{
|
|
225
|
+
composition: Composition;
|
|
226
|
+
filePath: string;
|
|
227
|
+
}[]>;
|
|
228
|
+
private normalizeCompositionTypes;
|
|
224
229
|
findComponentInstances(composition: Composition, componentType: string, options?: FindOptions): FoundComponentInstance[];
|
|
225
230
|
private searchSlots;
|
|
226
231
|
getRootOverrides(composition: Composition): Record<string, ParameterValue>;
|
|
@@ -272,6 +277,7 @@ declare class PropertyPropagatorService {
|
|
|
272
277
|
private logger;
|
|
273
278
|
constructor(fileSystem: FileSystemService, componentService: ComponentService, compositionService: CompositionService, logger: Logger);
|
|
274
279
|
propagate(options: PropagateOptions): Promise<PropagateResult>;
|
|
280
|
+
private parsePipeSeparatedValues;
|
|
275
281
|
}
|
|
276
282
|
|
|
277
283
|
interface RenameSlotInternalOptions {
|
package/dist/index.js
CHANGED
|
@@ -362,13 +362,22 @@ var CompositionService = class {
|
|
|
362
362
|
await this.fileSystem.writeFile(filePath, composition);
|
|
363
363
|
}
|
|
364
364
|
async findCompositionsByType(compositionsDir, compositionType, options = {}) {
|
|
365
|
+
return this.findCompositionsByTypes(compositionsDir, [compositionType], options);
|
|
366
|
+
}
|
|
367
|
+
async findCompositionsByTypes(compositionsDir, compositionTypes, options = {}) {
|
|
365
368
|
const { strict = false } = options;
|
|
369
|
+
const normalizedTypes = this.normalizeCompositionTypes(compositionTypes, strict);
|
|
370
|
+
if (normalizedTypes.length === 0) {
|
|
371
|
+
return [];
|
|
372
|
+
}
|
|
366
373
|
const files = await this.fileSystem.findFiles(compositionsDir, "**/*.{json,yaml,yml}");
|
|
367
374
|
const results = [];
|
|
368
375
|
for (const filePath of files) {
|
|
369
376
|
try {
|
|
370
377
|
const composition = await this.loadComposition(filePath);
|
|
371
|
-
if (composition.composition?.type &&
|
|
378
|
+
if (composition.composition?.type && normalizedTypes.some(
|
|
379
|
+
(type) => this.compareTypes(composition.composition.type, type, strict)
|
|
380
|
+
)) {
|
|
372
381
|
results.push({ composition, filePath });
|
|
373
382
|
}
|
|
374
383
|
} catch {
|
|
@@ -376,6 +385,22 @@ var CompositionService = class {
|
|
|
376
385
|
}
|
|
377
386
|
return results;
|
|
378
387
|
}
|
|
388
|
+
normalizeCompositionTypes(compositionTypes, strict) {
|
|
389
|
+
const normalized = [];
|
|
390
|
+
for (const type of compositionTypes) {
|
|
391
|
+
const trimmed = type.trim();
|
|
392
|
+
if (!trimmed) {
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
const exists = normalized.some(
|
|
396
|
+
(existing) => strict ? existing === trimmed : existing.toLowerCase() === trimmed.toLowerCase()
|
|
397
|
+
);
|
|
398
|
+
if (!exists) {
|
|
399
|
+
normalized.push(trimmed);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return normalized;
|
|
403
|
+
}
|
|
379
404
|
findComponentInstances(composition, componentType, options = {}) {
|
|
380
405
|
const { strict = false } = options;
|
|
381
406
|
const results = [];
|
|
@@ -500,26 +525,52 @@ var PropertyPropagatorService = class {
|
|
|
500
525
|
deleteSourceParameter
|
|
501
526
|
} = options;
|
|
502
527
|
const findOptions = { strict };
|
|
528
|
+
const compositionTypes = this.parsePipeSeparatedValues(compositionType, strict);
|
|
503
529
|
const fullComponentsDir = this.fileSystem.resolvePath(rootDir, componentsDir);
|
|
504
530
|
const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
|
|
505
|
-
|
|
506
|
-
const
|
|
531
|
+
const sourceComponents = [];
|
|
532
|
+
for (const sourceType of compositionTypes) {
|
|
533
|
+
this.logger.info(`Loading component: ${sourceType}`);
|
|
534
|
+
const { component: sourceComponent, filePath: sourceFilePath } = await this.componentService.loadComponent(fullComponentsDir, sourceType, findOptions);
|
|
535
|
+
sourceComponents.push({ sourceType, sourceFilePath, sourceComponent });
|
|
536
|
+
}
|
|
507
537
|
this.logger.info(`Loading component: ${targetComponentType}`);
|
|
508
538
|
const { component: targetComponent, filePath: targetFilePath } = await this.componentService.loadComponent(fullComponentsDir, targetComponentType, findOptions);
|
|
509
|
-
const propertyNames = property.split("|").map((p) => p.trim());
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
539
|
+
const propertyNames = property.split("|").map((p) => p.trim()).filter((p) => p.length > 0);
|
|
540
|
+
const resolvedParams = [];
|
|
541
|
+
const resolvedNames = [];
|
|
542
|
+
for (const { sourceType, sourceComponent } of sourceComponents) {
|
|
543
|
+
const { parameters: sourceParams, notFound } = this.componentService.resolveProperties(
|
|
544
|
+
sourceComponent,
|
|
545
|
+
propertyNames,
|
|
546
|
+
findOptions
|
|
547
|
+
);
|
|
548
|
+
if (notFound.length > 0) {
|
|
549
|
+
this.logger.warn(`Property "${notFound.join(", ")}" not found on component "${sourceType}"`);
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
for (const param of sourceParams) {
|
|
553
|
+
const exists = resolvedParams.some(
|
|
554
|
+
(existing) => strict ? existing.id === param.id : existing.id.toLowerCase() === param.id.toLowerCase()
|
|
555
|
+
);
|
|
556
|
+
if (!exists) {
|
|
557
|
+
resolvedParams.push(param);
|
|
558
|
+
resolvedNames.push(param.id);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
const groupSources = [];
|
|
563
|
+
for (const { sourceType, sourceComponent } of sourceComponents) {
|
|
564
|
+
for (const name of propertyNames) {
|
|
565
|
+
const param = this.componentService.findParameter(sourceComponent, name, findOptions);
|
|
566
|
+
if (param && this.componentService.isGroupParameter(param)) {
|
|
567
|
+
const groupSource = `${sourceType}.${name}`;
|
|
568
|
+
if (!groupSources.includes(groupSource)) {
|
|
569
|
+
groupSources.push(groupSource);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
517
573
|
}
|
|
518
|
-
const resolvedNames = resolvedParams.map((p) => p.id);
|
|
519
|
-
const groupSources = propertyNames.filter((name) => {
|
|
520
|
-
const param = this.componentService.findParameter(sourceComponent, name, findOptions);
|
|
521
|
-
return param && this.componentService.isGroupParameter(param);
|
|
522
|
-
});
|
|
523
574
|
if (groupSources.length > 0) {
|
|
524
575
|
this.logger.info(
|
|
525
576
|
`Resolved properties: ${resolvedNames.join(", ")} (from ${groupSources.join(", ")})`
|
|
@@ -594,9 +645,9 @@ var PropertyPropagatorService = class {
|
|
|
594
645
|
if (componentModified && !whatIf) {
|
|
595
646
|
await this.componentService.saveComponent(targetFilePath, modifiedComponent);
|
|
596
647
|
}
|
|
597
|
-
const compositions = await this.compositionService.
|
|
648
|
+
const compositions = await this.compositionService.findCompositionsByTypes(
|
|
598
649
|
fullCompositionsDir,
|
|
599
|
-
|
|
650
|
+
compositionTypes,
|
|
600
651
|
findOptions
|
|
601
652
|
);
|
|
602
653
|
let modifiedCompositions = 0;
|
|
@@ -643,31 +694,41 @@ var PropertyPropagatorService = class {
|
|
|
643
694
|
modifiedCompositions++;
|
|
644
695
|
}
|
|
645
696
|
}
|
|
646
|
-
let
|
|
697
|
+
let modifiedSourceComponents = 0;
|
|
647
698
|
if (deleteSourceParameter) {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
699
|
+
for (const { sourceType, sourceFilePath, sourceComponent } of sourceComponents) {
|
|
700
|
+
let modifiedSource = { ...sourceComponent };
|
|
701
|
+
let sourceComponentModified = false;
|
|
702
|
+
for (const param of resolvedParams) {
|
|
703
|
+
const exists = this.componentService.findParameter(modifiedSource, param.id, findOptions);
|
|
704
|
+
if (exists) {
|
|
705
|
+
this.logger.action(whatIf, "DELETE", `Parameter "${param.id}" from ${sourceType}`);
|
|
706
|
+
modifiedSource = this.componentService.removeParameter(modifiedSource, param.id, findOptions);
|
|
707
|
+
sourceComponentModified = true;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
const beforeGroupCount = modifiedSource.parameters?.filter(
|
|
711
|
+
(p) => this.componentService.isGroupParameter(p)
|
|
712
|
+
).length ?? 0;
|
|
713
|
+
modifiedSource = this.componentService.removeEmptyGroups(modifiedSource);
|
|
714
|
+
const afterGroupCount = modifiedSource.parameters?.filter(
|
|
715
|
+
(p) => this.componentService.isGroupParameter(p)
|
|
716
|
+
).length ?? 0;
|
|
717
|
+
if (afterGroupCount < beforeGroupCount) {
|
|
718
|
+
const removedCount = beforeGroupCount - afterGroupCount;
|
|
719
|
+
this.logger.action(
|
|
720
|
+
whatIf,
|
|
721
|
+
"DELETE",
|
|
722
|
+
`${removedCount} empty group(s) from ${sourceType}`
|
|
723
|
+
);
|
|
724
|
+
sourceComponentModified = true;
|
|
725
|
+
}
|
|
726
|
+
if (sourceComponentModified) {
|
|
727
|
+
modifiedSourceComponents++;
|
|
728
|
+
}
|
|
729
|
+
if (sourceComponentModified && !whatIf) {
|
|
730
|
+
await this.componentService.saveComponent(sourceFilePath, modifiedSource);
|
|
731
|
+
}
|
|
671
732
|
}
|
|
672
733
|
for (const { composition, filePath } of compositions) {
|
|
673
734
|
const relativePath = filePath.replace(fullCompositionsDir, "").replace(/^[/\\]/, "");
|
|
@@ -686,11 +747,24 @@ var PropertyPropagatorService = class {
|
|
|
686
747
|
}
|
|
687
748
|
}
|
|
688
749
|
return {
|
|
689
|
-
modifiedComponents: (componentModified ? 1 : 0) +
|
|
750
|
+
modifiedComponents: (componentModified ? 1 : 0) + modifiedSourceComponents,
|
|
690
751
|
modifiedCompositions,
|
|
691
752
|
propagatedInstances
|
|
692
753
|
};
|
|
693
754
|
}
|
|
755
|
+
parsePipeSeparatedValues(value, strict) {
|
|
756
|
+
const entries = value.split("|").map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
757
|
+
const normalized = [];
|
|
758
|
+
for (const entry of entries) {
|
|
759
|
+
const exists = normalized.some(
|
|
760
|
+
(existing) => strict ? existing === entry : existing.toLowerCase() === entry.toLowerCase()
|
|
761
|
+
);
|
|
762
|
+
if (!exists) {
|
|
763
|
+
normalized.push(entry);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
return normalized;
|
|
767
|
+
}
|
|
694
768
|
};
|
|
695
769
|
|
|
696
770
|
// src/core/services/slot-renamer.service.ts
|