@uniformdev/transformer 1.1.38 → 1.1.39

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 Command17 } from "commander";
4
+ import { Command as Command18 } from "commander";
5
5
 
6
6
  // src/cli/commands/propagate-root-component-property.ts
7
7
  import { Command } from "commander";
@@ -6370,10 +6370,134 @@ function createRemoveOrphanEntriesCommand() {
6370
6370
  return command;
6371
6371
  }
6372
6372
 
6373
+ // src/cli/commands/remove-unused-content-types.ts
6374
+ import { Command as Command17 } from "commander";
6375
+
6376
+ // src/core/services/unused-content-type-remover.service.ts
6377
+ var UnusedContentTypeRemoverService = class {
6378
+ constructor(fileSystem, logger) {
6379
+ this.fileSystem = fileSystem;
6380
+ this.logger = logger;
6381
+ }
6382
+ async remove(options) {
6383
+ const { rootDir, contentTypesDir, entriesDir, whatIf, strict } = options;
6384
+ const contentTypesDirFull = this.fileSystem.resolvePath(rootDir, contentTypesDir);
6385
+ const entriesDirFull = this.fileSystem.resolvePath(rootDir, entriesDir);
6386
+ const ctDirExists = await this.fileSystem.fileExists(contentTypesDirFull);
6387
+ if (!ctDirExists) {
6388
+ this.logger.warn(`Content types directory not found: ${contentTypesDir} \u2014 nothing to do`);
6389
+ return { totalContentTypes: 0, removedContentTypes: 0, retainedContentTypes: 0 };
6390
+ }
6391
+ const ctFiles = await this.fileSystem.findFiles(contentTypesDirFull, "**/*.{json,yaml,yml}");
6392
+ if (ctFiles.length === 0) {
6393
+ this.logger.warn("No content type files found \u2014 nothing to do");
6394
+ return { totalContentTypes: 0, removedContentTypes: 0, retainedContentTypes: 0 };
6395
+ }
6396
+ this.logger.info(`Loaded ${ctFiles.length} content type file(s)`);
6397
+ const contentTypeMap = /* @__PURE__ */ new Map();
6398
+ for (const filePath of ctFiles) {
6399
+ let ct;
6400
+ try {
6401
+ ct = await this.fileSystem.readFile(filePath);
6402
+ } catch {
6403
+ this.logger.warn(`Could not read content type file: ${filePath} \u2014 skipping`);
6404
+ continue;
6405
+ }
6406
+ if (!ct?.id) {
6407
+ this.logger.warn(`Content type file missing id: ${filePath} \u2014 skipping`);
6408
+ continue;
6409
+ }
6410
+ contentTypeMap.set(filePath, { filePath, id: ct.id });
6411
+ }
6412
+ const usedTypeIds = /* @__PURE__ */ new Set();
6413
+ const entriesDirExists = await this.fileSystem.fileExists(entriesDirFull);
6414
+ if (!entriesDirExists) {
6415
+ this.logger.warn(`Entries directory not found: ${entriesDir} \u2014 treating all content types as unused`);
6416
+ } else {
6417
+ const entryFiles = await this.fileSystem.findFiles(entriesDirFull, "**/*.{json,yaml,yml}");
6418
+ this.logger.info(`Loaded ${entryFiles.length} entry file(s)`);
6419
+ for (const filePath of entryFiles) {
6420
+ let entryData;
6421
+ try {
6422
+ entryData = await this.fileSystem.readFile(filePath);
6423
+ } catch {
6424
+ this.logger.warn(`Could not read entry file: ${filePath} \u2014 skipping`);
6425
+ continue;
6426
+ }
6427
+ if (!entryData?.entry?.type) {
6428
+ continue;
6429
+ }
6430
+ usedTypeIds.add(entryData.entry.type);
6431
+ }
6432
+ }
6433
+ let removedContentTypes = 0;
6434
+ let retainedContentTypes = 0;
6435
+ for (const { filePath, id } of contentTypeMap.values()) {
6436
+ const isUsed = this.isUsed(id, usedTypeIds, strict);
6437
+ if (isUsed) {
6438
+ retainedContentTypes++;
6439
+ } else {
6440
+ const relPath = this.fileSystem.joinPath(
6441
+ contentTypesDir,
6442
+ this.fileSystem.getBasename(filePath)
6443
+ );
6444
+ this.logger.action(whatIf, "DELETE", relPath);
6445
+ if (!whatIf) {
6446
+ this.fileSystem.deleteFile(filePath);
6447
+ }
6448
+ removedContentTypes++;
6449
+ }
6450
+ }
6451
+ return {
6452
+ totalContentTypes: contentTypeMap.size,
6453
+ removedContentTypes,
6454
+ retainedContentTypes
6455
+ };
6456
+ }
6457
+ isUsed(contentTypeId, usedTypeIds, strict) {
6458
+ if (strict) {
6459
+ return usedTypeIds.has(contentTypeId);
6460
+ }
6461
+ const lower = contentTypeId.toLowerCase();
6462
+ for (const used of usedTypeIds) {
6463
+ if (used.toLowerCase() === lower) return true;
6464
+ }
6465
+ return false;
6466
+ }
6467
+ };
6468
+
6469
+ // src/cli/commands/remove-unused-content-types.ts
6470
+ function createRemoveUnusedContentTypesCommand() {
6471
+ const command = new Command17("remove-unused-content-types");
6472
+ command.description("Removes content type definition files that have zero entries referencing them.").action(async (_opts, cmd) => {
6473
+ const globalOpts = cmd.optsWithGlobals();
6474
+ const options = {
6475
+ ...globalOpts
6476
+ };
6477
+ const logger = new Logger();
6478
+ logger.info(`rootDir: ${options.rootDir}`);
6479
+ logger.info(`contentTypesDir: ${options.contentTypesDir}`);
6480
+ logger.info(`entriesDir: ${options.entriesDir}`);
6481
+ const fileSystem = new FileSystemService();
6482
+ const service = new UnusedContentTypeRemoverService(fileSystem, logger);
6483
+ const result = await service.remove({
6484
+ rootDir: options.rootDir,
6485
+ contentTypesDir: options.contentTypesDir,
6486
+ entriesDir: options.entriesDir,
6487
+ whatIf: options.whatIf ?? false,
6488
+ strict: options.strict ?? false
6489
+ });
6490
+ logger.success(
6491
+ `Removed ${result.removedContentTypes} unused content type(s). ${result.retainedContentTypes} content type(s) retained.`
6492
+ );
6493
+ });
6494
+ return command;
6495
+ }
6496
+
6373
6497
  // package.json
6374
6498
  var package_default = {
6375
6499
  name: "@uniformdev/transformer",
6376
- version: "1.1.38",
6500
+ version: "1.1.39",
6377
6501
  description: "CLI tool for transforming Uniform.dev serialization files offline",
6378
6502
  type: "module",
6379
6503
  bin: {
@@ -6442,7 +6566,7 @@ var package_default = {
6442
6566
  };
6443
6567
 
6444
6568
  // src/cli/index.ts
6445
- var program = new Command17();
6569
+ var program = new Command18();
6446
6570
  var appVersion = package_default.version;
6447
6571
  console.error(`uniform-transform v${appVersion}`);
6448
6572
  program.name("uniform-transform").description("CLI tool for transforming Uniform.dev serialization files offline").version(appVersion);
@@ -6471,5 +6595,6 @@ program.addCommand(createAddComponentParameterCommand());
6471
6595
  program.addCommand(createAddContentTypeFieldCommand());
6472
6596
  program.addCommand(createFlattenBlockFieldCommand());
6473
6597
  program.addCommand(createRemoveOrphanEntriesCommand());
6598
+ program.addCommand(createRemoveUnusedContentTypesCommand());
6474
6599
  program.parse();
6475
6600
  //# sourceMappingURL=index.js.map