@uniformdev/transformer 1.1.30 → 1.1.32
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 +515 -59
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +12 -4
- package/dist/index.js +96 -55
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli/index.ts
|
|
4
|
-
import { Command as
|
|
4
|
+
import { Command as Command16 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/cli/commands/propagate-root-component-property.ts
|
|
7
7
|
import { Command } from "commander";
|
|
@@ -346,18 +346,31 @@ var ComponentService = class {
|
|
|
346
346
|
}
|
|
347
347
|
return component;
|
|
348
348
|
}
|
|
349
|
+
resolveRemoveIds(component, parameterId, options = {}) {
|
|
350
|
+
const param = this.findParameter(component, parameterId, options);
|
|
351
|
+
if (!param) return [];
|
|
352
|
+
if (!this.isGroupParameter(param)) {
|
|
353
|
+
return [param.id];
|
|
354
|
+
}
|
|
355
|
+
const ids = [param.id];
|
|
356
|
+
for (const childId of param.typeConfig?.childrenParams ?? []) {
|
|
357
|
+
ids.push(...this.resolveRemoveIds(component, childId, options));
|
|
358
|
+
}
|
|
359
|
+
return ids;
|
|
360
|
+
}
|
|
349
361
|
removeParameter(component, parameterId, options = {}) {
|
|
350
362
|
const { strict = false } = options;
|
|
351
363
|
if (!component.parameters) {
|
|
352
364
|
return component;
|
|
353
365
|
}
|
|
366
|
+
const idsToRemove = this.resolveRemoveIds(component, parameterId, options);
|
|
354
367
|
component.parameters = component.parameters.filter(
|
|
355
|
-
(p) => !this.compareIds(p.id,
|
|
368
|
+
(p) => !idsToRemove.some((id) => this.compareIds(p.id, id, strict))
|
|
356
369
|
);
|
|
357
370
|
for (const param of component.parameters) {
|
|
358
371
|
if (this.isGroupParameter(param) && param.typeConfig?.childrenParams) {
|
|
359
372
|
param.typeConfig.childrenParams = param.typeConfig.childrenParams.filter(
|
|
360
|
-
(id) => !this.compareIds(id,
|
|
373
|
+
(id) => !idsToRemove.some((removeId) => this.compareIds(id, removeId, strict))
|
|
361
374
|
);
|
|
362
375
|
}
|
|
363
376
|
}
|
|
@@ -4520,11 +4533,20 @@ var ParameterRemoverService = class {
|
|
|
4520
4533
|
if (!param) {
|
|
4521
4534
|
throw new PropertyNotFoundError(parameterId, componentType);
|
|
4522
4535
|
}
|
|
4536
|
+
const allIdsToRemove = this.componentService.resolveRemoveIds(component, parameterId, findOptions);
|
|
4537
|
+
const childIds = allIdsToRemove.filter((id) => !this.compareIds(id, parameterId, strict));
|
|
4523
4538
|
this.logger.action(
|
|
4524
4539
|
whatIf,
|
|
4525
4540
|
"REMOVE",
|
|
4526
4541
|
`Parameter "${parameterId}" from component/${this.fileSystem.getBasename(componentFilePath)}`
|
|
4527
4542
|
);
|
|
4543
|
+
if (childIds.length > 0) {
|
|
4544
|
+
this.logger.action(
|
|
4545
|
+
whatIf,
|
|
4546
|
+
"REMOVE",
|
|
4547
|
+
`Cascade-removing ${childIds.length} child parameter(s) [${childIds.join(", ")}] from component/${this.fileSystem.getBasename(componentFilePath)}`
|
|
4548
|
+
);
|
|
4549
|
+
}
|
|
4528
4550
|
let modifiedComponent = this.componentService.removeParameter(component, parameterId, findOptions);
|
|
4529
4551
|
const beforeGroupCount = modifiedComponent.parameters?.filter(
|
|
4530
4552
|
(p) => this.componentService.isGroupParameter(p)
|
|
@@ -4547,7 +4569,7 @@ var ParameterRemoverService = class {
|
|
|
4547
4569
|
const compositionsResult = await this.removeParameterInDirectory(
|
|
4548
4570
|
fullCompositionsDir,
|
|
4549
4571
|
componentType,
|
|
4550
|
-
|
|
4572
|
+
allIdsToRemove,
|
|
4551
4573
|
whatIf,
|
|
4552
4574
|
strict,
|
|
4553
4575
|
"composition"
|
|
@@ -4555,7 +4577,7 @@ var ParameterRemoverService = class {
|
|
|
4555
4577
|
const compositionPatternsResult = await this.removeParameterInDirectory(
|
|
4556
4578
|
fullCompositionPatternsDir,
|
|
4557
4579
|
componentType,
|
|
4558
|
-
|
|
4580
|
+
allIdsToRemove,
|
|
4559
4581
|
whatIf,
|
|
4560
4582
|
strict,
|
|
4561
4583
|
"compositionPattern"
|
|
@@ -4563,7 +4585,7 @@ var ParameterRemoverService = class {
|
|
|
4563
4585
|
const componentPatternsResult = await this.removeParameterInDirectory(
|
|
4564
4586
|
fullComponentPatternsDir,
|
|
4565
4587
|
componentType,
|
|
4566
|
-
|
|
4588
|
+
allIdsToRemove,
|
|
4567
4589
|
whatIf,
|
|
4568
4590
|
strict,
|
|
4569
4591
|
"componentPattern"
|
|
@@ -4582,7 +4604,7 @@ var ParameterRemoverService = class {
|
|
|
4582
4604
|
instancesUpdated: totalInstances
|
|
4583
4605
|
};
|
|
4584
4606
|
}
|
|
4585
|
-
async removeParameterInDirectory(directory, componentType,
|
|
4607
|
+
async removeParameterInDirectory(directory, componentType, parameterIds, whatIf, strict, label) {
|
|
4586
4608
|
let files;
|
|
4587
4609
|
try {
|
|
4588
4610
|
files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
|
|
@@ -4607,13 +4629,13 @@ var ParameterRemoverService = class {
|
|
|
4607
4629
|
const count = this.removeParameterFromTree(
|
|
4608
4630
|
composition.composition,
|
|
4609
4631
|
componentType,
|
|
4610
|
-
|
|
4632
|
+
parameterIds,
|
|
4611
4633
|
strict
|
|
4612
4634
|
);
|
|
4613
4635
|
const overridesCount = this.removeParameterFromOverrides(
|
|
4614
4636
|
composition,
|
|
4615
4637
|
componentType,
|
|
4616
|
-
|
|
4638
|
+
parameterIds,
|
|
4617
4639
|
strict
|
|
4618
4640
|
);
|
|
4619
4641
|
const totalCount = count + overridesCount;
|
|
@@ -4633,11 +4655,11 @@ var ParameterRemoverService = class {
|
|
|
4633
4655
|
}
|
|
4634
4656
|
return { filesModified, instancesUpdated };
|
|
4635
4657
|
}
|
|
4636
|
-
removeParameterFromTree(node, componentType,
|
|
4658
|
+
removeParameterFromTree(node, componentType, parameterIds, strict) {
|
|
4637
4659
|
let count = 0;
|
|
4638
4660
|
if (this.compareIds(node.type, componentType, strict) && node.parameters) {
|
|
4639
|
-
const removed = this.
|
|
4640
|
-
if (removed) {
|
|
4661
|
+
const removed = this.removeKeysFromMap(node.parameters, parameterIds, strict);
|
|
4662
|
+
if (removed > 0) {
|
|
4641
4663
|
count++;
|
|
4642
4664
|
}
|
|
4643
4665
|
}
|
|
@@ -4645,13 +4667,13 @@ var ParameterRemoverService = class {
|
|
|
4645
4667
|
for (const slotInstances of Object.values(node.slots)) {
|
|
4646
4668
|
if (!Array.isArray(slotInstances)) continue;
|
|
4647
4669
|
for (const instance of slotInstances) {
|
|
4648
|
-
count += this.removeParameterFromTree(instance, componentType,
|
|
4670
|
+
count += this.removeParameterFromTree(instance, componentType, parameterIds, strict);
|
|
4649
4671
|
}
|
|
4650
4672
|
}
|
|
4651
4673
|
}
|
|
4652
4674
|
return count;
|
|
4653
4675
|
}
|
|
4654
|
-
removeParameterFromOverrides(composition, componentType,
|
|
4676
|
+
removeParameterFromOverrides(composition, componentType, parameterIds, strict) {
|
|
4655
4677
|
if (!composition.composition._overrides) {
|
|
4656
4678
|
return 0;
|
|
4657
4679
|
}
|
|
@@ -4660,8 +4682,8 @@ var ParameterRemoverService = class {
|
|
|
4660
4682
|
const rootId = composition.composition._id;
|
|
4661
4683
|
const rootOverrides = composition.composition._overrides[rootId];
|
|
4662
4684
|
if (rootOverrides?.parameters) {
|
|
4663
|
-
const removed = this.
|
|
4664
|
-
if (removed) {
|
|
4685
|
+
const removed = this.removeKeysFromMap(rootOverrides.parameters, parameterIds, strict);
|
|
4686
|
+
if (removed > 0) {
|
|
4665
4687
|
count++;
|
|
4666
4688
|
}
|
|
4667
4689
|
}
|
|
@@ -4671,14 +4693,14 @@ var ParameterRemoverService = class {
|
|
|
4671
4693
|
composition.composition,
|
|
4672
4694
|
composition.composition._overrides,
|
|
4673
4695
|
componentType,
|
|
4674
|
-
|
|
4696
|
+
parameterIds,
|
|
4675
4697
|
strict,
|
|
4676
4698
|
counter
|
|
4677
4699
|
);
|
|
4678
4700
|
count += counter.count;
|
|
4679
4701
|
return count;
|
|
4680
4702
|
}
|
|
4681
|
-
removeOverridesForMatchingInstances(node, overrides, componentType,
|
|
4703
|
+
removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict, counter) {
|
|
4682
4704
|
if (node.slots) {
|
|
4683
4705
|
for (const slotInstances of Object.values(node.slots)) {
|
|
4684
4706
|
if (!Array.isArray(slotInstances)) continue;
|
|
@@ -4686,8 +4708,8 @@ var ParameterRemoverService = class {
|
|
|
4686
4708
|
if (this.compareIds(instance.type, componentType, strict) && instance._id) {
|
|
4687
4709
|
const instanceOverrides = overrides[instance._id];
|
|
4688
4710
|
if (instanceOverrides?.parameters) {
|
|
4689
|
-
const removed = this.
|
|
4690
|
-
if (removed) {
|
|
4711
|
+
const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
|
|
4712
|
+
if (removed > 0) {
|
|
4691
4713
|
counter.count++;
|
|
4692
4714
|
}
|
|
4693
4715
|
}
|
|
@@ -4696,7 +4718,7 @@ var ParameterRemoverService = class {
|
|
|
4696
4718
|
instance,
|
|
4697
4719
|
overrides,
|
|
4698
4720
|
componentType,
|
|
4699
|
-
|
|
4721
|
+
parameterIds,
|
|
4700
4722
|
strict,
|
|
4701
4723
|
counter
|
|
4702
4724
|
);
|
|
@@ -4704,15 +4726,16 @@ var ParameterRemoverService = class {
|
|
|
4704
4726
|
}
|
|
4705
4727
|
}
|
|
4706
4728
|
}
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4729
|
+
removeKeysFromMap(map, keys, strict) {
|
|
4730
|
+
let removed = 0;
|
|
4731
|
+
for (const key of keys) {
|
|
4732
|
+
const matchingKey = Object.keys(map).find((k) => this.compareIds(k, key, strict));
|
|
4733
|
+
if (matchingKey) {
|
|
4734
|
+
delete map[matchingKey];
|
|
4735
|
+
removed++;
|
|
4736
|
+
}
|
|
4713
4737
|
}
|
|
4714
|
-
|
|
4715
|
-
return true;
|
|
4738
|
+
return removed;
|
|
4716
4739
|
}
|
|
4717
4740
|
};
|
|
4718
4741
|
|
|
@@ -4774,8 +4797,9 @@ import { Command as Command12 } from "commander";
|
|
|
4774
4797
|
|
|
4775
4798
|
// src/core/services/field-remover.service.ts
|
|
4776
4799
|
var FieldRemoverService = class {
|
|
4777
|
-
constructor(fileSystem, logger) {
|
|
4800
|
+
constructor(fileSystem, componentService, logger) {
|
|
4778
4801
|
this.fileSystem = fileSystem;
|
|
4802
|
+
this.componentService = componentService;
|
|
4779
4803
|
this.logger = logger;
|
|
4780
4804
|
}
|
|
4781
4805
|
compareIds(id1, id2, strict) {
|
|
@@ -4787,6 +4811,7 @@ var FieldRemoverService = class {
|
|
|
4787
4811
|
async remove(options) {
|
|
4788
4812
|
const {
|
|
4789
4813
|
rootDir,
|
|
4814
|
+
componentsDir,
|
|
4790
4815
|
compositionsDir,
|
|
4791
4816
|
compositionPatternsDir,
|
|
4792
4817
|
componentPatternsDir,
|
|
@@ -4795,14 +4820,29 @@ var FieldRemoverService = class {
|
|
|
4795
4820
|
whatIf,
|
|
4796
4821
|
strict
|
|
4797
4822
|
} = options;
|
|
4823
|
+
const findOptions = { strict };
|
|
4824
|
+
const fullComponentsDir = this.fileSystem.resolvePath(rootDir, componentsDir);
|
|
4798
4825
|
const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
|
|
4799
4826
|
const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
|
|
4800
4827
|
const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
|
|
4828
|
+
let allIdsToRemove = [parameterId];
|
|
4829
|
+
try {
|
|
4830
|
+
const { component } = await this.componentService.loadComponent(fullComponentsDir, componentType, findOptions);
|
|
4831
|
+
const resolved = this.componentService.resolveRemoveIds(component, parameterId, findOptions);
|
|
4832
|
+
if (resolved.length > 0) {
|
|
4833
|
+
allIdsToRemove = resolved;
|
|
4834
|
+
}
|
|
4835
|
+
} catch {
|
|
4836
|
+
}
|
|
4837
|
+
const childIds = allIdsToRemove.filter((id) => id.toLowerCase() !== parameterId.toLowerCase());
|
|
4838
|
+
if (childIds.length > 0) {
|
|
4839
|
+
this.logger.info(`Cascade-removing ${childIds.length} child field(s) [${childIds.join(", ")}] along with "${parameterId}"`);
|
|
4840
|
+
}
|
|
4801
4841
|
this.logger.info(`Removing field "${parameterId}" from instances of ${componentType}`);
|
|
4802
4842
|
const compositionsResult = await this.removeFieldInDirectory(
|
|
4803
4843
|
fullCompositionsDir,
|
|
4804
4844
|
componentType,
|
|
4805
|
-
|
|
4845
|
+
allIdsToRemove,
|
|
4806
4846
|
whatIf,
|
|
4807
4847
|
strict,
|
|
4808
4848
|
"composition"
|
|
@@ -4810,7 +4850,7 @@ var FieldRemoverService = class {
|
|
|
4810
4850
|
const compositionPatternsResult = await this.removeFieldInDirectory(
|
|
4811
4851
|
fullCompositionPatternsDir,
|
|
4812
4852
|
componentType,
|
|
4813
|
-
|
|
4853
|
+
allIdsToRemove,
|
|
4814
4854
|
whatIf,
|
|
4815
4855
|
strict,
|
|
4816
4856
|
"compositionPattern"
|
|
@@ -4818,7 +4858,7 @@ var FieldRemoverService = class {
|
|
|
4818
4858
|
const componentPatternsResult = await this.removeFieldInDirectory(
|
|
4819
4859
|
fullComponentPatternsDir,
|
|
4820
4860
|
componentType,
|
|
4821
|
-
|
|
4861
|
+
allIdsToRemove,
|
|
4822
4862
|
whatIf,
|
|
4823
4863
|
strict,
|
|
4824
4864
|
"componentPattern"
|
|
@@ -4836,7 +4876,7 @@ var FieldRemoverService = class {
|
|
|
4836
4876
|
instancesUpdated: totalInstances
|
|
4837
4877
|
};
|
|
4838
4878
|
}
|
|
4839
|
-
async removeFieldInDirectory(directory, componentType,
|
|
4879
|
+
async removeFieldInDirectory(directory, componentType, parameterIds, whatIf, strict, label) {
|
|
4840
4880
|
let files;
|
|
4841
4881
|
try {
|
|
4842
4882
|
files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
|
|
@@ -4861,13 +4901,13 @@ var FieldRemoverService = class {
|
|
|
4861
4901
|
const treeCount = this.removeFieldFromTree(
|
|
4862
4902
|
composition.composition,
|
|
4863
4903
|
componentType,
|
|
4864
|
-
|
|
4904
|
+
parameterIds,
|
|
4865
4905
|
strict
|
|
4866
4906
|
);
|
|
4867
4907
|
const overridesCount = this.removeFieldFromOverrides(
|
|
4868
4908
|
composition,
|
|
4869
4909
|
componentType,
|
|
4870
|
-
|
|
4910
|
+
parameterIds,
|
|
4871
4911
|
strict
|
|
4872
4912
|
);
|
|
4873
4913
|
const totalCount = treeCount + overridesCount;
|
|
@@ -4887,11 +4927,11 @@ var FieldRemoverService = class {
|
|
|
4887
4927
|
}
|
|
4888
4928
|
return { filesModified, instancesUpdated };
|
|
4889
4929
|
}
|
|
4890
|
-
removeFieldFromTree(node, componentType,
|
|
4930
|
+
removeFieldFromTree(node, componentType, parameterIds, strict) {
|
|
4891
4931
|
let count = 0;
|
|
4892
4932
|
if (this.compareIds(node.type, componentType, strict) && node.parameters) {
|
|
4893
|
-
const removed = this.
|
|
4894
|
-
if (removed) {
|
|
4933
|
+
const removed = this.removeKeysFromMap(node.parameters, parameterIds, strict);
|
|
4934
|
+
if (removed > 0) {
|
|
4895
4935
|
count++;
|
|
4896
4936
|
}
|
|
4897
4937
|
}
|
|
@@ -4899,13 +4939,13 @@ var FieldRemoverService = class {
|
|
|
4899
4939
|
for (const slotInstances of Object.values(node.slots)) {
|
|
4900
4940
|
if (!Array.isArray(slotInstances)) continue;
|
|
4901
4941
|
for (const instance of slotInstances) {
|
|
4902
|
-
count += this.removeFieldFromTree(instance, componentType,
|
|
4942
|
+
count += this.removeFieldFromTree(instance, componentType, parameterIds, strict);
|
|
4903
4943
|
}
|
|
4904
4944
|
}
|
|
4905
4945
|
}
|
|
4906
4946
|
return count;
|
|
4907
4947
|
}
|
|
4908
|
-
removeFieldFromOverrides(composition, componentType,
|
|
4948
|
+
removeFieldFromOverrides(composition, componentType, parameterIds, strict) {
|
|
4909
4949
|
if (!composition.composition._overrides) {
|
|
4910
4950
|
return 0;
|
|
4911
4951
|
}
|
|
@@ -4914,8 +4954,8 @@ var FieldRemoverService = class {
|
|
|
4914
4954
|
const rootId = composition.composition._id;
|
|
4915
4955
|
const rootOverrides = composition.composition._overrides[rootId];
|
|
4916
4956
|
if (rootOverrides?.parameters) {
|
|
4917
|
-
const removed = this.
|
|
4918
|
-
if (removed) {
|
|
4957
|
+
const removed = this.removeKeysFromMap(rootOverrides.parameters, parameterIds, strict);
|
|
4958
|
+
if (removed > 0) {
|
|
4919
4959
|
count++;
|
|
4920
4960
|
}
|
|
4921
4961
|
}
|
|
@@ -4924,12 +4964,12 @@ var FieldRemoverService = class {
|
|
|
4924
4964
|
composition.composition,
|
|
4925
4965
|
composition.composition._overrides,
|
|
4926
4966
|
componentType,
|
|
4927
|
-
|
|
4967
|
+
parameterIds,
|
|
4928
4968
|
strict
|
|
4929
4969
|
);
|
|
4930
4970
|
return count;
|
|
4931
4971
|
}
|
|
4932
|
-
removeOverridesForMatchingInstances(node, overrides, componentType,
|
|
4972
|
+
removeOverridesForMatchingInstances(node, overrides, componentType, parameterIds, strict) {
|
|
4933
4973
|
let count = 0;
|
|
4934
4974
|
if (node.slots) {
|
|
4935
4975
|
for (const slotInstances of Object.values(node.slots)) {
|
|
@@ -4938,8 +4978,8 @@ var FieldRemoverService = class {
|
|
|
4938
4978
|
if (this.compareIds(instance.type, componentType, strict) && instance._id) {
|
|
4939
4979
|
const instanceOverrides = overrides[instance._id];
|
|
4940
4980
|
if (instanceOverrides?.parameters) {
|
|
4941
|
-
const removed = this.
|
|
4942
|
-
if (removed) {
|
|
4981
|
+
const removed = this.removeKeysFromMap(instanceOverrides.parameters, parameterIds, strict);
|
|
4982
|
+
if (removed > 0) {
|
|
4943
4983
|
count++;
|
|
4944
4984
|
}
|
|
4945
4985
|
}
|
|
@@ -4948,7 +4988,7 @@ var FieldRemoverService = class {
|
|
|
4948
4988
|
instance,
|
|
4949
4989
|
overrides,
|
|
4950
4990
|
componentType,
|
|
4951
|
-
|
|
4991
|
+
parameterIds,
|
|
4952
4992
|
strict
|
|
4953
4993
|
);
|
|
4954
4994
|
}
|
|
@@ -4956,15 +4996,16 @@ var FieldRemoverService = class {
|
|
|
4956
4996
|
}
|
|
4957
4997
|
return count;
|
|
4958
4998
|
}
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4999
|
+
removeKeysFromMap(map, keys, strict) {
|
|
5000
|
+
let removed = 0;
|
|
5001
|
+
for (const key of keys) {
|
|
5002
|
+
const matchingKey = Object.keys(map).find((k) => this.compareIds(k, key, strict));
|
|
5003
|
+
if (matchingKey) {
|
|
5004
|
+
delete map[matchingKey];
|
|
5005
|
+
removed++;
|
|
5006
|
+
}
|
|
4965
5007
|
}
|
|
4966
|
-
|
|
4967
|
-
return true;
|
|
5008
|
+
return removed;
|
|
4968
5009
|
}
|
|
4969
5010
|
};
|
|
4970
5011
|
|
|
@@ -4993,10 +5034,12 @@ function createRemoveFieldCommand() {
|
|
|
4993
5034
|
};
|
|
4994
5035
|
const logger = new Logger();
|
|
4995
5036
|
const fileSystem = new FileSystemService();
|
|
4996
|
-
const
|
|
5037
|
+
const componentService = new ComponentService(fileSystem);
|
|
5038
|
+
const remover = new FieldRemoverService(fileSystem, componentService, logger);
|
|
4997
5039
|
try {
|
|
4998
5040
|
const result = await remover.remove({
|
|
4999
5041
|
rootDir: options.rootDir,
|
|
5042
|
+
componentsDir: options.componentsDir,
|
|
5000
5043
|
compositionsDir: options.compositionsDir,
|
|
5001
5044
|
compositionPatternsDir: options.compositionPatternsDir,
|
|
5002
5045
|
componentPatternsDir: options.componentPatternsDir,
|
|
@@ -5334,10 +5377,422 @@ function createAddContentTypeFieldCommand() {
|
|
|
5334
5377
|
return command;
|
|
5335
5378
|
}
|
|
5336
5379
|
|
|
5380
|
+
// src/cli/commands/flatten-block-field.ts
|
|
5381
|
+
import { Command as Command15 } from "commander";
|
|
5382
|
+
|
|
5383
|
+
// src/core/services/block-field-flattener.service.ts
|
|
5384
|
+
var BlockFieldFlattenerService = class {
|
|
5385
|
+
constructor(fileSystem, componentService, logger) {
|
|
5386
|
+
this.fileSystem = fileSystem;
|
|
5387
|
+
this.componentService = componentService;
|
|
5388
|
+
this.logger = logger;
|
|
5389
|
+
}
|
|
5390
|
+
compareIds(id1, id2, strict) {
|
|
5391
|
+
if (strict) return id1 === id2;
|
|
5392
|
+
return id1.toLowerCase() === id2.toLowerCase();
|
|
5393
|
+
}
|
|
5394
|
+
async loadContentType(contentTypesDir, contentTypeId, strict) {
|
|
5395
|
+
const jsonPath = this.fileSystem.joinPath(contentTypesDir, `${contentTypeId}.json`);
|
|
5396
|
+
const yamlPath = this.fileSystem.joinPath(contentTypesDir, `${contentTypeId}.yaml`);
|
|
5397
|
+
const ymlPath = this.fileSystem.joinPath(contentTypesDir, `${contentTypeId}.yml`);
|
|
5398
|
+
if (await this.fileSystem.fileExists(jsonPath)) {
|
|
5399
|
+
return { contentType: await this.fileSystem.readFile(jsonPath), filePath: jsonPath };
|
|
5400
|
+
}
|
|
5401
|
+
if (await this.fileSystem.fileExists(yamlPath)) {
|
|
5402
|
+
return { contentType: await this.fileSystem.readFile(yamlPath), filePath: yamlPath };
|
|
5403
|
+
}
|
|
5404
|
+
if (await this.fileSystem.fileExists(ymlPath)) {
|
|
5405
|
+
return { contentType: await this.fileSystem.readFile(ymlPath), filePath: ymlPath };
|
|
5406
|
+
}
|
|
5407
|
+
if (!strict) {
|
|
5408
|
+
const files = await this.fileSystem.findFiles(contentTypesDir, "*.{json,yaml,yml}");
|
|
5409
|
+
for (const filePath of files) {
|
|
5410
|
+
const basename2 = this.fileSystem.getBasename(filePath);
|
|
5411
|
+
const nameWithoutExt = basename2.replace(/\.(json|yaml|yml)$/i, "");
|
|
5412
|
+
if (nameWithoutExt.toLowerCase() === contentTypeId.toLowerCase()) {
|
|
5413
|
+
return { contentType: await this.fileSystem.readFile(filePath), filePath };
|
|
5414
|
+
}
|
|
5415
|
+
}
|
|
5416
|
+
}
|
|
5417
|
+
throw new TransformError(`Content type not found: ${contentTypeId} (searched: ${contentTypesDir})`);
|
|
5418
|
+
}
|
|
5419
|
+
async flatten(options) {
|
|
5420
|
+
const {
|
|
5421
|
+
rootDir,
|
|
5422
|
+
componentsDir,
|
|
5423
|
+
compositionsDir,
|
|
5424
|
+
compositionPatternsDir,
|
|
5425
|
+
componentPatternsDir,
|
|
5426
|
+
contentTypesDir,
|
|
5427
|
+
componentId,
|
|
5428
|
+
parameterId,
|
|
5429
|
+
whatIf,
|
|
5430
|
+
strict,
|
|
5431
|
+
excludeFields = []
|
|
5432
|
+
} = options;
|
|
5433
|
+
const findOptions = { strict };
|
|
5434
|
+
const fullComponentsDir = this.fileSystem.resolvePath(rootDir, componentsDir);
|
|
5435
|
+
const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
|
|
5436
|
+
const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
|
|
5437
|
+
const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
|
|
5438
|
+
const fullContentTypesDir = this.fileSystem.resolvePath(rootDir, contentTypesDir);
|
|
5439
|
+
this.logger.info(`Loading component: ${componentId}`);
|
|
5440
|
+
const { component, filePath: componentFilePath } = await this.componentService.loadComponent(fullComponentsDir, componentId, findOptions);
|
|
5441
|
+
const blockParam = this.componentService.findParameter(component, parameterId, findOptions);
|
|
5442
|
+
if (!blockParam) {
|
|
5443
|
+
throw new PropertyNotFoundError(parameterId, componentId);
|
|
5444
|
+
}
|
|
5445
|
+
const allowedTypes = blockParam.typeConfig?.allowedTypes;
|
|
5446
|
+
if (!allowedTypes || allowedTypes.length === 0) {
|
|
5447
|
+
throw new TransformError(
|
|
5448
|
+
`Parameter "${parameterId}" on component "${componentId}" has no allowedTypes in typeConfig`
|
|
5449
|
+
);
|
|
5450
|
+
}
|
|
5451
|
+
if (allowedTypes.length > 1) {
|
|
5452
|
+
throw new TransformError(
|
|
5453
|
+
`Cannot flatten: parameter "${parameterId}" allows multiple block types: ${allowedTypes.join(", ")}`
|
|
5454
|
+
);
|
|
5455
|
+
}
|
|
5456
|
+
const blockContentTypeId = allowedTypes[0];
|
|
5457
|
+
this.logger.info(`Block content type: ${blockContentTypeId}`);
|
|
5458
|
+
const { contentType: blockContentType } = await this.loadContentType(fullContentTypesDir, blockContentTypeId, strict);
|
|
5459
|
+
const excludeSet = new Set(excludeFields.map((id) => id.toLowerCase()));
|
|
5460
|
+
const blockFields = (blockContentType.fields ?? []).filter(
|
|
5461
|
+
(f) => !excludeSet.has(f.id.toLowerCase())
|
|
5462
|
+
);
|
|
5463
|
+
const blockFieldIds = blockFields.map((f) => f.id);
|
|
5464
|
+
this.logger.info(
|
|
5465
|
+
`Block content type: ${blockContentTypeId} (${blockFields.length} field(s): ${blockFieldIds.join(", ")})`
|
|
5466
|
+
);
|
|
5467
|
+
for (const field of blockFields) {
|
|
5468
|
+
const existingParam = this.componentService.findParameter(component, field.id, findOptions);
|
|
5469
|
+
if (existingParam && !this.compareIds(existingParam.id, parameterId, strict)) {
|
|
5470
|
+
throw new TransformError(
|
|
5471
|
+
`Cannot flatten: field "${field.id}" from block type "${blockContentTypeId}" conflicts with existing parameter "${existingParam.id}" on component "${componentId}"`
|
|
5472
|
+
);
|
|
5473
|
+
}
|
|
5474
|
+
}
|
|
5475
|
+
this.logger.info("Validation pass: scanning compositions...");
|
|
5476
|
+
await this.validateDirectory(fullCompositionsDir, componentId, parameterId, strict, "composition");
|
|
5477
|
+
await this.validateDirectory(fullCompositionPatternsDir, componentId, parameterId, strict, "compositionPattern");
|
|
5478
|
+
await this.validateDirectory(fullComponentPatternsDir, componentId, parameterId, strict, "componentPattern");
|
|
5479
|
+
this.logger.action(
|
|
5480
|
+
whatIf,
|
|
5481
|
+
"REMOVE",
|
|
5482
|
+
`parameter "${parameterId}" from component/${this.fileSystem.getBasename(componentFilePath)}`
|
|
5483
|
+
);
|
|
5484
|
+
this.logger.action(
|
|
5485
|
+
whatIf,
|
|
5486
|
+
"ADD",
|
|
5487
|
+
`parameters "${blockFieldIds.join(", ")}" to component/${this.fileSystem.getBasename(componentFilePath)}`
|
|
5488
|
+
);
|
|
5489
|
+
let updatedComponent = this.componentService.removeParameter(component, parameterId, findOptions);
|
|
5490
|
+
updatedComponent = this.componentService.removeEmptyGroups(updatedComponent);
|
|
5491
|
+
for (const field of blockFields) {
|
|
5492
|
+
updatedComponent = this.componentService.addParameterToComponent(
|
|
5493
|
+
updatedComponent,
|
|
5494
|
+
{ id: field.id, name: field.name, type: field.type, ...field.typeConfig ? { typeConfig: field.typeConfig } : {}, ...this.extraFieldProps(field) },
|
|
5495
|
+
findOptions
|
|
5496
|
+
);
|
|
5497
|
+
}
|
|
5498
|
+
if (!whatIf) {
|
|
5499
|
+
await this.componentService.saveComponent(componentFilePath, updatedComponent);
|
|
5500
|
+
}
|
|
5501
|
+
const compositionsResult = await this.flattenInDirectory(
|
|
5502
|
+
fullCompositionsDir,
|
|
5503
|
+
componentId,
|
|
5504
|
+
parameterId,
|
|
5505
|
+
whatIf,
|
|
5506
|
+
strict,
|
|
5507
|
+
"composition"
|
|
5508
|
+
);
|
|
5509
|
+
const compositionPatternsResult = await this.flattenInDirectory(
|
|
5510
|
+
fullCompositionPatternsDir,
|
|
5511
|
+
componentId,
|
|
5512
|
+
parameterId,
|
|
5513
|
+
whatIf,
|
|
5514
|
+
strict,
|
|
5515
|
+
"compositionPattern"
|
|
5516
|
+
);
|
|
5517
|
+
const componentPatternsResult = await this.flattenInDirectory(
|
|
5518
|
+
fullComponentPatternsDir,
|
|
5519
|
+
componentId,
|
|
5520
|
+
parameterId,
|
|
5521
|
+
whatIf,
|
|
5522
|
+
strict,
|
|
5523
|
+
"componentPattern"
|
|
5524
|
+
);
|
|
5525
|
+
const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
|
|
5526
|
+
const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
|
|
5527
|
+
this.logger.info("");
|
|
5528
|
+
this.logger.info(
|
|
5529
|
+
`Summary: 1 component definition updated, ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
|
|
5530
|
+
);
|
|
5531
|
+
return {
|
|
5532
|
+
componentDefinitionUpdated: true,
|
|
5533
|
+
compositionsModified: compositionsResult.filesModified,
|
|
5534
|
+
compositionPatternsModified: compositionPatternsResult.filesModified,
|
|
5535
|
+
componentPatternsModified: componentPatternsResult.filesModified,
|
|
5536
|
+
instancesUpdated: totalInstances
|
|
5537
|
+
};
|
|
5538
|
+
}
|
|
5539
|
+
// Extract extra field props beyond id, name, type, typeConfig
|
|
5540
|
+
extraFieldProps(field) {
|
|
5541
|
+
const { id: _id, name: _name, type: _type, typeConfig: _tc, ...rest } = field;
|
|
5542
|
+
return rest;
|
|
5543
|
+
}
|
|
5544
|
+
async validateDirectory(directory, componentId, parameterId, strict, label) {
|
|
5545
|
+
let files;
|
|
5546
|
+
try {
|
|
5547
|
+
files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
|
|
5548
|
+
} catch {
|
|
5549
|
+
return;
|
|
5550
|
+
}
|
|
5551
|
+
for (const filePath of files) {
|
|
5552
|
+
let composition;
|
|
5553
|
+
try {
|
|
5554
|
+
composition = await this.fileSystem.readFile(filePath);
|
|
5555
|
+
} catch {
|
|
5556
|
+
continue;
|
|
5557
|
+
}
|
|
5558
|
+
if (!composition?.composition) continue;
|
|
5559
|
+
this.validateBlocksInTree(composition.composition, componentId, parameterId, strict, filePath, label);
|
|
5560
|
+
this.validateBlocksInOverrides(composition, componentId, parameterId, strict, filePath, label);
|
|
5561
|
+
}
|
|
5562
|
+
}
|
|
5563
|
+
validateBlocksInTree(node, componentId, parameterId, strict, filePath, label) {
|
|
5564
|
+
if (this.compareIds(node.type, componentId, strict) && node.parameters) {
|
|
5565
|
+
const blockParamValue = this.findKeyInMap(node.parameters, parameterId, strict);
|
|
5566
|
+
if (blockParamValue) {
|
|
5567
|
+
const items = blockParamValue.value;
|
|
5568
|
+
if (Array.isArray(items) && items.length > 1) {
|
|
5569
|
+
throw new TransformError(
|
|
5570
|
+
`Cannot flatten: more than one block item in parameter "${parameterId}" of "${componentId}" instance "${node._id ?? "(root)"}" in file "${label}/${this.fileSystem.getBasename(filePath)}"`
|
|
5571
|
+
);
|
|
5572
|
+
}
|
|
5573
|
+
}
|
|
5574
|
+
}
|
|
5575
|
+
if (node.slots) {
|
|
5576
|
+
for (const slotInstances of Object.values(node.slots)) {
|
|
5577
|
+
if (!Array.isArray(slotInstances)) continue;
|
|
5578
|
+
for (const instance of slotInstances) {
|
|
5579
|
+
this.validateBlocksInTree(instance, componentId, parameterId, strict, filePath, label);
|
|
5580
|
+
}
|
|
5581
|
+
}
|
|
5582
|
+
}
|
|
5583
|
+
}
|
|
5584
|
+
validateBlocksInOverrides(composition, componentId, parameterId, strict, filePath, label) {
|
|
5585
|
+
if (!composition.composition._overrides) return;
|
|
5586
|
+
for (const [overrideId, override] of Object.entries(composition.composition._overrides)) {
|
|
5587
|
+
if (!override.parameters) continue;
|
|
5588
|
+
const blockParamValue = this.findKeyInMap(override.parameters, parameterId, strict);
|
|
5589
|
+
if (blockParamValue) {
|
|
5590
|
+
const items = blockParamValue.value;
|
|
5591
|
+
if (Array.isArray(items) && items.length > 1) {
|
|
5592
|
+
throw new TransformError(
|
|
5593
|
+
`Cannot flatten: more than one block item in _overrides["${overrideId}"] parameter "${parameterId}" in file "${label}/${this.fileSystem.getBasename(filePath)}"`
|
|
5594
|
+
);
|
|
5595
|
+
}
|
|
5596
|
+
}
|
|
5597
|
+
}
|
|
5598
|
+
}
|
|
5599
|
+
async flattenInDirectory(directory, componentId, parameterId, whatIf, strict, label) {
|
|
5600
|
+
let files;
|
|
5601
|
+
try {
|
|
5602
|
+
files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
|
|
5603
|
+
} catch {
|
|
5604
|
+
return { filesModified: 0, instancesUpdated: 0 };
|
|
5605
|
+
}
|
|
5606
|
+
if (files.length === 0) return { filesModified: 0, instancesUpdated: 0 };
|
|
5607
|
+
let filesModified = 0;
|
|
5608
|
+
let instancesUpdated = 0;
|
|
5609
|
+
for (const filePath of files) {
|
|
5610
|
+
let composition;
|
|
5611
|
+
try {
|
|
5612
|
+
composition = await this.fileSystem.readFile(filePath);
|
|
5613
|
+
} catch {
|
|
5614
|
+
continue;
|
|
5615
|
+
}
|
|
5616
|
+
if (!composition?.composition) continue;
|
|
5617
|
+
const treeCount = this.flattenBlocksInTree(composition.composition, componentId, parameterId, strict);
|
|
5618
|
+
const overridesCount = this.flattenBlocksInOverrides(composition, componentId, parameterId, strict);
|
|
5619
|
+
const totalCount = treeCount + overridesCount;
|
|
5620
|
+
if (totalCount > 0) {
|
|
5621
|
+
const relativePath = filePath.replace(directory, "").replace(/^[/\\]/, "");
|
|
5622
|
+
this.logger.action(
|
|
5623
|
+
whatIf,
|
|
5624
|
+
"UPDATE",
|
|
5625
|
+
`${label}/${relativePath} (${totalCount} instance(s) of ${componentId})`
|
|
5626
|
+
);
|
|
5627
|
+
if (!whatIf) {
|
|
5628
|
+
await this.fileSystem.writeFile(filePath, composition);
|
|
5629
|
+
}
|
|
5630
|
+
filesModified++;
|
|
5631
|
+
instancesUpdated += totalCount;
|
|
5632
|
+
}
|
|
5633
|
+
}
|
|
5634
|
+
return { filesModified, instancesUpdated };
|
|
5635
|
+
}
|
|
5636
|
+
flattenBlocksInTree(node, componentId, parameterId, strict) {
|
|
5637
|
+
let count = 0;
|
|
5638
|
+
if (this.compareIds(node.type, componentId, strict) && node.parameters) {
|
|
5639
|
+
const matchingKey = this.findKeyName(node.parameters, parameterId, strict);
|
|
5640
|
+
if (matchingKey !== void 0) {
|
|
5641
|
+
const blockParamValue = node.parameters[matchingKey];
|
|
5642
|
+
const items = blockParamValue.value;
|
|
5643
|
+
if (Array.isArray(items) && items.length === 1) {
|
|
5644
|
+
const blockItem = items[0];
|
|
5645
|
+
for (const [fieldId, fieldValue] of Object.entries(blockItem.fields ?? {})) {
|
|
5646
|
+
node.parameters[fieldId] = fieldValue;
|
|
5647
|
+
}
|
|
5648
|
+
}
|
|
5649
|
+
delete node.parameters[matchingKey];
|
|
5650
|
+
count++;
|
|
5651
|
+
}
|
|
5652
|
+
}
|
|
5653
|
+
if (node.slots) {
|
|
5654
|
+
for (const slotInstances of Object.values(node.slots)) {
|
|
5655
|
+
if (!Array.isArray(slotInstances)) continue;
|
|
5656
|
+
for (const instance of slotInstances) {
|
|
5657
|
+
count += this.flattenBlocksInTree(instance, componentId, parameterId, strict);
|
|
5658
|
+
}
|
|
5659
|
+
}
|
|
5660
|
+
}
|
|
5661
|
+
return count;
|
|
5662
|
+
}
|
|
5663
|
+
flattenBlocksInOverrides(composition, componentId, parameterId, strict) {
|
|
5664
|
+
if (!composition.composition._overrides) return 0;
|
|
5665
|
+
let count = 0;
|
|
5666
|
+
if (this.compareIds(composition.composition.type, componentId, strict)) {
|
|
5667
|
+
count += this.flattenOverrideMap(composition.composition._overrides, parameterId, strict);
|
|
5668
|
+
}
|
|
5669
|
+
count += this.flattenOverridesForMatchingInstances(
|
|
5670
|
+
composition.composition,
|
|
5671
|
+
composition.composition._overrides,
|
|
5672
|
+
componentId,
|
|
5673
|
+
parameterId,
|
|
5674
|
+
strict
|
|
5675
|
+
);
|
|
5676
|
+
return count;
|
|
5677
|
+
}
|
|
5678
|
+
flattenOverrideMap(overrides, parameterId, strict) {
|
|
5679
|
+
let count = 0;
|
|
5680
|
+
for (const override of Object.values(overrides)) {
|
|
5681
|
+
if (!override.parameters) continue;
|
|
5682
|
+
const matchingKey = this.findKeyName(override.parameters, parameterId, strict);
|
|
5683
|
+
if (matchingKey === void 0) continue;
|
|
5684
|
+
const blockParamValue = override.parameters[matchingKey];
|
|
5685
|
+
const items = blockParamValue.value;
|
|
5686
|
+
if (Array.isArray(items) && items.length === 1) {
|
|
5687
|
+
const blockItem = items[0];
|
|
5688
|
+
for (const [fieldId, fieldValue] of Object.entries(blockItem.fields ?? {})) {
|
|
5689
|
+
override.parameters[fieldId] = fieldValue;
|
|
5690
|
+
}
|
|
5691
|
+
}
|
|
5692
|
+
delete override.parameters[matchingKey];
|
|
5693
|
+
count++;
|
|
5694
|
+
}
|
|
5695
|
+
return count;
|
|
5696
|
+
}
|
|
5697
|
+
flattenOverridesForMatchingInstances(node, overrides, componentId, parameterId, strict) {
|
|
5698
|
+
let count = 0;
|
|
5699
|
+
if (node.slots) {
|
|
5700
|
+
for (const slotInstances of Object.values(node.slots)) {
|
|
5701
|
+
if (!Array.isArray(slotInstances)) continue;
|
|
5702
|
+
for (const instance of slotInstances) {
|
|
5703
|
+
if (this.compareIds(instance.type, componentId, strict) && instance._id) {
|
|
5704
|
+
const override = overrides[instance._id];
|
|
5705
|
+
if (override?.parameters) {
|
|
5706
|
+
const matchingKey = this.findKeyName(override.parameters, parameterId, strict);
|
|
5707
|
+
if (matchingKey !== void 0) {
|
|
5708
|
+
const blockParamValue = override.parameters[matchingKey];
|
|
5709
|
+
const items = blockParamValue.value;
|
|
5710
|
+
if (Array.isArray(items) && items.length === 1) {
|
|
5711
|
+
const blockItem = items[0];
|
|
5712
|
+
for (const [fieldId, fieldValue] of Object.entries(blockItem.fields ?? {})) {
|
|
5713
|
+
override.parameters[fieldId] = fieldValue;
|
|
5714
|
+
}
|
|
5715
|
+
}
|
|
5716
|
+
delete override.parameters[matchingKey];
|
|
5717
|
+
count++;
|
|
5718
|
+
}
|
|
5719
|
+
}
|
|
5720
|
+
}
|
|
5721
|
+
count += this.flattenOverridesForMatchingInstances(instance, overrides, componentId, parameterId, strict);
|
|
5722
|
+
}
|
|
5723
|
+
}
|
|
5724
|
+
}
|
|
5725
|
+
return count;
|
|
5726
|
+
}
|
|
5727
|
+
findKeyName(map, key, strict) {
|
|
5728
|
+
return Object.keys(map).find((k) => this.compareIds(k, key, strict));
|
|
5729
|
+
}
|
|
5730
|
+
findKeyInMap(map, key, strict) {
|
|
5731
|
+
const k = this.findKeyName(map, key, strict);
|
|
5732
|
+
return k !== void 0 ? map[k] : void 0;
|
|
5733
|
+
}
|
|
5734
|
+
};
|
|
5735
|
+
|
|
5736
|
+
// src/cli/commands/flatten-block-field.ts
|
|
5737
|
+
function createFlattenBlockFieldCommand() {
|
|
5738
|
+
const command = new Command15("flatten-block-field");
|
|
5739
|
+
command.description(
|
|
5740
|
+
"Dissolves a $block parameter by lifting the block content type fields onto the component and extracting block item values into composition instances directly."
|
|
5741
|
+
).option("--componentId <id>", "The ID of the component that owns the block parameter").option("--parameterId <id>", "The ID of the $block parameter to flatten").option("--excludeFields <ids>", "Comma-separated list of block content type field IDs to skip when flattening").hook("preAction", (thisCommand) => {
|
|
5742
|
+
const opts = thisCommand.opts();
|
|
5743
|
+
const requiredOptions = [
|
|
5744
|
+
{ name: "componentId", flag: "--componentId" },
|
|
5745
|
+
{ name: "parameterId", flag: "--parameterId" }
|
|
5746
|
+
];
|
|
5747
|
+
const missing = requiredOptions.filter((opt) => !opts[opt.name]).map((opt) => opt.flag);
|
|
5748
|
+
if (missing.length > 0) {
|
|
5749
|
+
console.error(`error: missing required options: ${missing.join(", ")}`);
|
|
5750
|
+
process.exit(1);
|
|
5751
|
+
}
|
|
5752
|
+
}).action(async (opts, cmd) => {
|
|
5753
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
5754
|
+
const options = {
|
|
5755
|
+
...globalOpts,
|
|
5756
|
+
componentId: opts.componentId,
|
|
5757
|
+
parameterId: opts.parameterId,
|
|
5758
|
+
excludeFields: opts.excludeFields
|
|
5759
|
+
};
|
|
5760
|
+
const logger = new Logger();
|
|
5761
|
+
const fileSystem = new FileSystemService();
|
|
5762
|
+
const componentService = new ComponentService(fileSystem);
|
|
5763
|
+
const flattener = new BlockFieldFlattenerService(fileSystem, componentService, logger);
|
|
5764
|
+
try {
|
|
5765
|
+
const result = await flattener.flatten({
|
|
5766
|
+
rootDir: options.rootDir,
|
|
5767
|
+
componentsDir: options.componentsDir,
|
|
5768
|
+
compositionsDir: options.compositionsDir,
|
|
5769
|
+
compositionPatternsDir: options.compositionPatternsDir,
|
|
5770
|
+
componentPatternsDir: options.componentPatternsDir,
|
|
5771
|
+
contentTypesDir: options.contentTypesDir,
|
|
5772
|
+
componentId: options.componentId,
|
|
5773
|
+
parameterId: options.parameterId,
|
|
5774
|
+
whatIf: options.whatIf ?? false,
|
|
5775
|
+
strict: options.strict ?? false,
|
|
5776
|
+
excludeFields: options.excludeFields ? options.excludeFields.split(",").map((s) => s.trim()) : []
|
|
5777
|
+
});
|
|
5778
|
+
logger.success(
|
|
5779
|
+
`Flattened parameter "${options.parameterId}" on component "${options.componentId}": ${result.compositionsModified} composition(s), ${result.compositionPatternsModified} composition pattern(s), ${result.componentPatternsModified} component pattern(s) updated`
|
|
5780
|
+
);
|
|
5781
|
+
} catch (error) {
|
|
5782
|
+
if (error instanceof TransformError) {
|
|
5783
|
+
logger.error(error.message);
|
|
5784
|
+
process.exit(1);
|
|
5785
|
+
}
|
|
5786
|
+
throw error;
|
|
5787
|
+
}
|
|
5788
|
+
});
|
|
5789
|
+
return command;
|
|
5790
|
+
}
|
|
5791
|
+
|
|
5337
5792
|
// package.json
|
|
5338
5793
|
var package_default = {
|
|
5339
5794
|
name: "@uniformdev/transformer",
|
|
5340
|
-
version: "1.1.
|
|
5795
|
+
version: "1.1.32",
|
|
5341
5796
|
description: "CLI tool for transforming Uniform.dev serialization files offline",
|
|
5342
5797
|
type: "module",
|
|
5343
5798
|
bin: {
|
|
@@ -5406,7 +5861,7 @@ var package_default = {
|
|
|
5406
5861
|
};
|
|
5407
5862
|
|
|
5408
5863
|
// src/cli/index.ts
|
|
5409
|
-
var program = new
|
|
5864
|
+
var program = new Command16();
|
|
5410
5865
|
var appVersion = package_default.version;
|
|
5411
5866
|
console.error(`uniform-transform v${appVersion}`);
|
|
5412
5867
|
program.name("uniform-transform").description("CLI tool for transforming Uniform.dev serialization files offline").version(appVersion);
|
|
@@ -5433,5 +5888,6 @@ program.addCommand(createRemoveParameterCommand());
|
|
|
5433
5888
|
program.addCommand(createRemoveFieldCommand());
|
|
5434
5889
|
program.addCommand(createAddComponentParameterCommand());
|
|
5435
5890
|
program.addCommand(createAddContentTypeFieldCommand());
|
|
5891
|
+
program.addCommand(createFlattenBlockFieldCommand());
|
|
5436
5892
|
program.parse();
|
|
5437
5893
|
//# sourceMappingURL=index.js.map
|