@uniformdev/transformer 1.1.50 → 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 +214 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +6 -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 Command23 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/cli/commands/propagate-root-component-property.ts
|
|
7
7
|
import { Command } from "commander";
|
|
@@ -7491,10 +7491,220 @@ function createPropagateRootSlotCommand() {
|
|
|
7491
7491
|
return command;
|
|
7492
7492
|
}
|
|
7493
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
|
+
|
|
7494
7704
|
// package.json
|
|
7495
7705
|
var package_default = {
|
|
7496
7706
|
name: "@uniformdev/transformer",
|
|
7497
|
-
version: "1.1.
|
|
7707
|
+
version: "1.1.51",
|
|
7498
7708
|
description: "CLI tool for transforming Uniform.dev serialization files offline",
|
|
7499
7709
|
type: "module",
|
|
7500
7710
|
bin: {
|
|
@@ -7563,7 +7773,7 @@ var package_default = {
|
|
|
7563
7773
|
};
|
|
7564
7774
|
|
|
7565
7775
|
// src/cli/index.ts
|
|
7566
|
-
var program = new
|
|
7776
|
+
var program = new Command23();
|
|
7567
7777
|
var appVersion = package_default.version;
|
|
7568
7778
|
console.error(`uniform-transform v${appVersion}`);
|
|
7569
7779
|
program.name("uniform-transform").description("CLI tool for transforming Uniform.dev serialization files offline").version(appVersion);
|
|
@@ -7600,5 +7810,6 @@ program.addCommand(createRemoveUnusedComponentTypesCommand());
|
|
|
7600
7810
|
program.addCommand(createGenerateMissingProjectMapNodesCommand());
|
|
7601
7811
|
program.addCommand(createSplitContentTypeCommand());
|
|
7602
7812
|
program.addCommand(createPropagateRootSlotCommand());
|
|
7813
|
+
program.addCommand(createClearSlotCommand());
|
|
7603
7814
|
program.parse();
|
|
7604
7815
|
//# sourceMappingURL=index.js.map
|