@uniformdev/transformer 1.1.12 → 1.1.14
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 +548 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +70 -1
- package/dist/index.js +435 -3
- 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 Command13 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/cli/commands/propagate-root-component-property.ts
|
|
7
7
|
import { Command } from "commander";
|
|
@@ -3699,11 +3699,12 @@ var CompositionConverterService = class {
|
|
|
3699
3699
|
if (flattenComponentIds.length > 0) {
|
|
3700
3700
|
this.transformContentReferences(entry);
|
|
3701
3701
|
}
|
|
3702
|
-
const
|
|
3702
|
+
const entryId = entry.entry._id;
|
|
3703
|
+
const entryFilePath = this.fileSystem.joinPath(entriesDirFull, `${entryId}.json`);
|
|
3703
3704
|
this.logger.action(
|
|
3704
3705
|
whatIf,
|
|
3705
3706
|
"WRITE",
|
|
3706
|
-
`${entriesDir}/${
|
|
3707
|
+
`${entriesDir}/${entryId}.json (${compositionType}, "${this.truncate(compositionName, 50)}")`
|
|
3707
3708
|
);
|
|
3708
3709
|
if (!whatIf) {
|
|
3709
3710
|
await this.fileSystem.writeFile(entryFilePath, entry);
|
|
@@ -3835,9 +3836,10 @@ var CompositionConverterService = class {
|
|
|
3835
3836
|
extraWrapperProps[key] = value;
|
|
3836
3837
|
}
|
|
3837
3838
|
}
|
|
3839
|
+
const entryId = computeGuidHash(`entry${comp._id}`);
|
|
3838
3840
|
return {
|
|
3839
3841
|
entry: {
|
|
3840
|
-
_id:
|
|
3842
|
+
_id: entryId,
|
|
3841
3843
|
_name: comp._name ?? comp._id,
|
|
3842
3844
|
type: comp.type,
|
|
3843
3845
|
fields: { ...comp.parameters ?? {} },
|
|
@@ -4050,10 +4052,548 @@ function createConvertCompositionsToEntriesCommand() {
|
|
|
4050
4052
|
return command;
|
|
4051
4053
|
}
|
|
4052
4054
|
|
|
4055
|
+
// src/cli/commands/remove-parameter.ts
|
|
4056
|
+
import { Command as Command11 } from "commander";
|
|
4057
|
+
|
|
4058
|
+
// src/core/services/parameter-remover.service.ts
|
|
4059
|
+
var ParameterRemoverService = class {
|
|
4060
|
+
constructor(fileSystem, componentService, logger) {
|
|
4061
|
+
this.fileSystem = fileSystem;
|
|
4062
|
+
this.componentService = componentService;
|
|
4063
|
+
this.logger = logger;
|
|
4064
|
+
}
|
|
4065
|
+
compareIds(id1, id2, strict) {
|
|
4066
|
+
if (strict) {
|
|
4067
|
+
return id1 === id2;
|
|
4068
|
+
}
|
|
4069
|
+
return id1.toLowerCase() === id2.toLowerCase();
|
|
4070
|
+
}
|
|
4071
|
+
async remove(options) {
|
|
4072
|
+
const {
|
|
4073
|
+
rootDir,
|
|
4074
|
+
componentsDir,
|
|
4075
|
+
compositionsDir,
|
|
4076
|
+
compositionPatternsDir,
|
|
4077
|
+
componentPatternsDir,
|
|
4078
|
+
componentType,
|
|
4079
|
+
parameterId,
|
|
4080
|
+
whatIf,
|
|
4081
|
+
strict
|
|
4082
|
+
} = options;
|
|
4083
|
+
const findOptions = { strict };
|
|
4084
|
+
const fullComponentsDir = this.fileSystem.resolvePath(rootDir, componentsDir);
|
|
4085
|
+
const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
|
|
4086
|
+
const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
|
|
4087
|
+
const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
|
|
4088
|
+
this.logger.info(`Loading component: ${componentType}`);
|
|
4089
|
+
const { component, filePath: componentFilePath } = await this.componentService.loadComponent(fullComponentsDir, componentType, findOptions);
|
|
4090
|
+
const param = this.componentService.findParameter(component, parameterId, findOptions);
|
|
4091
|
+
if (!param) {
|
|
4092
|
+
throw new PropertyNotFoundError(parameterId, componentType);
|
|
4093
|
+
}
|
|
4094
|
+
this.logger.action(
|
|
4095
|
+
whatIf,
|
|
4096
|
+
"REMOVE",
|
|
4097
|
+
`Parameter "${parameterId}" from component/${this.fileSystem.getBasename(componentFilePath)}`
|
|
4098
|
+
);
|
|
4099
|
+
let modifiedComponent = this.componentService.removeParameter(component, parameterId, findOptions);
|
|
4100
|
+
const beforeGroupCount = modifiedComponent.parameters?.filter(
|
|
4101
|
+
(p) => this.componentService.isGroupParameter(p)
|
|
4102
|
+
).length ?? 0;
|
|
4103
|
+
modifiedComponent = this.componentService.removeEmptyGroups(modifiedComponent);
|
|
4104
|
+
const afterGroupCount = modifiedComponent.parameters?.filter(
|
|
4105
|
+
(p) => this.componentService.isGroupParameter(p)
|
|
4106
|
+
).length ?? 0;
|
|
4107
|
+
if (afterGroupCount < beforeGroupCount) {
|
|
4108
|
+
const removedCount = beforeGroupCount - afterGroupCount;
|
|
4109
|
+
this.logger.action(
|
|
4110
|
+
whatIf,
|
|
4111
|
+
"REMOVE",
|
|
4112
|
+
`${removedCount} empty group(s) from component/${this.fileSystem.getBasename(componentFilePath)}`
|
|
4113
|
+
);
|
|
4114
|
+
}
|
|
4115
|
+
if (!whatIf) {
|
|
4116
|
+
await this.componentService.saveComponent(componentFilePath, modifiedComponent);
|
|
4117
|
+
}
|
|
4118
|
+
const compositionsResult = await this.removeParameterInDirectory(
|
|
4119
|
+
fullCompositionsDir,
|
|
4120
|
+
componentType,
|
|
4121
|
+
parameterId,
|
|
4122
|
+
whatIf,
|
|
4123
|
+
strict,
|
|
4124
|
+
"composition"
|
|
4125
|
+
);
|
|
4126
|
+
const compositionPatternsResult = await this.removeParameterInDirectory(
|
|
4127
|
+
fullCompositionPatternsDir,
|
|
4128
|
+
componentType,
|
|
4129
|
+
parameterId,
|
|
4130
|
+
whatIf,
|
|
4131
|
+
strict,
|
|
4132
|
+
"compositionPattern"
|
|
4133
|
+
);
|
|
4134
|
+
const componentPatternsResult = await this.removeParameterInDirectory(
|
|
4135
|
+
fullComponentPatternsDir,
|
|
4136
|
+
componentType,
|
|
4137
|
+
parameterId,
|
|
4138
|
+
whatIf,
|
|
4139
|
+
strict,
|
|
4140
|
+
"componentPattern"
|
|
4141
|
+
);
|
|
4142
|
+
const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
|
|
4143
|
+
const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
|
|
4144
|
+
this.logger.info("");
|
|
4145
|
+
this.logger.info(
|
|
4146
|
+
`Summary: 1 component definition updated, ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
|
|
4147
|
+
);
|
|
4148
|
+
return {
|
|
4149
|
+
componentDefinitionUpdated: true,
|
|
4150
|
+
compositionsModified: compositionsResult.filesModified,
|
|
4151
|
+
compositionPatternsModified: compositionPatternsResult.filesModified,
|
|
4152
|
+
componentPatternsModified: componentPatternsResult.filesModified,
|
|
4153
|
+
instancesUpdated: totalInstances
|
|
4154
|
+
};
|
|
4155
|
+
}
|
|
4156
|
+
async removeParameterInDirectory(directory, componentType, parameterId, whatIf, strict, label) {
|
|
4157
|
+
let files;
|
|
4158
|
+
try {
|
|
4159
|
+
files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
|
|
4160
|
+
} catch {
|
|
4161
|
+
return { filesModified: 0, instancesUpdated: 0 };
|
|
4162
|
+
}
|
|
4163
|
+
if (files.length === 0) {
|
|
4164
|
+
return { filesModified: 0, instancesUpdated: 0 };
|
|
4165
|
+
}
|
|
4166
|
+
let filesModified = 0;
|
|
4167
|
+
let instancesUpdated = 0;
|
|
4168
|
+
for (const filePath of files) {
|
|
4169
|
+
let composition;
|
|
4170
|
+
try {
|
|
4171
|
+
composition = await this.fileSystem.readFile(filePath);
|
|
4172
|
+
} catch {
|
|
4173
|
+
continue;
|
|
4174
|
+
}
|
|
4175
|
+
if (!composition?.composition) {
|
|
4176
|
+
continue;
|
|
4177
|
+
}
|
|
4178
|
+
const count = this.removeParameterFromTree(
|
|
4179
|
+
composition.composition,
|
|
4180
|
+
componentType,
|
|
4181
|
+
parameterId,
|
|
4182
|
+
strict
|
|
4183
|
+
);
|
|
4184
|
+
const overridesCount = this.removeParameterFromOverrides(
|
|
4185
|
+
composition,
|
|
4186
|
+
componentType,
|
|
4187
|
+
parameterId,
|
|
4188
|
+
strict
|
|
4189
|
+
);
|
|
4190
|
+
const totalCount = count + overridesCount;
|
|
4191
|
+
if (totalCount > 0) {
|
|
4192
|
+
const relativePath = filePath.replace(directory, "").replace(/^[/\\]/, "");
|
|
4193
|
+
this.logger.action(
|
|
4194
|
+
whatIf,
|
|
4195
|
+
"UPDATE",
|
|
4196
|
+
`${label}/${relativePath} (${totalCount} instance(s) of ${componentType})`
|
|
4197
|
+
);
|
|
4198
|
+
if (!whatIf) {
|
|
4199
|
+
await this.fileSystem.writeFile(filePath, composition);
|
|
4200
|
+
}
|
|
4201
|
+
filesModified++;
|
|
4202
|
+
instancesUpdated += totalCount;
|
|
4203
|
+
}
|
|
4204
|
+
}
|
|
4205
|
+
return { filesModified, instancesUpdated };
|
|
4206
|
+
}
|
|
4207
|
+
removeParameterFromTree(node, componentType, parameterId, strict) {
|
|
4208
|
+
let count = 0;
|
|
4209
|
+
if (this.compareIds(node.type, componentType, strict) && node.parameters) {
|
|
4210
|
+
const removed = this.removeKeyFromMap(node.parameters, parameterId, strict);
|
|
4211
|
+
if (removed) {
|
|
4212
|
+
count++;
|
|
4213
|
+
}
|
|
4214
|
+
}
|
|
4215
|
+
if (node.slots) {
|
|
4216
|
+
for (const slotInstances of Object.values(node.slots)) {
|
|
4217
|
+
if (!Array.isArray(slotInstances)) continue;
|
|
4218
|
+
for (const instance of slotInstances) {
|
|
4219
|
+
count += this.removeParameterFromTree(instance, componentType, parameterId, strict);
|
|
4220
|
+
}
|
|
4221
|
+
}
|
|
4222
|
+
}
|
|
4223
|
+
return count;
|
|
4224
|
+
}
|
|
4225
|
+
removeParameterFromOverrides(composition, componentType, parameterId, strict) {
|
|
4226
|
+
if (!composition.composition._overrides) {
|
|
4227
|
+
return 0;
|
|
4228
|
+
}
|
|
4229
|
+
let count = 0;
|
|
4230
|
+
if (this.compareIds(composition.composition.type, componentType, strict)) {
|
|
4231
|
+
const rootId = composition.composition._id;
|
|
4232
|
+
const rootOverrides = composition.composition._overrides[rootId];
|
|
4233
|
+
if (rootOverrides?.parameters) {
|
|
4234
|
+
const removed = this.removeKeyFromMap(rootOverrides.parameters, parameterId, strict);
|
|
4235
|
+
if (removed) {
|
|
4236
|
+
count++;
|
|
4237
|
+
}
|
|
4238
|
+
}
|
|
4239
|
+
}
|
|
4240
|
+
const counter = { count: 0 };
|
|
4241
|
+
this.removeOverridesForMatchingInstances(
|
|
4242
|
+
composition.composition,
|
|
4243
|
+
composition.composition._overrides,
|
|
4244
|
+
componentType,
|
|
4245
|
+
parameterId,
|
|
4246
|
+
strict,
|
|
4247
|
+
counter
|
|
4248
|
+
);
|
|
4249
|
+
count += counter.count;
|
|
4250
|
+
return count;
|
|
4251
|
+
}
|
|
4252
|
+
removeOverridesForMatchingInstances(node, overrides, componentType, parameterId, strict, counter) {
|
|
4253
|
+
if (node.slots) {
|
|
4254
|
+
for (const slotInstances of Object.values(node.slots)) {
|
|
4255
|
+
if (!Array.isArray(slotInstances)) continue;
|
|
4256
|
+
for (const instance of slotInstances) {
|
|
4257
|
+
if (this.compareIds(instance.type, componentType, strict) && instance._id) {
|
|
4258
|
+
const instanceOverrides = overrides[instance._id];
|
|
4259
|
+
if (instanceOverrides?.parameters) {
|
|
4260
|
+
const removed = this.removeKeyFromMap(instanceOverrides.parameters, parameterId, strict);
|
|
4261
|
+
if (removed) {
|
|
4262
|
+
counter.count++;
|
|
4263
|
+
}
|
|
4264
|
+
}
|
|
4265
|
+
}
|
|
4266
|
+
this.removeOverridesForMatchingInstances(
|
|
4267
|
+
instance,
|
|
4268
|
+
overrides,
|
|
4269
|
+
componentType,
|
|
4270
|
+
parameterId,
|
|
4271
|
+
strict,
|
|
4272
|
+
counter
|
|
4273
|
+
);
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
}
|
|
4277
|
+
}
|
|
4278
|
+
removeKeyFromMap(map, key, strict) {
|
|
4279
|
+
const matchingKey = Object.keys(map).find(
|
|
4280
|
+
(k) => this.compareIds(k, key, strict)
|
|
4281
|
+
);
|
|
4282
|
+
if (!matchingKey) {
|
|
4283
|
+
return false;
|
|
4284
|
+
}
|
|
4285
|
+
delete map[matchingKey];
|
|
4286
|
+
return true;
|
|
4287
|
+
}
|
|
4288
|
+
};
|
|
4289
|
+
|
|
4290
|
+
// src/cli/commands/remove-parameter.ts
|
|
4291
|
+
function createRemoveParameterCommand() {
|
|
4292
|
+
const command = new Command11("remove-parameter");
|
|
4293
|
+
command.description(
|
|
4294
|
+
"Removes a parameter definition from a component and deletes all corresponding parameter values from compositions, composition patterns, and component patterns."
|
|
4295
|
+
).option("--componentType <type>", "The component type that owns the parameter to remove").option("--parameterId <id>", "The parameter ID to remove").hook("preAction", (thisCommand) => {
|
|
4296
|
+
const opts = thisCommand.opts();
|
|
4297
|
+
const requiredOptions = [
|
|
4298
|
+
{ name: "componentType", flag: "--componentType" },
|
|
4299
|
+
{ name: "parameterId", flag: "--parameterId" }
|
|
4300
|
+
];
|
|
4301
|
+
const missing = requiredOptions.filter((opt) => !opts[opt.name]).map((opt) => opt.flag);
|
|
4302
|
+
if (missing.length > 0) {
|
|
4303
|
+
console.error(`error: missing required options: ${missing.join(", ")}`);
|
|
4304
|
+
process.exit(1);
|
|
4305
|
+
}
|
|
4306
|
+
}).action(async (opts, cmd) => {
|
|
4307
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
4308
|
+
const options = {
|
|
4309
|
+
...globalOpts,
|
|
4310
|
+
componentType: opts.componentType,
|
|
4311
|
+
parameterId: opts.parameterId
|
|
4312
|
+
};
|
|
4313
|
+
const logger = new Logger();
|
|
4314
|
+
const fileSystem = new FileSystemService();
|
|
4315
|
+
const componentService = new ComponentService(fileSystem);
|
|
4316
|
+
const remover = new ParameterRemoverService(fileSystem, componentService, logger);
|
|
4317
|
+
try {
|
|
4318
|
+
const result = await remover.remove({
|
|
4319
|
+
rootDir: options.rootDir,
|
|
4320
|
+
componentsDir: options.componentsDir,
|
|
4321
|
+
compositionsDir: options.compositionsDir,
|
|
4322
|
+
compositionPatternsDir: options.compositionPatternsDir,
|
|
4323
|
+
componentPatternsDir: options.componentPatternsDir,
|
|
4324
|
+
componentType: options.componentType,
|
|
4325
|
+
parameterId: options.parameterId,
|
|
4326
|
+
whatIf: options.whatIf ?? false,
|
|
4327
|
+
strict: options.strict ?? false
|
|
4328
|
+
});
|
|
4329
|
+
logger.success(
|
|
4330
|
+
`Removed parameter: ${result.compositionsModified} composition(s), ${result.compositionPatternsModified} composition pattern(s), ${result.componentPatternsModified} component pattern(s) updated`
|
|
4331
|
+
);
|
|
4332
|
+
} catch (error) {
|
|
4333
|
+
if (error instanceof TransformError) {
|
|
4334
|
+
logger.error(error.message);
|
|
4335
|
+
process.exit(1);
|
|
4336
|
+
}
|
|
4337
|
+
throw error;
|
|
4338
|
+
}
|
|
4339
|
+
});
|
|
4340
|
+
return command;
|
|
4341
|
+
}
|
|
4342
|
+
|
|
4343
|
+
// src/cli/commands/remove-field.ts
|
|
4344
|
+
import { Command as Command12 } from "commander";
|
|
4345
|
+
|
|
4346
|
+
// src/core/services/field-remover.service.ts
|
|
4347
|
+
var FieldRemoverService = class {
|
|
4348
|
+
constructor(fileSystem, logger) {
|
|
4349
|
+
this.fileSystem = fileSystem;
|
|
4350
|
+
this.logger = logger;
|
|
4351
|
+
}
|
|
4352
|
+
compareIds(id1, id2, strict) {
|
|
4353
|
+
if (strict) {
|
|
4354
|
+
return id1 === id2;
|
|
4355
|
+
}
|
|
4356
|
+
return id1.toLowerCase() === id2.toLowerCase();
|
|
4357
|
+
}
|
|
4358
|
+
async remove(options) {
|
|
4359
|
+
const {
|
|
4360
|
+
rootDir,
|
|
4361
|
+
compositionsDir,
|
|
4362
|
+
compositionPatternsDir,
|
|
4363
|
+
componentPatternsDir,
|
|
4364
|
+
componentType,
|
|
4365
|
+
parameterId,
|
|
4366
|
+
whatIf,
|
|
4367
|
+
strict
|
|
4368
|
+
} = options;
|
|
4369
|
+
const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
|
|
4370
|
+
const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
|
|
4371
|
+
const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
|
|
4372
|
+
this.logger.info(`Removing field "${parameterId}" from instances of ${componentType}`);
|
|
4373
|
+
const compositionsResult = await this.removeFieldInDirectory(
|
|
4374
|
+
fullCompositionsDir,
|
|
4375
|
+
componentType,
|
|
4376
|
+
parameterId,
|
|
4377
|
+
whatIf,
|
|
4378
|
+
strict,
|
|
4379
|
+
"composition"
|
|
4380
|
+
);
|
|
4381
|
+
const compositionPatternsResult = await this.removeFieldInDirectory(
|
|
4382
|
+
fullCompositionPatternsDir,
|
|
4383
|
+
componentType,
|
|
4384
|
+
parameterId,
|
|
4385
|
+
whatIf,
|
|
4386
|
+
strict,
|
|
4387
|
+
"compositionPattern"
|
|
4388
|
+
);
|
|
4389
|
+
const componentPatternsResult = await this.removeFieldInDirectory(
|
|
4390
|
+
fullComponentPatternsDir,
|
|
4391
|
+
componentType,
|
|
4392
|
+
parameterId,
|
|
4393
|
+
whatIf,
|
|
4394
|
+
strict,
|
|
4395
|
+
"componentPattern"
|
|
4396
|
+
);
|
|
4397
|
+
const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
|
|
4398
|
+
const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
|
|
4399
|
+
this.logger.info("");
|
|
4400
|
+
this.logger.info(
|
|
4401
|
+
`Summary: ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
|
|
4402
|
+
);
|
|
4403
|
+
return {
|
|
4404
|
+
compositionsModified: compositionsResult.filesModified,
|
|
4405
|
+
compositionPatternsModified: compositionPatternsResult.filesModified,
|
|
4406
|
+
componentPatternsModified: componentPatternsResult.filesModified,
|
|
4407
|
+
instancesUpdated: totalInstances
|
|
4408
|
+
};
|
|
4409
|
+
}
|
|
4410
|
+
async removeFieldInDirectory(directory, componentType, parameterId, whatIf, strict, label) {
|
|
4411
|
+
let files;
|
|
4412
|
+
try {
|
|
4413
|
+
files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
|
|
4414
|
+
} catch {
|
|
4415
|
+
return { filesModified: 0, instancesUpdated: 0 };
|
|
4416
|
+
}
|
|
4417
|
+
if (files.length === 0) {
|
|
4418
|
+
return { filesModified: 0, instancesUpdated: 0 };
|
|
4419
|
+
}
|
|
4420
|
+
let filesModified = 0;
|
|
4421
|
+
let instancesUpdated = 0;
|
|
4422
|
+
for (const filePath of files) {
|
|
4423
|
+
let composition;
|
|
4424
|
+
try {
|
|
4425
|
+
composition = await this.fileSystem.readFile(filePath);
|
|
4426
|
+
} catch {
|
|
4427
|
+
continue;
|
|
4428
|
+
}
|
|
4429
|
+
if (!composition?.composition) {
|
|
4430
|
+
continue;
|
|
4431
|
+
}
|
|
4432
|
+
const treeCount = this.removeFieldFromTree(
|
|
4433
|
+
composition.composition,
|
|
4434
|
+
componentType,
|
|
4435
|
+
parameterId,
|
|
4436
|
+
strict
|
|
4437
|
+
);
|
|
4438
|
+
const overridesCount = this.removeFieldFromOverrides(
|
|
4439
|
+
composition,
|
|
4440
|
+
componentType,
|
|
4441
|
+
parameterId,
|
|
4442
|
+
strict
|
|
4443
|
+
);
|
|
4444
|
+
const totalCount = treeCount + overridesCount;
|
|
4445
|
+
if (totalCount > 0) {
|
|
4446
|
+
const relativePath = filePath.replace(directory, "").replace(/^[/\\]/, "");
|
|
4447
|
+
this.logger.action(
|
|
4448
|
+
whatIf,
|
|
4449
|
+
"UPDATE",
|
|
4450
|
+
`${label}/${relativePath} (${totalCount} instance(s) of ${componentType})`
|
|
4451
|
+
);
|
|
4452
|
+
if (!whatIf) {
|
|
4453
|
+
await this.fileSystem.writeFile(filePath, composition);
|
|
4454
|
+
}
|
|
4455
|
+
filesModified++;
|
|
4456
|
+
instancesUpdated += totalCount;
|
|
4457
|
+
}
|
|
4458
|
+
}
|
|
4459
|
+
return { filesModified, instancesUpdated };
|
|
4460
|
+
}
|
|
4461
|
+
removeFieldFromTree(node, componentType, parameterId, strict) {
|
|
4462
|
+
let count = 0;
|
|
4463
|
+
if (this.compareIds(node.type, componentType, strict) && node.parameters) {
|
|
4464
|
+
const removed = this.removeKeyFromMap(node.parameters, parameterId, strict);
|
|
4465
|
+
if (removed) {
|
|
4466
|
+
count++;
|
|
4467
|
+
}
|
|
4468
|
+
}
|
|
4469
|
+
if (node.slots) {
|
|
4470
|
+
for (const slotInstances of Object.values(node.slots)) {
|
|
4471
|
+
if (!Array.isArray(slotInstances)) continue;
|
|
4472
|
+
for (const instance of slotInstances) {
|
|
4473
|
+
count += this.removeFieldFromTree(instance, componentType, parameterId, strict);
|
|
4474
|
+
}
|
|
4475
|
+
}
|
|
4476
|
+
}
|
|
4477
|
+
return count;
|
|
4478
|
+
}
|
|
4479
|
+
removeFieldFromOverrides(composition, componentType, parameterId, strict) {
|
|
4480
|
+
if (!composition.composition._overrides) {
|
|
4481
|
+
return 0;
|
|
4482
|
+
}
|
|
4483
|
+
let count = 0;
|
|
4484
|
+
if (this.compareIds(composition.composition.type, componentType, strict)) {
|
|
4485
|
+
const rootId = composition.composition._id;
|
|
4486
|
+
const rootOverrides = composition.composition._overrides[rootId];
|
|
4487
|
+
if (rootOverrides?.parameters) {
|
|
4488
|
+
const removed = this.removeKeyFromMap(rootOverrides.parameters, parameterId, strict);
|
|
4489
|
+
if (removed) {
|
|
4490
|
+
count++;
|
|
4491
|
+
}
|
|
4492
|
+
}
|
|
4493
|
+
}
|
|
4494
|
+
count += this.removeOverridesForMatchingInstances(
|
|
4495
|
+
composition.composition,
|
|
4496
|
+
composition.composition._overrides,
|
|
4497
|
+
componentType,
|
|
4498
|
+
parameterId,
|
|
4499
|
+
strict
|
|
4500
|
+
);
|
|
4501
|
+
return count;
|
|
4502
|
+
}
|
|
4503
|
+
removeOverridesForMatchingInstances(node, overrides, componentType, parameterId, strict) {
|
|
4504
|
+
let count = 0;
|
|
4505
|
+
if (node.slots) {
|
|
4506
|
+
for (const slotInstances of Object.values(node.slots)) {
|
|
4507
|
+
if (!Array.isArray(slotInstances)) continue;
|
|
4508
|
+
for (const instance of slotInstances) {
|
|
4509
|
+
if (this.compareIds(instance.type, componentType, strict) && instance._id) {
|
|
4510
|
+
const instanceOverrides = overrides[instance._id];
|
|
4511
|
+
if (instanceOverrides?.parameters) {
|
|
4512
|
+
const removed = this.removeKeyFromMap(instanceOverrides.parameters, parameterId, strict);
|
|
4513
|
+
if (removed) {
|
|
4514
|
+
count++;
|
|
4515
|
+
}
|
|
4516
|
+
}
|
|
4517
|
+
}
|
|
4518
|
+
count += this.removeOverridesForMatchingInstances(
|
|
4519
|
+
instance,
|
|
4520
|
+
overrides,
|
|
4521
|
+
componentType,
|
|
4522
|
+
parameterId,
|
|
4523
|
+
strict
|
|
4524
|
+
);
|
|
4525
|
+
}
|
|
4526
|
+
}
|
|
4527
|
+
}
|
|
4528
|
+
return count;
|
|
4529
|
+
}
|
|
4530
|
+
removeKeyFromMap(map, key, strict) {
|
|
4531
|
+
const matchingKey = Object.keys(map).find(
|
|
4532
|
+
(k) => this.compareIds(k, key, strict)
|
|
4533
|
+
);
|
|
4534
|
+
if (!matchingKey) {
|
|
4535
|
+
return false;
|
|
4536
|
+
}
|
|
4537
|
+
delete map[matchingKey];
|
|
4538
|
+
return true;
|
|
4539
|
+
}
|
|
4540
|
+
};
|
|
4541
|
+
|
|
4542
|
+
// src/cli/commands/remove-field.ts
|
|
4543
|
+
function createRemoveFieldCommand() {
|
|
4544
|
+
const command = new Command12("remove-field");
|
|
4545
|
+
command.description(
|
|
4546
|
+
"Removes parameter values from component instances in compositions, composition patterns, and component patterns without modifying the component definition."
|
|
4547
|
+
).option("--componentType <type>", "The component type whose instances should have the parameter value removed").option("--parameterId <id>", "The parameter value key to remove from matching instances").hook("preAction", (thisCommand) => {
|
|
4548
|
+
const opts = thisCommand.opts();
|
|
4549
|
+
const requiredOptions = [
|
|
4550
|
+
{ name: "componentType", flag: "--componentType" },
|
|
4551
|
+
{ name: "parameterId", flag: "--parameterId" }
|
|
4552
|
+
];
|
|
4553
|
+
const missing = requiredOptions.filter((opt) => !opts[opt.name]).map((opt) => opt.flag);
|
|
4554
|
+
if (missing.length > 0) {
|
|
4555
|
+
console.error(`error: missing required options: ${missing.join(", ")}`);
|
|
4556
|
+
process.exit(1);
|
|
4557
|
+
}
|
|
4558
|
+
}).action(async (opts, cmd) => {
|
|
4559
|
+
const globalOpts = cmd.optsWithGlobals();
|
|
4560
|
+
const options = {
|
|
4561
|
+
...globalOpts,
|
|
4562
|
+
componentType: opts.componentType,
|
|
4563
|
+
parameterId: opts.parameterId
|
|
4564
|
+
};
|
|
4565
|
+
const logger = new Logger();
|
|
4566
|
+
const fileSystem = new FileSystemService();
|
|
4567
|
+
const remover = new FieldRemoverService(fileSystem, logger);
|
|
4568
|
+
try {
|
|
4569
|
+
const result = await remover.remove({
|
|
4570
|
+
rootDir: options.rootDir,
|
|
4571
|
+
compositionsDir: options.compositionsDir,
|
|
4572
|
+
compositionPatternsDir: options.compositionPatternsDir,
|
|
4573
|
+
componentPatternsDir: options.componentPatternsDir,
|
|
4574
|
+
componentType: options.componentType,
|
|
4575
|
+
parameterId: options.parameterId,
|
|
4576
|
+
whatIf: options.whatIf ?? false,
|
|
4577
|
+
strict: options.strict ?? false
|
|
4578
|
+
});
|
|
4579
|
+
logger.success(
|
|
4580
|
+
`Removed field: ${result.compositionsModified} composition(s), ${result.compositionPatternsModified} composition pattern(s), ${result.componentPatternsModified} component pattern(s) updated`
|
|
4581
|
+
);
|
|
4582
|
+
} catch (error) {
|
|
4583
|
+
if (error instanceof TransformError) {
|
|
4584
|
+
logger.error(error.message);
|
|
4585
|
+
process.exit(1);
|
|
4586
|
+
}
|
|
4587
|
+
throw error;
|
|
4588
|
+
}
|
|
4589
|
+
});
|
|
4590
|
+
return command;
|
|
4591
|
+
}
|
|
4592
|
+
|
|
4053
4593
|
// package.json
|
|
4054
4594
|
var package_default = {
|
|
4055
4595
|
name: "@uniformdev/transformer",
|
|
4056
|
-
version: "1.1.
|
|
4596
|
+
version: "1.1.14",
|
|
4057
4597
|
description: "CLI tool for transforming Uniform.dev serialization files offline",
|
|
4058
4598
|
type: "module",
|
|
4059
4599
|
bin: {
|
|
@@ -4122,7 +4662,7 @@ var package_default = {
|
|
|
4122
4662
|
};
|
|
4123
4663
|
|
|
4124
4664
|
// src/cli/index.ts
|
|
4125
|
-
var program = new
|
|
4665
|
+
var program = new Command13();
|
|
4126
4666
|
var appVersion = package_default.version;
|
|
4127
4667
|
console.error(`uniform-transform v${appVersion}`);
|
|
4128
4668
|
program.name("uniform-transform").description("CLI tool for transforming Uniform.dev serialization files offline").version(appVersion);
|
|
@@ -4145,5 +4685,7 @@ program.addCommand(createAddComponentCommand());
|
|
|
4145
4685
|
program.addCommand(createAddComponentPatternCommand());
|
|
4146
4686
|
program.addCommand(createPropagateRootComponentSlotCommand());
|
|
4147
4687
|
program.addCommand(createConvertCompositionsToEntriesCommand());
|
|
4688
|
+
program.addCommand(createRemoveParameterCommand());
|
|
4689
|
+
program.addCommand(createRemoveFieldCommand());
|
|
4148
4690
|
program.parse();
|
|
4149
4691
|
//# sourceMappingURL=index.js.map
|