@uniformdev/transformer 1.1.49 → 1.1.51

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
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/cli/index.ts
4
- import { Command as Command22 } from "commander";
4
+ import { Command as Command23 } from "commander";
5
5
 
6
6
  // src/cli/commands/propagate-root-component-property.ts
7
7
  import { Command } from "commander";
@@ -4044,6 +4044,7 @@ var ComponentAdderService = class {
4044
4044
  parentComponentType,
4045
4045
  slot,
4046
4046
  componentPatternId,
4047
+ compositionIds,
4047
4048
  whatIf,
4048
4049
  strict
4049
4050
  } = options;
@@ -4137,7 +4138,8 @@ var ComponentAdderService = class {
4137
4138
  newInstance,
4138
4139
  whatIf,
4139
4140
  strict,
4140
- "composition"
4141
+ "composition",
4142
+ compositionIds
4141
4143
  );
4142
4144
  const compositionPatternsResult = await this.addComponentToDirectory(
4143
4145
  fullCompositionPatternsDir,
@@ -4146,7 +4148,8 @@ var ComponentAdderService = class {
4146
4148
  newInstance,
4147
4149
  whatIf,
4148
4150
  strict,
4149
- "compositionPattern"
4151
+ "compositionPattern",
4152
+ compositionIds
4150
4153
  );
4151
4154
  const componentPatternsResult = await this.addComponentToDirectory(
4152
4155
  fullComponentPatternsDir,
@@ -4210,7 +4213,7 @@ var ComponentAdderService = class {
4210
4213
  }
4211
4214
  return raw;
4212
4215
  }
4213
- async addComponentToDirectory(directory, parentTypes, slot, newInstance, whatIf, strict, dirType) {
4216
+ async addComponentToDirectory(directory, parentTypes, slot, newInstance, whatIf, strict, dirType, compositionIds) {
4214
4217
  const exists = await this.fileSystem.fileExists(directory);
4215
4218
  if (!exists) {
4216
4219
  this.logger.detail(`${dirType} directory does not exist, skipping`);
@@ -4242,6 +4245,12 @@ var ComponentAdderService = class {
4242
4245
  continue;
4243
4246
  }
4244
4247
  const rootInstance = composition.composition;
4248
+ if (compositionIds && compositionIds.length > 0) {
4249
+ const compositionId = rootInstance._id;
4250
+ if (!compositionId || !compositionIds.some((id) => this.compareIds(compositionId, id, strict))) {
4251
+ continue;
4252
+ }
4253
+ }
4245
4254
  const rootPath = `${rootInstance._id ?? ""}${rootInstance.type}`;
4246
4255
  let modified = false;
4247
4256
  if (this.matchesAnyParentType(rootInstance.type, parentTypes, strict)) {
@@ -4400,7 +4409,7 @@ function createAddComponentCommand() {
4400
4409
  import { Command as Command8 } from "commander";
4401
4410
  function createAddComponentPatternCommand() {
4402
4411
  const command = new Command8("add-component-pattern");
4403
- command.description("Adds a component pattern instance to existing component slots across all compositions.").option("--parentComponentType <type>", "The component type that owns the slot").option("--slot <slotId>", "The slot ID where the component pattern will be added").option("--componentPatternId <id>", "The component pattern ID to add").hook("preAction", (thisCommand) => {
4412
+ command.description("Adds a component pattern instance to existing component slots across all compositions.").option("--parentComponentType <type>", "The component type that owns the slot").option("--slot <slotId>", "The slot ID where the component pattern will be added").option("--componentPatternId <id>", "The component pattern ID to add").option("--compositionIds <ids>", "Comma, semicolon, or pipe-separated list of composition IDs to limit the operation to").hook("preAction", (thisCommand) => {
4404
4413
  const opts = thisCommand.opts();
4405
4414
  const requiredOptions = [
4406
4415
  { name: "parentComponentType", flag: "--parentComponentType" },
@@ -4418,12 +4427,20 @@ function createAddComponentPatternCommand() {
4418
4427
  ...globalOpts,
4419
4428
  parentComponentType: opts.parentComponentType,
4420
4429
  slot: opts.slot,
4421
- componentPatternId: opts.componentPatternId
4430
+ componentPatternId: opts.componentPatternId,
4431
+ compositionIds: opts.compositionIds
4422
4432
  };
4423
4433
  const logger = new Logger();
4434
+ logger.info(`parentComponentType: ${options.parentComponentType}`);
4435
+ logger.info(`slot: ${options.slot}`);
4436
+ logger.info(`componentPatternId: ${options.componentPatternId}`);
4437
+ if (options.compositionIds) {
4438
+ logger.info(`compositionIds: ${options.compositionIds}`);
4439
+ }
4424
4440
  const fileSystem = new FileSystemService();
4425
4441
  const componentService = new ComponentService(fileSystem);
4426
4442
  const adder = new ComponentAdderService(fileSystem, componentService, logger);
4443
+ const parsedCompositionIds = options.compositionIds ? splitList(options.compositionIds) : void 0;
4427
4444
  try {
4428
4445
  const result = await adder.addComponentPattern({
4429
4446
  rootDir: options.rootDir,
@@ -4434,6 +4451,7 @@ function createAddComponentPatternCommand() {
4434
4451
  parentComponentType: options.parentComponentType,
4435
4452
  slot: options.slot,
4436
4453
  componentPatternId: options.componentPatternId,
4454
+ compositionIds: parsedCompositionIds,
4437
4455
  whatIf: options.whatIf ?? false,
4438
4456
  strict: options.strict ?? false
4439
4457
  });
@@ -7473,10 +7491,220 @@ function createPropagateRootSlotCommand() {
7473
7491
  return command;
7474
7492
  }
7475
7493
 
7494
+ // src/cli/commands/clear-slot.ts
7495
+ import { Command as Command22 } from "commander";
7496
+
7497
+ // src/core/services/slot-clearer.service.ts
7498
+ var SlotClearerService = class {
7499
+ constructor(fileSystem, logger) {
7500
+ this.fileSystem = fileSystem;
7501
+ this.logger = logger;
7502
+ }
7503
+ compareIds(id1, id2, strict) {
7504
+ if (strict) {
7505
+ return id1 === id2;
7506
+ }
7507
+ return id1.toLowerCase() === id2.toLowerCase();
7508
+ }
7509
+ matchesParentType(type, parentTypes, strict) {
7510
+ if (!parentTypes) return true;
7511
+ return parentTypes.some((pt) => this.compareIds(type, pt, strict));
7512
+ }
7513
+ matchesCompositionId(id, compositionIds, strict) {
7514
+ if (!compositionIds) return true;
7515
+ return compositionIds.some((cid) => this.compareIds(id, cid, strict));
7516
+ }
7517
+ async clearSlot(options) {
7518
+ const {
7519
+ rootDir,
7520
+ compositionsDir,
7521
+ compositionPatternsDir,
7522
+ componentPatternsDir,
7523
+ slot,
7524
+ parentComponentTypes,
7525
+ compositionIds,
7526
+ whatIf,
7527
+ strict
7528
+ } = options;
7529
+ const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
7530
+ const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
7531
+ const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
7532
+ this.logger.info(
7533
+ `Clearing slot "${slot}"` + (parentComponentTypes ? ` on component type(s): ${parentComponentTypes.join(", ")}` : "") + (compositionIds ? ` in composition(s): ${compositionIds.join(", ")}` : "")
7534
+ );
7535
+ const compositionsResult = await this.clearSlotInDirectory(
7536
+ fullCompositionsDir,
7537
+ slot,
7538
+ parentComponentTypes,
7539
+ compositionIds,
7540
+ whatIf,
7541
+ strict,
7542
+ "composition"
7543
+ );
7544
+ const compositionPatternsResult = await this.clearSlotInDirectory(
7545
+ fullCompositionPatternsDir,
7546
+ slot,
7547
+ parentComponentTypes,
7548
+ null,
7549
+ whatIf,
7550
+ strict,
7551
+ "compositionPattern"
7552
+ );
7553
+ const componentPatternsResult = await this.clearSlotInDirectory(
7554
+ fullComponentPatternsDir,
7555
+ slot,
7556
+ parentComponentTypes,
7557
+ null,
7558
+ whatIf,
7559
+ strict,
7560
+ "componentPattern"
7561
+ );
7562
+ const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
7563
+ const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
7564
+ this.logger.info("");
7565
+ this.logger.info(`Summary: ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`);
7566
+ return {
7567
+ compositionsModified: compositionsResult.filesModified,
7568
+ compositionPatternsModified: compositionPatternsResult.filesModified,
7569
+ componentPatternsModified: componentPatternsResult.filesModified,
7570
+ instancesUpdated: totalInstances
7571
+ };
7572
+ }
7573
+ async clearSlotInDirectory(directory, slot, parentComponentTypes, compositionIds, whatIf, strict, label) {
7574
+ let files;
7575
+ try {
7576
+ files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
7577
+ } catch {
7578
+ return { filesModified: 0, instancesUpdated: 0 };
7579
+ }
7580
+ if (files.length === 0) {
7581
+ return { filesModified: 0, instancesUpdated: 0 };
7582
+ }
7583
+ let filesModified = 0;
7584
+ let instancesUpdated = 0;
7585
+ for (const filePath of files) {
7586
+ let composition;
7587
+ try {
7588
+ composition = await this.fileSystem.readFile(filePath);
7589
+ } catch {
7590
+ continue;
7591
+ }
7592
+ if (!composition?.composition) {
7593
+ continue;
7594
+ }
7595
+ if (compositionIds && !this.matchesCompositionId(composition.composition._id, compositionIds, strict)) {
7596
+ continue;
7597
+ }
7598
+ const count = this.clearSlotInTree(
7599
+ composition.composition,
7600
+ slot,
7601
+ parentComponentTypes,
7602
+ strict
7603
+ );
7604
+ if (count > 0) {
7605
+ const relativePath = filePath.replace(directory, "").replace(/^[/\\]/, "");
7606
+ this.logger.action(
7607
+ whatIf,
7608
+ "CLEAR",
7609
+ `slot "${slot}" in ${label}/${relativePath} (${count} instance(s))`
7610
+ );
7611
+ if (!whatIf) {
7612
+ await this.fileSystem.writeFile(filePath, composition);
7613
+ }
7614
+ filesModified++;
7615
+ instancesUpdated += count;
7616
+ }
7617
+ }
7618
+ return { filesModified, instancesUpdated };
7619
+ }
7620
+ clearSlotInTree(node, slot, parentComponentTypes, strict) {
7621
+ let count = 0;
7622
+ if (this.matchesParentType(node.type, parentComponentTypes, strict) && node.slots) {
7623
+ const matchingSlotKey = Object.keys(node.slots).find(
7624
+ (k) => this.compareIds(k, slot, strict)
7625
+ );
7626
+ if (matchingSlotKey) {
7627
+ const slotContent = node.slots[matchingSlotKey];
7628
+ if (Array.isArray(slotContent) && slotContent.length > 0) {
7629
+ node.slots[matchingSlotKey] = [];
7630
+ count++;
7631
+ }
7632
+ }
7633
+ }
7634
+ if (node.slots) {
7635
+ for (const slotInstances of Object.values(node.slots)) {
7636
+ if (!Array.isArray(slotInstances)) continue;
7637
+ for (const instance of slotInstances) {
7638
+ count += this.clearSlotInTree(instance, slot, parentComponentTypes, strict);
7639
+ }
7640
+ }
7641
+ }
7642
+ return count;
7643
+ }
7644
+ };
7645
+
7646
+ // src/cli/commands/clear-slot.ts
7647
+ function createClearSlotCommand() {
7648
+ const command = new Command22("clear-slot");
7649
+ command.description(
7650
+ "Removes all components from a given slot in compositions, composition patterns, and component patterns."
7651
+ ).option("--slot <name>", "The slot name to clear").option(
7652
+ "--parentComponentType <types>",
7653
+ "Comma/semicolon/pipe-separated list of parent component types to filter by"
7654
+ ).option(
7655
+ "--compositionIds <ids>",
7656
+ "Comma/semicolon/pipe-separated list of composition IDs to restrict processing to"
7657
+ ).hook("preAction", (thisCommand) => {
7658
+ const opts = thisCommand.opts();
7659
+ const requiredOptions = [{ name: "slot", flag: "--slot" }];
7660
+ const missing = requiredOptions.filter((opt) => !opts[opt.name]).map((opt) => opt.flag);
7661
+ if (missing.length > 0) {
7662
+ console.error(`error: missing required options: ${missing.join(", ")}`);
7663
+ process.exit(1);
7664
+ }
7665
+ }).action(async (opts, cmd) => {
7666
+ const globalOpts = cmd.optsWithGlobals();
7667
+ const options = {
7668
+ ...globalOpts,
7669
+ slot: opts.slot,
7670
+ parentComponentType: opts.parentComponentType,
7671
+ compositionIds: opts.compositionIds
7672
+ };
7673
+ const logger = new Logger();
7674
+ const fileSystem = new FileSystemService();
7675
+ const clearer = new SlotClearerService(fileSystem, logger);
7676
+ const parentComponentTypes = options.parentComponentType ? splitList(options.parentComponentType) : null;
7677
+ const compositionIds = options.compositionIds ? splitList(options.compositionIds) : null;
7678
+ try {
7679
+ const result = await clearer.clearSlot({
7680
+ rootDir: options.rootDir,
7681
+ compositionsDir: options.compositionsDir,
7682
+ compositionPatternsDir: options.compositionPatternsDir,
7683
+ componentPatternsDir: options.componentPatternsDir,
7684
+ slot: options.slot,
7685
+ parentComponentTypes,
7686
+ compositionIds,
7687
+ whatIf: options.whatIf ?? false,
7688
+ strict: options.strict ?? false
7689
+ });
7690
+ logger.success(
7691
+ `Cleared slot: ${result.compositionsModified} composition(s), ${result.compositionPatternsModified} composition pattern(s), ${result.componentPatternsModified} component pattern(s) updated`
7692
+ );
7693
+ } catch (error) {
7694
+ if (error instanceof TransformError) {
7695
+ logger.error(error.message);
7696
+ process.exit(1);
7697
+ }
7698
+ throw error;
7699
+ }
7700
+ });
7701
+ return command;
7702
+ }
7703
+
7476
7704
  // package.json
7477
7705
  var package_default = {
7478
7706
  name: "@uniformdev/transformer",
7479
- version: "1.1.49",
7707
+ version: "1.1.51",
7480
7708
  description: "CLI tool for transforming Uniform.dev serialization files offline",
7481
7709
  type: "module",
7482
7710
  bin: {
@@ -7545,7 +7773,7 @@ var package_default = {
7545
7773
  };
7546
7774
 
7547
7775
  // src/cli/index.ts
7548
- var program = new Command22();
7776
+ var program = new Command23();
7549
7777
  var appVersion = package_default.version;
7550
7778
  console.error(`uniform-transform v${appVersion}`);
7551
7779
  program.name("uniform-transform").description("CLI tool for transforming Uniform.dev serialization files offline").version(appVersion);
@@ -7582,5 +7810,6 @@ program.addCommand(createRemoveUnusedComponentTypesCommand());
7582
7810
  program.addCommand(createGenerateMissingProjectMapNodesCommand());
7583
7811
  program.addCommand(createSplitContentTypeCommand());
7584
7812
  program.addCommand(createPropagateRootSlotCommand());
7813
+ program.addCommand(createClearSlotCommand());
7585
7814
  program.parse();
7586
7815
  //# sourceMappingURL=index.js.map