@uniformdev/transformer 1.1.51 → 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/index.d.ts CHANGED
@@ -620,6 +620,7 @@ interface RemoveFieldInternalOptions {
620
620
  compositionsDir: string;
621
621
  compositionPatternsDir: string;
622
622
  componentPatternsDir: string;
623
+ contentTypesDir: string;
623
624
  componentType: string;
624
625
  parameterId: string;
625
626
  whatIf: boolean;
@@ -629,6 +630,7 @@ interface RemoveFieldResult {
629
630
  compositionsModified: number;
630
631
  compositionPatternsModified: number;
631
632
  componentPatternsModified: number;
633
+ contentTypesModified: number;
632
634
  instancesUpdated: number;
633
635
  }
634
636
  declare class FieldRemoverService {
@@ -638,6 +640,7 @@ declare class FieldRemoverService {
638
640
  constructor(fileSystem: FileSystemService, componentService: ComponentService, logger: Logger);
639
641
  private compareIds;
640
642
  remove(options: RemoveFieldInternalOptions): Promise<RemoveFieldResult>;
643
+ private removeFieldFromContentTypes;
641
644
  private removeFieldInDirectory;
642
645
  private removeFieldFromTree;
643
646
  private removeFieldFromOverrides;
package/dist/index.js CHANGED
@@ -3076,6 +3076,7 @@ var FieldRemoverService = class {
3076
3076
  compositionsDir,
3077
3077
  compositionPatternsDir,
3078
3078
  componentPatternsDir,
3079
+ contentTypesDir,
3079
3080
  componentType,
3080
3081
  parameterId,
3081
3082
  whatIf,
@@ -3086,6 +3087,7 @@ var FieldRemoverService = class {
3086
3087
  const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
3087
3088
  const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
3088
3089
  const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
3090
+ const fullContentTypesDir = this.fileSystem.resolvePath(rootDir, contentTypesDir);
3089
3091
  let allIdsToRemove = [parameterId];
3090
3092
  try {
3091
3093
  const { component } = await this.componentService.loadComponent(fullComponentsDir, componentType, findOptions);
@@ -3100,6 +3102,13 @@ var FieldRemoverService = class {
3100
3102
  this.logger.info(`Cascade-removing ${childIds.length} child field(s) [${childIds.join(", ")}] along with "${parameterId}"`);
3101
3103
  }
3102
3104
  this.logger.info(`Removing field "${parameterId}" from instances of ${componentType}`);
3105
+ const contentTypesModified = await this.removeFieldFromContentTypes(
3106
+ fullContentTypesDir,
3107
+ componentType,
3108
+ allIdsToRemove,
3109
+ whatIf,
3110
+ strict
3111
+ );
3103
3112
  const compositionsResult = await this.removeFieldInDirectory(
3104
3113
  fullCompositionsDir,
3105
3114
  componentType,
@@ -3128,15 +3137,70 @@ var FieldRemoverService = class {
3128
3137
  const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
3129
3138
  this.logger.info("");
3130
3139
  this.logger.info(
3131
- `Summary: ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
3140
+ `Summary: ${contentTypesModified} content type(s), ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
3132
3141
  );
3133
3142
  return {
3134
3143
  compositionsModified: compositionsResult.filesModified,
3135
3144
  compositionPatternsModified: compositionPatternsResult.filesModified,
3136
3145
  componentPatternsModified: componentPatternsResult.filesModified,
3146
+ contentTypesModified,
3137
3147
  instancesUpdated: totalInstances
3138
3148
  };
3139
3149
  }
3150
+ async removeFieldFromContentTypes(contentTypesDir, componentType, fieldIds, whatIf, strict) {
3151
+ let files;
3152
+ try {
3153
+ files = await this.fileSystem.findFiles(contentTypesDir, "**/*.{json,yaml,yml}");
3154
+ } catch {
3155
+ return 0;
3156
+ }
3157
+ if (files.length === 0) {
3158
+ return 0;
3159
+ }
3160
+ const isWildcard = componentType === "*";
3161
+ let contentTypesModified = 0;
3162
+ for (const filePath of files) {
3163
+ let contentType;
3164
+ try {
3165
+ contentType = await this.fileSystem.readFile(filePath);
3166
+ } catch {
3167
+ continue;
3168
+ }
3169
+ if (!contentType?.id || !contentType.fields) {
3170
+ continue;
3171
+ }
3172
+ if (!isWildcard && !this.compareIds(contentType.id, componentType, strict)) {
3173
+ continue;
3174
+ }
3175
+ const removedFieldIds = [];
3176
+ contentType.fields = contentType.fields.filter((field) => {
3177
+ const shouldRemove = fieldIds.some((id) => this.compareIds(field.id, id, strict));
3178
+ if (shouldRemove) {
3179
+ removedFieldIds.push(field.id);
3180
+ }
3181
+ return !shouldRemove;
3182
+ });
3183
+ if (removedFieldIds.length === 0) {
3184
+ continue;
3185
+ }
3186
+ const entryName = contentType.entryName;
3187
+ if (entryName && removedFieldIds.some((id) => this.compareIds(id, entryName, strict))) {
3188
+ this.logger.info(`Clearing entryName "${entryName}" on content type "${contentType.id}" (field was removed)`);
3189
+ contentType.entryName = "";
3190
+ }
3191
+ const relativePath = this.fileSystem.getBasename(filePath);
3192
+ this.logger.action(
3193
+ whatIf,
3194
+ "UPDATE",
3195
+ `contentType/${relativePath} (removed ${removedFieldIds.length} field(s): ${removedFieldIds.join(", ")})`
3196
+ );
3197
+ if (!whatIf) {
3198
+ await this.fileSystem.writeFile(filePath, contentType);
3199
+ }
3200
+ contentTypesModified++;
3201
+ }
3202
+ return contentTypesModified;
3203
+ }
3140
3204
  async removeFieldInDirectory(directory, componentType, parameterIds, whatIf, strict, label) {
3141
3205
  let files;
3142
3206
  try {