@uniformdev/transformer 1.1.50 → 1.1.52
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 +286 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +65 -1
- 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 Command23 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/cli/commands/propagate-root-component-property.ts
|
|
7
7
|
import { Command } from "commander";
|
|
@@ -5259,6 +5259,7 @@ var FieldRemoverService = class {
|
|
|
5259
5259
|
compositionsDir,
|
|
5260
5260
|
compositionPatternsDir,
|
|
5261
5261
|
componentPatternsDir,
|
|
5262
|
+
contentTypesDir,
|
|
5262
5263
|
componentType,
|
|
5263
5264
|
parameterId,
|
|
5264
5265
|
whatIf,
|
|
@@ -5269,6 +5270,7 @@ var FieldRemoverService = class {
|
|
|
5269
5270
|
const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
|
|
5270
5271
|
const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
|
|
5271
5272
|
const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
|
|
5273
|
+
const fullContentTypesDir = this.fileSystem.resolvePath(rootDir, contentTypesDir);
|
|
5272
5274
|
let allIdsToRemove = [parameterId];
|
|
5273
5275
|
try {
|
|
5274
5276
|
const { component } = await this.componentService.loadComponent(fullComponentsDir, componentType, findOptions);
|
|
@@ -5283,6 +5285,13 @@ var FieldRemoverService = class {
|
|
|
5283
5285
|
this.logger.info(`Cascade-removing ${childIds.length} child field(s) [${childIds.join(", ")}] along with "${parameterId}"`);
|
|
5284
5286
|
}
|
|
5285
5287
|
this.logger.info(`Removing field "${parameterId}" from instances of ${componentType}`);
|
|
5288
|
+
const contentTypesModified = await this.removeFieldFromContentTypes(
|
|
5289
|
+
fullContentTypesDir,
|
|
5290
|
+
componentType,
|
|
5291
|
+
allIdsToRemove,
|
|
5292
|
+
whatIf,
|
|
5293
|
+
strict
|
|
5294
|
+
);
|
|
5286
5295
|
const compositionsResult = await this.removeFieldInDirectory(
|
|
5287
5296
|
fullCompositionsDir,
|
|
5288
5297
|
componentType,
|
|
@@ -5311,15 +5320,70 @@ var FieldRemoverService = class {
|
|
|
5311
5320
|
const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
|
|
5312
5321
|
this.logger.info("");
|
|
5313
5322
|
this.logger.info(
|
|
5314
|
-
`Summary: ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
|
|
5323
|
+
`Summary: ${contentTypesModified} content type(s), ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
|
|
5315
5324
|
);
|
|
5316
5325
|
return {
|
|
5317
5326
|
compositionsModified: compositionsResult.filesModified,
|
|
5318
5327
|
compositionPatternsModified: compositionPatternsResult.filesModified,
|
|
5319
5328
|
componentPatternsModified: componentPatternsResult.filesModified,
|
|
5329
|
+
contentTypesModified,
|
|
5320
5330
|
instancesUpdated: totalInstances
|
|
5321
5331
|
};
|
|
5322
5332
|
}
|
|
5333
|
+
async removeFieldFromContentTypes(contentTypesDir, componentType, fieldIds, whatIf, strict) {
|
|
5334
|
+
let files;
|
|
5335
|
+
try {
|
|
5336
|
+
files = await this.fileSystem.findFiles(contentTypesDir, "**/*.{json,yaml,yml}");
|
|
5337
|
+
} catch {
|
|
5338
|
+
return 0;
|
|
5339
|
+
}
|
|
5340
|
+
if (files.length === 0) {
|
|
5341
|
+
return 0;
|
|
5342
|
+
}
|
|
5343
|
+
const isWildcard = componentType === "*";
|
|
5344
|
+
let contentTypesModified = 0;
|
|
5345
|
+
for (const filePath of files) {
|
|
5346
|
+
let contentType;
|
|
5347
|
+
try {
|
|
5348
|
+
contentType = await this.fileSystem.readFile(filePath);
|
|
5349
|
+
} catch {
|
|
5350
|
+
continue;
|
|
5351
|
+
}
|
|
5352
|
+
if (!contentType?.id || !contentType.fields) {
|
|
5353
|
+
continue;
|
|
5354
|
+
}
|
|
5355
|
+
if (!isWildcard && !this.compareIds(contentType.id, componentType, strict)) {
|
|
5356
|
+
continue;
|
|
5357
|
+
}
|
|
5358
|
+
const removedFieldIds = [];
|
|
5359
|
+
contentType.fields = contentType.fields.filter((field) => {
|
|
5360
|
+
const shouldRemove = fieldIds.some((id) => this.compareIds(field.id, id, strict));
|
|
5361
|
+
if (shouldRemove) {
|
|
5362
|
+
removedFieldIds.push(field.id);
|
|
5363
|
+
}
|
|
5364
|
+
return !shouldRemove;
|
|
5365
|
+
});
|
|
5366
|
+
if (removedFieldIds.length === 0) {
|
|
5367
|
+
continue;
|
|
5368
|
+
}
|
|
5369
|
+
const entryName = contentType.entryName;
|
|
5370
|
+
if (entryName && removedFieldIds.some((id) => this.compareIds(id, entryName, strict))) {
|
|
5371
|
+
this.logger.info(`Clearing entryName "${entryName}" on content type "${contentType.id}" (field was removed)`);
|
|
5372
|
+
contentType.entryName = "";
|
|
5373
|
+
}
|
|
5374
|
+
const relativePath = this.fileSystem.getBasename(filePath);
|
|
5375
|
+
this.logger.action(
|
|
5376
|
+
whatIf,
|
|
5377
|
+
"UPDATE",
|
|
5378
|
+
`contentType/${relativePath} (removed ${removedFieldIds.length} field(s): ${removedFieldIds.join(", ")})`
|
|
5379
|
+
);
|
|
5380
|
+
if (!whatIf) {
|
|
5381
|
+
await this.fileSystem.writeFile(filePath, contentType);
|
|
5382
|
+
}
|
|
5383
|
+
contentTypesModified++;
|
|
5384
|
+
}
|
|
5385
|
+
return contentTypesModified;
|
|
5386
|
+
}
|
|
5323
5387
|
async removeFieldInDirectory(directory, componentType, parameterIds, whatIf, strict, label) {
|
|
5324
5388
|
let files;
|
|
5325
5389
|
try {
|
|
@@ -5477,6 +5541,8 @@ function createRemoveFieldCommand() {
|
|
|
5477
5541
|
parameterId: opts.parameterId
|
|
5478
5542
|
};
|
|
5479
5543
|
const logger = new Logger();
|
|
5544
|
+
logger.info(`componentType: ${options.componentType}`);
|
|
5545
|
+
logger.info(`parameterId: ${options.parameterId}`);
|
|
5480
5546
|
const fileSystem = new FileSystemService();
|
|
5481
5547
|
const componentService = new ComponentService(fileSystem);
|
|
5482
5548
|
const remover = new FieldRemoverService(fileSystem, componentService, logger);
|
|
@@ -5485,7 +5551,8 @@ function createRemoveFieldCommand() {
|
|
|
5485
5551
|
const aggregate = {
|
|
5486
5552
|
compositionsModified: 0,
|
|
5487
5553
|
compositionPatternsModified: 0,
|
|
5488
|
-
componentPatternsModified: 0
|
|
5554
|
+
componentPatternsModified: 0,
|
|
5555
|
+
contentTypesModified: 0
|
|
5489
5556
|
};
|
|
5490
5557
|
try {
|
|
5491
5558
|
for (const componentType of componentTypes) {
|
|
@@ -5495,6 +5562,7 @@ function createRemoveFieldCommand() {
|
|
|
5495
5562
|
compositionsDir: options.compositionsDir,
|
|
5496
5563
|
compositionPatternsDir: options.compositionPatternsDir,
|
|
5497
5564
|
componentPatternsDir: options.componentPatternsDir,
|
|
5565
|
+
contentTypesDir: options.contentTypesDir,
|
|
5498
5566
|
componentType,
|
|
5499
5567
|
parameterId: options.parameterId,
|
|
5500
5568
|
whatIf: options.whatIf ?? false,
|
|
@@ -5503,9 +5571,10 @@ function createRemoveFieldCommand() {
|
|
|
5503
5571
|
aggregate.compositionsModified += result.compositionsModified;
|
|
5504
5572
|
aggregate.compositionPatternsModified += result.compositionPatternsModified;
|
|
5505
5573
|
aggregate.componentPatternsModified += result.componentPatternsModified;
|
|
5574
|
+
aggregate.contentTypesModified += result.contentTypesModified;
|
|
5506
5575
|
}
|
|
5507
5576
|
logger.success(
|
|
5508
|
-
`Removed field: ${aggregate.compositionsModified} composition(s), ${aggregate.compositionPatternsModified} composition pattern(s), ${aggregate.componentPatternsModified} component pattern(s) updated`
|
|
5577
|
+
`Removed field: ${aggregate.contentTypesModified} content type(s), ${aggregate.compositionsModified} composition(s), ${aggregate.compositionPatternsModified} composition pattern(s), ${aggregate.componentPatternsModified} component pattern(s) updated`
|
|
5509
5578
|
);
|
|
5510
5579
|
} catch (error) {
|
|
5511
5580
|
if (error instanceof TransformError) {
|
|
@@ -7491,10 +7560,220 @@ function createPropagateRootSlotCommand() {
|
|
|
7491
7560
|
return command;
|
|
7492
7561
|
}
|
|
7493
7562
|
|
|
7563
|
+
// src/cli/commands/clear-slot.ts
|
|
7564
|
+
import { Command as Command22 } from "commander";
|
|
7565
|
+
|
|
7566
|
+
// src/core/services/slot-clearer.service.ts
|
|
7567
|
+
var SlotClearerService = class {
|
|
7568
|
+
constructor(fileSystem, logger) {
|
|
7569
|
+
this.fileSystem = fileSystem;
|
|
7570
|
+
this.logger = logger;
|
|
7571
|
+
}
|
|
7572
|
+
compareIds(id1, id2, strict) {
|
|
7573
|
+
if (strict) {
|
|
7574
|
+
return id1 === id2;
|
|
7575
|
+
}
|
|
7576
|
+
return id1.toLowerCase() === id2.toLowerCase();
|
|
7577
|
+
}
|
|
7578
|
+
matchesParentType(type, parentTypes, strict) {
|
|
7579
|
+
if (!parentTypes) return true;
|
|
7580
|
+
return parentTypes.some((pt) => this.compareIds(type, pt, strict));
|
|
7581
|
+
}
|
|
7582
|
+
matchesCompositionId(id, compositionIds, strict) {
|
|
7583
|
+
if (!compositionIds) return true;
|
|
7584
|
+
return compositionIds.some((cid) => this.compareIds(id, cid, strict));
|
|
7585
|
+
}
|
|
7586
|
+
async clearSlot(options) {
|
|
7587
|
+
const {
|
|
7588
|
+
rootDir,
|
|
7589
|
+
compositionsDir,
|
|
7590
|
+
compositionPatternsDir,
|
|
7591
|
+
componentPatternsDir,
|
|
7592
|
+
slot,
|
|
7593
|
+
parentComponentTypes,
|
|
7594
|
+
compositionIds,
|
|
7595
|
+
whatIf,
|
|
7596
|
+
strict
|
|
7597
|
+
} = options;
|
|
7598
|
+
const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
|
|
7599
|
+
const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
|
|
7600
|
+
const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
|
|
7601
|
+
this.logger.info(
|
|
7602
|
+
`Clearing slot "${slot}"` + (parentComponentTypes ? ` on component type(s): ${parentComponentTypes.join(", ")}` : "") + (compositionIds ? ` in composition(s): ${compositionIds.join(", ")}` : "")
|
|
7603
|
+
);
|
|
7604
|
+
const compositionsResult = await this.clearSlotInDirectory(
|
|
7605
|
+
fullCompositionsDir,
|
|
7606
|
+
slot,
|
|
7607
|
+
parentComponentTypes,
|
|
7608
|
+
compositionIds,
|
|
7609
|
+
whatIf,
|
|
7610
|
+
strict,
|
|
7611
|
+
"composition"
|
|
7612
|
+
);
|
|
7613
|
+
const compositionPatternsResult = await this.clearSlotInDirectory(
|
|
7614
|
+
fullCompositionPatternsDir,
|
|
7615
|
+
slot,
|
|
7616
|
+
parentComponentTypes,
|
|
7617
|
+
null,
|
|
7618
|
+
whatIf,
|
|
7619
|
+
strict,
|
|
7620
|
+
"compositionPattern"
|
|
7621
|
+
);
|
|
7622
|
+
const componentPatternsResult = await this.clearSlotInDirectory(
|
|
7623
|
+
fullComponentPatternsDir,
|
|
7624
|
+
slot,
|
|
7625
|
+
parentComponentTypes,
|
|
7626
|
+
null,
|
|
7627
|
+
whatIf,
|
|
7628
|
+
strict,
|
|
7629
|
+
"componentPattern"
|
|
7630
|
+
);
|
|
7631
|
+
const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
|
|
7632
|
+
const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
|
|
7633
|
+
this.logger.info("");
|
|
7634
|
+
this.logger.info(`Summary: ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`);
|
|
7635
|
+
return {
|
|
7636
|
+
compositionsModified: compositionsResult.filesModified,
|
|
7637
|
+
compositionPatternsModified: compositionPatternsResult.filesModified,
|
|
7638
|
+
componentPatternsModified: componentPatternsResult.filesModified,
|
|
7639
|
+
instancesUpdated: totalInstances
|
|
7640
|
+
};
|
|
7641
|
+
}
|
|
7642
|
+
async clearSlotInDirectory(directory, slot, parentComponentTypes, compositionIds, whatIf, strict, label) {
|
|
7643
|
+
let files;
|
|
7644
|
+
try {
|
|
7645
|
+
files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
|
|
7646
|
+
} catch {
|
|
7647
|
+
return { filesModified: 0, instancesUpdated: 0 };
|
|
7648
|
+
}
|
|
7649
|
+
if (files.length === 0) {
|
|
7650
|
+
return { filesModified: 0, instancesUpdated: 0 };
|
|
7651
|
+
}
|
|
7652
|
+
let filesModified = 0;
|
|
7653
|
+
let instancesUpdated = 0;
|
|
7654
|
+
for (const filePath of files) {
|
|
7655
|
+
let composition;
|
|
7656
|
+
try {
|
|
7657
|
+
composition = await this.fileSystem.readFile(filePath);
|
|
7658
|
+
} catch {
|
|
7659
|
+
continue;
|
|
7660
|
+
}
|
|
7661
|
+
if (!composition?.composition) {
|
|
7662
|
+
continue;
|
|
7663
|
+
}
|
|
7664
|
+
if (compositionIds && !this.matchesCompositionId(composition.composition._id, compositionIds, strict)) {
|
|
7665
|
+
continue;
|
|
7666
|
+
}
|
|
7667
|
+
const count = this.clearSlotInTree(
|
|
7668
|
+
composition.composition,
|
|
7669
|
+
slot,
|
|
7670
|
+
parentComponentTypes,
|
|
7671
|
+
strict
|
|
7672
|
+
);
|
|
7673
|
+
if (count > 0) {
|
|
7674
|
+
const relativePath = filePath.replace(directory, "").replace(/^[/\\]/, "");
|
|
7675
|
+
this.logger.action(
|
|
7676
|
+
whatIf,
|
|
7677
|
+
"CLEAR",
|
|
7678
|
+
`slot "${slot}" in ${label}/${relativePath} (${count} instance(s))`
|
|
7679
|
+
);
|
|
7680
|
+
if (!whatIf) {
|
|
7681
|
+
await this.fileSystem.writeFile(filePath, composition);
|
|
7682
|
+
}
|
|
7683
|
+
filesModified++;
|
|
7684
|
+
instancesUpdated += count;
|
|
7685
|
+
}
|
|
7686
|
+
}
|
|
7687
|
+
return { filesModified, instancesUpdated };
|
|
7688
|
+
}
|
|
7689
|
+
clearSlotInTree(node, slot, parentComponentTypes, strict) {
|
|
7690
|
+
let count = 0;
|
|
7691
|
+
if (this.matchesParentType(node.type, parentComponentTypes, strict) && node.slots) {
|
|
7692
|
+
const matchingSlotKey = Object.keys(node.slots).find(
|
|
7693
|
+
(k) => this.compareIds(k, slot, strict)
|
|
7694
|
+
);
|
|
7695
|
+
if (matchingSlotKey) {
|
|
7696
|
+
const slotContent = node.slots[matchingSlotKey];
|
|
7697
|
+
if (Array.isArray(slotContent) && slotContent.length > 0) {
|
|
7698
|
+
node.slots[matchingSlotKey] = [];
|
|
7699
|
+
count++;
|
|
7700
|
+
}
|
|
7701
|
+
}
|
|
7702
|
+
}
|
|
7703
|
+
if (node.slots) {
|
|
7704
|
+
for (const slotInstances of Object.values(node.slots)) {
|
|
7705
|
+
if (!Array.isArray(slotInstances)) continue;
|
|
7706
|
+
for (const instance of slotInstances) {
|
|
7707
|
+
count += this.clearSlotInTree(instance, slot, parentComponentTypes, strict);
|
|
7708
|
+
}
|
|
7709
|
+
}
|
|
7710
|
+
}
|
|
7711
|
+
return count;
|
|
7712
|
+
}
|
|
7713
|
+
};
|
|
7714
|
+
|
|
7715
|
+
// src/cli/commands/clear-slot.ts
|
|
7716
|
+
function createClearSlotCommand() {
|
|
7717
|
+
const command = new Command22("clear-slot");
|
|
7718
|
+
command.description(
|
|
7719
|
+
"Removes all components from a given slot in compositions, composition patterns, and component patterns."
|
|
7720
|
+
).option("--slot <name>", "The slot name to clear").option(
|
|
7721
|
+
"--parentComponentType <types>",
|
|
7722
|
+
"Comma/semicolon/pipe-separated list of parent component types to filter by"
|
|
7723
|
+
).option(
|
|
7724
|
+
"--compositionIds <ids>",
|
|
7725
|
+
"Comma/semicolon/pipe-separated list of composition IDs to restrict processing to"
|
|
7726
|
+
).hook("preAction", (thisCommand) => {
|
|
7727
|
+
const opts = thisCommand.opts();
|
|
7728
|
+
const requiredOptions = [{ name: "slot", flag: "--slot" }];
|
|
7729
|
+
const missing = requiredOptions.filter((opt) => !opts[opt.name]).map((opt) => opt.flag);
|
|
7730
|
+
if (missing.length > 0) {
|
|
7731
|
+
console.error(`error: missing required options: ${missing.join(", ")}`);
|
|
7732
|
+
process.exit(1);
|
|
7733
|
+
}
|
|
7734
|
+
}).action(async (opts, cmd) => {
|
|
7735
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
7736
|
+
const options = {
|
|
7737
|
+
...globalOpts,
|
|
7738
|
+
slot: opts.slot,
|
|
7739
|
+
parentComponentType: opts.parentComponentType,
|
|
7740
|
+
compositionIds: opts.compositionIds
|
|
7741
|
+
};
|
|
7742
|
+
const logger = new Logger();
|
|
7743
|
+
const fileSystem = new FileSystemService();
|
|
7744
|
+
const clearer = new SlotClearerService(fileSystem, logger);
|
|
7745
|
+
const parentComponentTypes = options.parentComponentType ? splitList(options.parentComponentType) : null;
|
|
7746
|
+
const compositionIds = options.compositionIds ? splitList(options.compositionIds) : null;
|
|
7747
|
+
try {
|
|
7748
|
+
const result = await clearer.clearSlot({
|
|
7749
|
+
rootDir: options.rootDir,
|
|
7750
|
+
compositionsDir: options.compositionsDir,
|
|
7751
|
+
compositionPatternsDir: options.compositionPatternsDir,
|
|
7752
|
+
componentPatternsDir: options.componentPatternsDir,
|
|
7753
|
+
slot: options.slot,
|
|
7754
|
+
parentComponentTypes,
|
|
7755
|
+
compositionIds,
|
|
7756
|
+
whatIf: options.whatIf ?? false,
|
|
7757
|
+
strict: options.strict ?? false
|
|
7758
|
+
});
|
|
7759
|
+
logger.success(
|
|
7760
|
+
`Cleared slot: ${result.compositionsModified} composition(s), ${result.compositionPatternsModified} composition pattern(s), ${result.componentPatternsModified} component pattern(s) updated`
|
|
7761
|
+
);
|
|
7762
|
+
} catch (error) {
|
|
7763
|
+
if (error instanceof TransformError) {
|
|
7764
|
+
logger.error(error.message);
|
|
7765
|
+
process.exit(1);
|
|
7766
|
+
}
|
|
7767
|
+
throw error;
|
|
7768
|
+
}
|
|
7769
|
+
});
|
|
7770
|
+
return command;
|
|
7771
|
+
}
|
|
7772
|
+
|
|
7494
7773
|
// package.json
|
|
7495
7774
|
var package_default = {
|
|
7496
7775
|
name: "@uniformdev/transformer",
|
|
7497
|
-
version: "1.1.
|
|
7776
|
+
version: "1.1.52",
|
|
7498
7777
|
description: "CLI tool for transforming Uniform.dev serialization files offline",
|
|
7499
7778
|
type: "module",
|
|
7500
7779
|
bin: {
|
|
@@ -7563,7 +7842,7 @@ var package_default = {
|
|
|
7563
7842
|
};
|
|
7564
7843
|
|
|
7565
7844
|
// src/cli/index.ts
|
|
7566
|
-
var program = new
|
|
7845
|
+
var program = new Command23();
|
|
7567
7846
|
var appVersion = package_default.version;
|
|
7568
7847
|
console.error(`uniform-transform v${appVersion}`);
|
|
7569
7848
|
program.name("uniform-transform").description("CLI tool for transforming Uniform.dev serialization files offline").version(appVersion);
|
|
@@ -7600,5 +7879,6 @@ program.addCommand(createRemoveUnusedComponentTypesCommand());
|
|
|
7600
7879
|
program.addCommand(createGenerateMissingProjectMapNodesCommand());
|
|
7601
7880
|
program.addCommand(createSplitContentTypeCommand());
|
|
7602
7881
|
program.addCommand(createPropagateRootSlotCommand());
|
|
7882
|
+
program.addCommand(createClearSlotCommand());
|
|
7603
7883
|
program.parse();
|
|
7604
7884
|
//# sourceMappingURL=index.js.map
|