@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/index.d.ts
CHANGED
|
@@ -132,6 +132,14 @@ interface ConvertCompositionsToEntriesOptions extends GlobalOptions {
|
|
|
132
132
|
compositionTypes: string;
|
|
133
133
|
flattenComponentIds?: string;
|
|
134
134
|
}
|
|
135
|
+
interface RemoveParameterOptions extends GlobalOptions {
|
|
136
|
+
componentType: string;
|
|
137
|
+
parameterId: string;
|
|
138
|
+
}
|
|
139
|
+
interface RemoveFieldOptions extends GlobalOptions {
|
|
140
|
+
componentType: string;
|
|
141
|
+
parameterId: string;
|
|
142
|
+
}
|
|
135
143
|
|
|
136
144
|
declare class TransformError extends Error {
|
|
137
145
|
constructor(message: string);
|
|
@@ -474,4 +482,65 @@ declare class CompositionConverterService {
|
|
|
474
482
|
*/
|
|
475
483
|
declare function computeGuidHash(guidOrSeed: string): string;
|
|
476
484
|
|
|
477
|
-
|
|
485
|
+
interface RemoveParameterInternalOptions {
|
|
486
|
+
rootDir: string;
|
|
487
|
+
componentsDir: string;
|
|
488
|
+
compositionsDir: string;
|
|
489
|
+
compositionPatternsDir: string;
|
|
490
|
+
componentPatternsDir: string;
|
|
491
|
+
componentType: string;
|
|
492
|
+
parameterId: string;
|
|
493
|
+
whatIf: boolean;
|
|
494
|
+
strict: boolean;
|
|
495
|
+
}
|
|
496
|
+
interface RemoveParameterResult {
|
|
497
|
+
componentDefinitionUpdated: boolean;
|
|
498
|
+
compositionsModified: number;
|
|
499
|
+
compositionPatternsModified: number;
|
|
500
|
+
componentPatternsModified: number;
|
|
501
|
+
instancesUpdated: number;
|
|
502
|
+
}
|
|
503
|
+
declare class ParameterRemoverService {
|
|
504
|
+
private fileSystem;
|
|
505
|
+
private componentService;
|
|
506
|
+
private logger;
|
|
507
|
+
constructor(fileSystem: FileSystemService, componentService: ComponentService, logger: Logger);
|
|
508
|
+
private compareIds;
|
|
509
|
+
remove(options: RemoveParameterInternalOptions): Promise<RemoveParameterResult>;
|
|
510
|
+
private removeParameterInDirectory;
|
|
511
|
+
private removeParameterFromTree;
|
|
512
|
+
private removeParameterFromOverrides;
|
|
513
|
+
private removeOverridesForMatchingInstances;
|
|
514
|
+
private removeKeyFromMap;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
interface RemoveFieldInternalOptions {
|
|
518
|
+
rootDir: string;
|
|
519
|
+
compositionsDir: string;
|
|
520
|
+
compositionPatternsDir: string;
|
|
521
|
+
componentPatternsDir: string;
|
|
522
|
+
componentType: string;
|
|
523
|
+
parameterId: string;
|
|
524
|
+
whatIf: boolean;
|
|
525
|
+
strict: boolean;
|
|
526
|
+
}
|
|
527
|
+
interface RemoveFieldResult {
|
|
528
|
+
compositionsModified: number;
|
|
529
|
+
compositionPatternsModified: number;
|
|
530
|
+
componentPatternsModified: number;
|
|
531
|
+
instancesUpdated: number;
|
|
532
|
+
}
|
|
533
|
+
declare class FieldRemoverService {
|
|
534
|
+
private fileSystem;
|
|
535
|
+
private logger;
|
|
536
|
+
constructor(fileSystem: FileSystemService, logger: Logger);
|
|
537
|
+
private compareIds;
|
|
538
|
+
remove(options: RemoveFieldInternalOptions): Promise<RemoveFieldResult>;
|
|
539
|
+
private removeFieldInDirectory;
|
|
540
|
+
private removeFieldFromTree;
|
|
541
|
+
private removeFieldFromOverrides;
|
|
542
|
+
private removeOverridesForMatchingInstances;
|
|
543
|
+
private removeKeyFromMap;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
export { type AddComponentOptions, type AddComponentPatternOptions, ComponentAdderService, ComponentAlreadyExistsError, type ComponentDefinition, type ComponentInstance, ComponentNotFoundError, ComponentRenamerService, ComponentService, type Composition, CompositionConverterService, type CompositionOverrides, type CompositionPatternCandidatesOptions, type CompositionRoot, CompositionService, type ConvertCompositionsToEntriesOptions, DuplicateIdError, FieldRemoverService, FileNotFoundError, FileSystemService, type GlobalOptions, InvalidYamlError, Logger, type PackSerializationOptions, type Parameter, ParameterRemoverService, type ParameterValue, type PropagateRootComponentPropertyOptions, type PropagateRootComponentSlotOptions, PropertyNotFoundError, PropertyPropagatorService, type RemoveFieldOptions, type RemoveParameterOptions, type RenameComponentOptions, type RenameSlotOptions, SlotAlreadyExistsError, type SlotDefinition, SlotNotFoundError, SlotRenamerService, TransformError, type UnpackSerializationOptions, computeGuidHash };
|
package/dist/index.js
CHANGED
|
@@ -1770,11 +1770,12 @@ var CompositionConverterService = class {
|
|
|
1770
1770
|
if (flattenComponentIds.length > 0) {
|
|
1771
1771
|
this.transformContentReferences(entry);
|
|
1772
1772
|
}
|
|
1773
|
-
const
|
|
1773
|
+
const entryId = entry.entry._id;
|
|
1774
|
+
const entryFilePath = this.fileSystem.joinPath(entriesDirFull, `${entryId}.json`);
|
|
1774
1775
|
this.logger.action(
|
|
1775
1776
|
whatIf,
|
|
1776
1777
|
"WRITE",
|
|
1777
|
-
`${entriesDir}/${
|
|
1778
|
+
`${entriesDir}/${entryId}.json (${compositionType}, "${this.truncate(compositionName, 50)}")`
|
|
1778
1779
|
);
|
|
1779
1780
|
if (!whatIf) {
|
|
1780
1781
|
await this.fileSystem.writeFile(entryFilePath, entry);
|
|
@@ -1906,9 +1907,10 @@ var CompositionConverterService = class {
|
|
|
1906
1907
|
extraWrapperProps[key] = value;
|
|
1907
1908
|
}
|
|
1908
1909
|
}
|
|
1910
|
+
const entryId = computeGuidHash(`entry${comp._id}`);
|
|
1909
1911
|
return {
|
|
1910
1912
|
entry: {
|
|
1911
|
-
_id:
|
|
1913
|
+
_id: entryId,
|
|
1912
1914
|
_name: comp._name ?? comp._id,
|
|
1913
1915
|
type: comp.type,
|
|
1914
1916
|
fields: { ...comp.parameters ?? {} },
|
|
@@ -2054,6 +2056,434 @@ function formatAsBracedUuid(uuid) {
|
|
|
2054
2056
|
return `{${clean}}`;
|
|
2055
2057
|
}
|
|
2056
2058
|
|
|
2059
|
+
// src/core/services/parameter-remover.service.ts
|
|
2060
|
+
var ParameterRemoverService = class {
|
|
2061
|
+
constructor(fileSystem, componentService, logger) {
|
|
2062
|
+
this.fileSystem = fileSystem;
|
|
2063
|
+
this.componentService = componentService;
|
|
2064
|
+
this.logger = logger;
|
|
2065
|
+
}
|
|
2066
|
+
compareIds(id1, id2, strict) {
|
|
2067
|
+
if (strict) {
|
|
2068
|
+
return id1 === id2;
|
|
2069
|
+
}
|
|
2070
|
+
return id1.toLowerCase() === id2.toLowerCase();
|
|
2071
|
+
}
|
|
2072
|
+
async remove(options) {
|
|
2073
|
+
const {
|
|
2074
|
+
rootDir,
|
|
2075
|
+
componentsDir,
|
|
2076
|
+
compositionsDir,
|
|
2077
|
+
compositionPatternsDir,
|
|
2078
|
+
componentPatternsDir,
|
|
2079
|
+
componentType,
|
|
2080
|
+
parameterId,
|
|
2081
|
+
whatIf,
|
|
2082
|
+
strict
|
|
2083
|
+
} = options;
|
|
2084
|
+
const findOptions = { strict };
|
|
2085
|
+
const fullComponentsDir = this.fileSystem.resolvePath(rootDir, componentsDir);
|
|
2086
|
+
const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
|
|
2087
|
+
const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
|
|
2088
|
+
const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
|
|
2089
|
+
this.logger.info(`Loading component: ${componentType}`);
|
|
2090
|
+
const { component, filePath: componentFilePath } = await this.componentService.loadComponent(fullComponentsDir, componentType, findOptions);
|
|
2091
|
+
const param = this.componentService.findParameter(component, parameterId, findOptions);
|
|
2092
|
+
if (!param) {
|
|
2093
|
+
throw new PropertyNotFoundError(parameterId, componentType);
|
|
2094
|
+
}
|
|
2095
|
+
this.logger.action(
|
|
2096
|
+
whatIf,
|
|
2097
|
+
"REMOVE",
|
|
2098
|
+
`Parameter "${parameterId}" from component/${this.fileSystem.getBasename(componentFilePath)}`
|
|
2099
|
+
);
|
|
2100
|
+
let modifiedComponent = this.componentService.removeParameter(component, parameterId, findOptions);
|
|
2101
|
+
const beforeGroupCount = modifiedComponent.parameters?.filter(
|
|
2102
|
+
(p) => this.componentService.isGroupParameter(p)
|
|
2103
|
+
).length ?? 0;
|
|
2104
|
+
modifiedComponent = this.componentService.removeEmptyGroups(modifiedComponent);
|
|
2105
|
+
const afterGroupCount = modifiedComponent.parameters?.filter(
|
|
2106
|
+
(p) => this.componentService.isGroupParameter(p)
|
|
2107
|
+
).length ?? 0;
|
|
2108
|
+
if (afterGroupCount < beforeGroupCount) {
|
|
2109
|
+
const removedCount = beforeGroupCount - afterGroupCount;
|
|
2110
|
+
this.logger.action(
|
|
2111
|
+
whatIf,
|
|
2112
|
+
"REMOVE",
|
|
2113
|
+
`${removedCount} empty group(s) from component/${this.fileSystem.getBasename(componentFilePath)}`
|
|
2114
|
+
);
|
|
2115
|
+
}
|
|
2116
|
+
if (!whatIf) {
|
|
2117
|
+
await this.componentService.saveComponent(componentFilePath, modifiedComponent);
|
|
2118
|
+
}
|
|
2119
|
+
const compositionsResult = await this.removeParameterInDirectory(
|
|
2120
|
+
fullCompositionsDir,
|
|
2121
|
+
componentType,
|
|
2122
|
+
parameterId,
|
|
2123
|
+
whatIf,
|
|
2124
|
+
strict,
|
|
2125
|
+
"composition"
|
|
2126
|
+
);
|
|
2127
|
+
const compositionPatternsResult = await this.removeParameterInDirectory(
|
|
2128
|
+
fullCompositionPatternsDir,
|
|
2129
|
+
componentType,
|
|
2130
|
+
parameterId,
|
|
2131
|
+
whatIf,
|
|
2132
|
+
strict,
|
|
2133
|
+
"compositionPattern"
|
|
2134
|
+
);
|
|
2135
|
+
const componentPatternsResult = await this.removeParameterInDirectory(
|
|
2136
|
+
fullComponentPatternsDir,
|
|
2137
|
+
componentType,
|
|
2138
|
+
parameterId,
|
|
2139
|
+
whatIf,
|
|
2140
|
+
strict,
|
|
2141
|
+
"componentPattern"
|
|
2142
|
+
);
|
|
2143
|
+
const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
|
|
2144
|
+
const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
|
|
2145
|
+
this.logger.info("");
|
|
2146
|
+
this.logger.info(
|
|
2147
|
+
`Summary: 1 component definition updated, ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
|
|
2148
|
+
);
|
|
2149
|
+
return {
|
|
2150
|
+
componentDefinitionUpdated: true,
|
|
2151
|
+
compositionsModified: compositionsResult.filesModified,
|
|
2152
|
+
compositionPatternsModified: compositionPatternsResult.filesModified,
|
|
2153
|
+
componentPatternsModified: componentPatternsResult.filesModified,
|
|
2154
|
+
instancesUpdated: totalInstances
|
|
2155
|
+
};
|
|
2156
|
+
}
|
|
2157
|
+
async removeParameterInDirectory(directory, componentType, parameterId, whatIf, strict, label) {
|
|
2158
|
+
let files;
|
|
2159
|
+
try {
|
|
2160
|
+
files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
|
|
2161
|
+
} catch {
|
|
2162
|
+
return { filesModified: 0, instancesUpdated: 0 };
|
|
2163
|
+
}
|
|
2164
|
+
if (files.length === 0) {
|
|
2165
|
+
return { filesModified: 0, instancesUpdated: 0 };
|
|
2166
|
+
}
|
|
2167
|
+
let filesModified = 0;
|
|
2168
|
+
let instancesUpdated = 0;
|
|
2169
|
+
for (const filePath of files) {
|
|
2170
|
+
let composition;
|
|
2171
|
+
try {
|
|
2172
|
+
composition = await this.fileSystem.readFile(filePath);
|
|
2173
|
+
} catch {
|
|
2174
|
+
continue;
|
|
2175
|
+
}
|
|
2176
|
+
if (!composition?.composition) {
|
|
2177
|
+
continue;
|
|
2178
|
+
}
|
|
2179
|
+
const count = this.removeParameterFromTree(
|
|
2180
|
+
composition.composition,
|
|
2181
|
+
componentType,
|
|
2182
|
+
parameterId,
|
|
2183
|
+
strict
|
|
2184
|
+
);
|
|
2185
|
+
const overridesCount = this.removeParameterFromOverrides(
|
|
2186
|
+
composition,
|
|
2187
|
+
componentType,
|
|
2188
|
+
parameterId,
|
|
2189
|
+
strict
|
|
2190
|
+
);
|
|
2191
|
+
const totalCount = count + overridesCount;
|
|
2192
|
+
if (totalCount > 0) {
|
|
2193
|
+
const relativePath = filePath.replace(directory, "").replace(/^[/\\]/, "");
|
|
2194
|
+
this.logger.action(
|
|
2195
|
+
whatIf,
|
|
2196
|
+
"UPDATE",
|
|
2197
|
+
`${label}/${relativePath} (${totalCount} instance(s) of ${componentType})`
|
|
2198
|
+
);
|
|
2199
|
+
if (!whatIf) {
|
|
2200
|
+
await this.fileSystem.writeFile(filePath, composition);
|
|
2201
|
+
}
|
|
2202
|
+
filesModified++;
|
|
2203
|
+
instancesUpdated += totalCount;
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
return { filesModified, instancesUpdated };
|
|
2207
|
+
}
|
|
2208
|
+
removeParameterFromTree(node, componentType, parameterId, strict) {
|
|
2209
|
+
let count = 0;
|
|
2210
|
+
if (this.compareIds(node.type, componentType, strict) && node.parameters) {
|
|
2211
|
+
const removed = this.removeKeyFromMap(node.parameters, parameterId, strict);
|
|
2212
|
+
if (removed) {
|
|
2213
|
+
count++;
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
if (node.slots) {
|
|
2217
|
+
for (const slotInstances of Object.values(node.slots)) {
|
|
2218
|
+
if (!Array.isArray(slotInstances)) continue;
|
|
2219
|
+
for (const instance of slotInstances) {
|
|
2220
|
+
count += this.removeParameterFromTree(instance, componentType, parameterId, strict);
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
return count;
|
|
2225
|
+
}
|
|
2226
|
+
removeParameterFromOverrides(composition, componentType, parameterId, strict) {
|
|
2227
|
+
if (!composition.composition._overrides) {
|
|
2228
|
+
return 0;
|
|
2229
|
+
}
|
|
2230
|
+
let count = 0;
|
|
2231
|
+
if (this.compareIds(composition.composition.type, componentType, strict)) {
|
|
2232
|
+
const rootId = composition.composition._id;
|
|
2233
|
+
const rootOverrides = composition.composition._overrides[rootId];
|
|
2234
|
+
if (rootOverrides?.parameters) {
|
|
2235
|
+
const removed = this.removeKeyFromMap(rootOverrides.parameters, parameterId, strict);
|
|
2236
|
+
if (removed) {
|
|
2237
|
+
count++;
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
const counter = { count: 0 };
|
|
2242
|
+
this.removeOverridesForMatchingInstances(
|
|
2243
|
+
composition.composition,
|
|
2244
|
+
composition.composition._overrides,
|
|
2245
|
+
componentType,
|
|
2246
|
+
parameterId,
|
|
2247
|
+
strict,
|
|
2248
|
+
counter
|
|
2249
|
+
);
|
|
2250
|
+
count += counter.count;
|
|
2251
|
+
return count;
|
|
2252
|
+
}
|
|
2253
|
+
removeOverridesForMatchingInstances(node, overrides, componentType, parameterId, strict, counter) {
|
|
2254
|
+
if (node.slots) {
|
|
2255
|
+
for (const slotInstances of Object.values(node.slots)) {
|
|
2256
|
+
if (!Array.isArray(slotInstances)) continue;
|
|
2257
|
+
for (const instance of slotInstances) {
|
|
2258
|
+
if (this.compareIds(instance.type, componentType, strict) && instance._id) {
|
|
2259
|
+
const instanceOverrides = overrides[instance._id];
|
|
2260
|
+
if (instanceOverrides?.parameters) {
|
|
2261
|
+
const removed = this.removeKeyFromMap(instanceOverrides.parameters, parameterId, strict);
|
|
2262
|
+
if (removed) {
|
|
2263
|
+
counter.count++;
|
|
2264
|
+
}
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
this.removeOverridesForMatchingInstances(
|
|
2268
|
+
instance,
|
|
2269
|
+
overrides,
|
|
2270
|
+
componentType,
|
|
2271
|
+
parameterId,
|
|
2272
|
+
strict,
|
|
2273
|
+
counter
|
|
2274
|
+
);
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
removeKeyFromMap(map, key, strict) {
|
|
2280
|
+
const matchingKey = Object.keys(map).find(
|
|
2281
|
+
(k) => this.compareIds(k, key, strict)
|
|
2282
|
+
);
|
|
2283
|
+
if (!matchingKey) {
|
|
2284
|
+
return false;
|
|
2285
|
+
}
|
|
2286
|
+
delete map[matchingKey];
|
|
2287
|
+
return true;
|
|
2288
|
+
}
|
|
2289
|
+
};
|
|
2290
|
+
|
|
2291
|
+
// src/core/services/field-remover.service.ts
|
|
2292
|
+
var FieldRemoverService = class {
|
|
2293
|
+
constructor(fileSystem, logger) {
|
|
2294
|
+
this.fileSystem = fileSystem;
|
|
2295
|
+
this.logger = logger;
|
|
2296
|
+
}
|
|
2297
|
+
compareIds(id1, id2, strict) {
|
|
2298
|
+
if (strict) {
|
|
2299
|
+
return id1 === id2;
|
|
2300
|
+
}
|
|
2301
|
+
return id1.toLowerCase() === id2.toLowerCase();
|
|
2302
|
+
}
|
|
2303
|
+
async remove(options) {
|
|
2304
|
+
const {
|
|
2305
|
+
rootDir,
|
|
2306
|
+
compositionsDir,
|
|
2307
|
+
compositionPatternsDir,
|
|
2308
|
+
componentPatternsDir,
|
|
2309
|
+
componentType,
|
|
2310
|
+
parameterId,
|
|
2311
|
+
whatIf,
|
|
2312
|
+
strict
|
|
2313
|
+
} = options;
|
|
2314
|
+
const fullCompositionsDir = this.fileSystem.resolvePath(rootDir, compositionsDir);
|
|
2315
|
+
const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
|
|
2316
|
+
const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
|
|
2317
|
+
this.logger.info(`Removing field "${parameterId}" from instances of ${componentType}`);
|
|
2318
|
+
const compositionsResult = await this.removeFieldInDirectory(
|
|
2319
|
+
fullCompositionsDir,
|
|
2320
|
+
componentType,
|
|
2321
|
+
parameterId,
|
|
2322
|
+
whatIf,
|
|
2323
|
+
strict,
|
|
2324
|
+
"composition"
|
|
2325
|
+
);
|
|
2326
|
+
const compositionPatternsResult = await this.removeFieldInDirectory(
|
|
2327
|
+
fullCompositionPatternsDir,
|
|
2328
|
+
componentType,
|
|
2329
|
+
parameterId,
|
|
2330
|
+
whatIf,
|
|
2331
|
+
strict,
|
|
2332
|
+
"compositionPattern"
|
|
2333
|
+
);
|
|
2334
|
+
const componentPatternsResult = await this.removeFieldInDirectory(
|
|
2335
|
+
fullComponentPatternsDir,
|
|
2336
|
+
componentType,
|
|
2337
|
+
parameterId,
|
|
2338
|
+
whatIf,
|
|
2339
|
+
strict,
|
|
2340
|
+
"componentPattern"
|
|
2341
|
+
);
|
|
2342
|
+
const totalFiles = compositionsResult.filesModified + compositionPatternsResult.filesModified + componentPatternsResult.filesModified;
|
|
2343
|
+
const totalInstances = compositionsResult.instancesUpdated + compositionPatternsResult.instancesUpdated + componentPatternsResult.instancesUpdated;
|
|
2344
|
+
this.logger.info("");
|
|
2345
|
+
this.logger.info(
|
|
2346
|
+
`Summary: ${totalFiles} file(s) (${totalInstances} instance(s)) updated.`
|
|
2347
|
+
);
|
|
2348
|
+
return {
|
|
2349
|
+
compositionsModified: compositionsResult.filesModified,
|
|
2350
|
+
compositionPatternsModified: compositionPatternsResult.filesModified,
|
|
2351
|
+
componentPatternsModified: componentPatternsResult.filesModified,
|
|
2352
|
+
instancesUpdated: totalInstances
|
|
2353
|
+
};
|
|
2354
|
+
}
|
|
2355
|
+
async removeFieldInDirectory(directory, componentType, parameterId, whatIf, strict, label) {
|
|
2356
|
+
let files;
|
|
2357
|
+
try {
|
|
2358
|
+
files = await this.fileSystem.findFiles(directory, "**/*.{json,yaml,yml}");
|
|
2359
|
+
} catch {
|
|
2360
|
+
return { filesModified: 0, instancesUpdated: 0 };
|
|
2361
|
+
}
|
|
2362
|
+
if (files.length === 0) {
|
|
2363
|
+
return { filesModified: 0, instancesUpdated: 0 };
|
|
2364
|
+
}
|
|
2365
|
+
let filesModified = 0;
|
|
2366
|
+
let instancesUpdated = 0;
|
|
2367
|
+
for (const filePath of files) {
|
|
2368
|
+
let composition;
|
|
2369
|
+
try {
|
|
2370
|
+
composition = await this.fileSystem.readFile(filePath);
|
|
2371
|
+
} catch {
|
|
2372
|
+
continue;
|
|
2373
|
+
}
|
|
2374
|
+
if (!composition?.composition) {
|
|
2375
|
+
continue;
|
|
2376
|
+
}
|
|
2377
|
+
const treeCount = this.removeFieldFromTree(
|
|
2378
|
+
composition.composition,
|
|
2379
|
+
componentType,
|
|
2380
|
+
parameterId,
|
|
2381
|
+
strict
|
|
2382
|
+
);
|
|
2383
|
+
const overridesCount = this.removeFieldFromOverrides(
|
|
2384
|
+
composition,
|
|
2385
|
+
componentType,
|
|
2386
|
+
parameterId,
|
|
2387
|
+
strict
|
|
2388
|
+
);
|
|
2389
|
+
const totalCount = treeCount + overridesCount;
|
|
2390
|
+
if (totalCount > 0) {
|
|
2391
|
+
const relativePath = filePath.replace(directory, "").replace(/^[/\\]/, "");
|
|
2392
|
+
this.logger.action(
|
|
2393
|
+
whatIf,
|
|
2394
|
+
"UPDATE",
|
|
2395
|
+
`${label}/${relativePath} (${totalCount} instance(s) of ${componentType})`
|
|
2396
|
+
);
|
|
2397
|
+
if (!whatIf) {
|
|
2398
|
+
await this.fileSystem.writeFile(filePath, composition);
|
|
2399
|
+
}
|
|
2400
|
+
filesModified++;
|
|
2401
|
+
instancesUpdated += totalCount;
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
return { filesModified, instancesUpdated };
|
|
2405
|
+
}
|
|
2406
|
+
removeFieldFromTree(node, componentType, parameterId, strict) {
|
|
2407
|
+
let count = 0;
|
|
2408
|
+
if (this.compareIds(node.type, componentType, strict) && node.parameters) {
|
|
2409
|
+
const removed = this.removeKeyFromMap(node.parameters, parameterId, strict);
|
|
2410
|
+
if (removed) {
|
|
2411
|
+
count++;
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
if (node.slots) {
|
|
2415
|
+
for (const slotInstances of Object.values(node.slots)) {
|
|
2416
|
+
if (!Array.isArray(slotInstances)) continue;
|
|
2417
|
+
for (const instance of slotInstances) {
|
|
2418
|
+
count += this.removeFieldFromTree(instance, componentType, parameterId, strict);
|
|
2419
|
+
}
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
return count;
|
|
2423
|
+
}
|
|
2424
|
+
removeFieldFromOverrides(composition, componentType, parameterId, strict) {
|
|
2425
|
+
if (!composition.composition._overrides) {
|
|
2426
|
+
return 0;
|
|
2427
|
+
}
|
|
2428
|
+
let count = 0;
|
|
2429
|
+
if (this.compareIds(composition.composition.type, componentType, strict)) {
|
|
2430
|
+
const rootId = composition.composition._id;
|
|
2431
|
+
const rootOverrides = composition.composition._overrides[rootId];
|
|
2432
|
+
if (rootOverrides?.parameters) {
|
|
2433
|
+
const removed = this.removeKeyFromMap(rootOverrides.parameters, parameterId, strict);
|
|
2434
|
+
if (removed) {
|
|
2435
|
+
count++;
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
count += this.removeOverridesForMatchingInstances(
|
|
2440
|
+
composition.composition,
|
|
2441
|
+
composition.composition._overrides,
|
|
2442
|
+
componentType,
|
|
2443
|
+
parameterId,
|
|
2444
|
+
strict
|
|
2445
|
+
);
|
|
2446
|
+
return count;
|
|
2447
|
+
}
|
|
2448
|
+
removeOverridesForMatchingInstances(node, overrides, componentType, parameterId, strict) {
|
|
2449
|
+
let count = 0;
|
|
2450
|
+
if (node.slots) {
|
|
2451
|
+
for (const slotInstances of Object.values(node.slots)) {
|
|
2452
|
+
if (!Array.isArray(slotInstances)) continue;
|
|
2453
|
+
for (const instance of slotInstances) {
|
|
2454
|
+
if (this.compareIds(instance.type, componentType, strict) && instance._id) {
|
|
2455
|
+
const instanceOverrides = overrides[instance._id];
|
|
2456
|
+
if (instanceOverrides?.parameters) {
|
|
2457
|
+
const removed = this.removeKeyFromMap(instanceOverrides.parameters, parameterId, strict);
|
|
2458
|
+
if (removed) {
|
|
2459
|
+
count++;
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
count += this.removeOverridesForMatchingInstances(
|
|
2464
|
+
instance,
|
|
2465
|
+
overrides,
|
|
2466
|
+
componentType,
|
|
2467
|
+
parameterId,
|
|
2468
|
+
strict
|
|
2469
|
+
);
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
return count;
|
|
2474
|
+
}
|
|
2475
|
+
removeKeyFromMap(map, key, strict) {
|
|
2476
|
+
const matchingKey = Object.keys(map).find(
|
|
2477
|
+
(k) => this.compareIds(k, key, strict)
|
|
2478
|
+
);
|
|
2479
|
+
if (!matchingKey) {
|
|
2480
|
+
return false;
|
|
2481
|
+
}
|
|
2482
|
+
delete map[matchingKey];
|
|
2483
|
+
return true;
|
|
2484
|
+
}
|
|
2485
|
+
};
|
|
2486
|
+
|
|
2057
2487
|
// src/cli/logger.ts
|
|
2058
2488
|
import chalk from "chalk";
|
|
2059
2489
|
var Logger = class {
|
|
@@ -2086,10 +2516,12 @@ export {
|
|
|
2086
2516
|
CompositionConverterService,
|
|
2087
2517
|
CompositionService,
|
|
2088
2518
|
DuplicateIdError,
|
|
2519
|
+
FieldRemoverService,
|
|
2089
2520
|
FileNotFoundError,
|
|
2090
2521
|
FileSystemService,
|
|
2091
2522
|
InvalidYamlError,
|
|
2092
2523
|
Logger,
|
|
2524
|
+
ParameterRemoverService,
|
|
2093
2525
|
PropertyNotFoundError,
|
|
2094
2526
|
PropertyPropagatorService,
|
|
2095
2527
|
SlotAlreadyExistsError,
|