@uniformdev/transformer 1.1.4 → 1.1.5
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 +260 -72
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +116 -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,51 @@ 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
|
+
throw new PropertyNotFoundError(notFound.join(", "), sourceType);
|
|
550
|
+
}
|
|
551
|
+
for (const param of sourceParams) {
|
|
552
|
+
const exists = resolvedParams.some(
|
|
553
|
+
(existing) => strict ? existing.id === param.id : existing.id.toLowerCase() === param.id.toLowerCase()
|
|
554
|
+
);
|
|
555
|
+
if (!exists) {
|
|
556
|
+
resolvedParams.push(param);
|
|
557
|
+
resolvedNames.push(param.id);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
const groupSources = [];
|
|
562
|
+
for (const { sourceType, sourceComponent } of sourceComponents) {
|
|
563
|
+
for (const name of propertyNames) {
|
|
564
|
+
const param = this.componentService.findParameter(sourceComponent, name, findOptions);
|
|
565
|
+
if (param && this.componentService.isGroupParameter(param)) {
|
|
566
|
+
const groupSource = `${sourceType}.${name}`;
|
|
567
|
+
if (!groupSources.includes(groupSource)) {
|
|
568
|
+
groupSources.push(groupSource);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
517
572
|
}
|
|
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
573
|
if (groupSources.length > 0) {
|
|
524
574
|
this.logger.info(
|
|
525
575
|
`Resolved properties: ${resolvedNames.join(", ")} (from ${groupSources.join(", ")})`
|
|
@@ -594,9 +644,9 @@ var PropertyPropagatorService = class {
|
|
|
594
644
|
if (componentModified && !whatIf) {
|
|
595
645
|
await this.componentService.saveComponent(targetFilePath, modifiedComponent);
|
|
596
646
|
}
|
|
597
|
-
const compositions = await this.compositionService.
|
|
647
|
+
const compositions = await this.compositionService.findCompositionsByTypes(
|
|
598
648
|
fullCompositionsDir,
|
|
599
|
-
|
|
649
|
+
compositionTypes,
|
|
600
650
|
findOptions
|
|
601
651
|
);
|
|
602
652
|
let modifiedCompositions = 0;
|
|
@@ -643,31 +693,41 @@ var PropertyPropagatorService = class {
|
|
|
643
693
|
modifiedCompositions++;
|
|
644
694
|
}
|
|
645
695
|
}
|
|
646
|
-
let
|
|
696
|
+
let modifiedSourceComponents = 0;
|
|
647
697
|
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
|
-
|
|
698
|
+
for (const { sourceType, sourceFilePath, sourceComponent } of sourceComponents) {
|
|
699
|
+
let modifiedSource = { ...sourceComponent };
|
|
700
|
+
let sourceComponentModified = false;
|
|
701
|
+
for (const param of resolvedParams) {
|
|
702
|
+
const exists = this.componentService.findParameter(modifiedSource, param.id, findOptions);
|
|
703
|
+
if (exists) {
|
|
704
|
+
this.logger.action(whatIf, "DELETE", `Parameter "${param.id}" from ${sourceType}`);
|
|
705
|
+
modifiedSource = this.componentService.removeParameter(modifiedSource, param.id, findOptions);
|
|
706
|
+
sourceComponentModified = true;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
const beforeGroupCount = modifiedSource.parameters?.filter(
|
|
710
|
+
(p) => this.componentService.isGroupParameter(p)
|
|
711
|
+
).length ?? 0;
|
|
712
|
+
modifiedSource = this.componentService.removeEmptyGroups(modifiedSource);
|
|
713
|
+
const afterGroupCount = modifiedSource.parameters?.filter(
|
|
714
|
+
(p) => this.componentService.isGroupParameter(p)
|
|
715
|
+
).length ?? 0;
|
|
716
|
+
if (afterGroupCount < beforeGroupCount) {
|
|
717
|
+
const removedCount = beforeGroupCount - afterGroupCount;
|
|
718
|
+
this.logger.action(
|
|
719
|
+
whatIf,
|
|
720
|
+
"DELETE",
|
|
721
|
+
`${removedCount} empty group(s) from ${sourceType}`
|
|
722
|
+
);
|
|
723
|
+
sourceComponentModified = true;
|
|
724
|
+
}
|
|
725
|
+
if (sourceComponentModified) {
|
|
726
|
+
modifiedSourceComponents++;
|
|
727
|
+
}
|
|
728
|
+
if (sourceComponentModified && !whatIf) {
|
|
729
|
+
await this.componentService.saveComponent(sourceFilePath, modifiedSource);
|
|
730
|
+
}
|
|
671
731
|
}
|
|
672
732
|
for (const { composition, filePath } of compositions) {
|
|
673
733
|
const relativePath = filePath.replace(fullCompositionsDir, "").replace(/^[/\\]/, "");
|
|
@@ -686,11 +746,24 @@ var PropertyPropagatorService = class {
|
|
|
686
746
|
}
|
|
687
747
|
}
|
|
688
748
|
return {
|
|
689
|
-
modifiedComponents: (componentModified ? 1 : 0) +
|
|
749
|
+
modifiedComponents: (componentModified ? 1 : 0) + modifiedSourceComponents,
|
|
690
750
|
modifiedCompositions,
|
|
691
751
|
propagatedInstances
|
|
692
752
|
};
|
|
693
753
|
}
|
|
754
|
+
parsePipeSeparatedValues(value, strict) {
|
|
755
|
+
const entries = value.split("|").map((entry) => entry.trim()).filter((entry) => entry.length > 0);
|
|
756
|
+
const normalized = [];
|
|
757
|
+
for (const entry of entries) {
|
|
758
|
+
const exists = normalized.some(
|
|
759
|
+
(existing) => strict ? existing === entry : existing.toLowerCase() === entry.toLowerCase()
|
|
760
|
+
);
|
|
761
|
+
if (!exists) {
|
|
762
|
+
normalized.push(entry);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
return normalized;
|
|
766
|
+
}
|
|
694
767
|
};
|
|
695
768
|
|
|
696
769
|
// src/core/services/slot-renamer.service.ts
|