@uniformdev/transformer 1.1.3 → 1.1.4
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 +92 -76
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +92 -76
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -366,6 +366,8 @@ declare class ComponentAdderService {
|
|
|
366
366
|
private logger;
|
|
367
367
|
constructor(fileSystem: FileSystemService, componentService: ComponentService, logger: Logger);
|
|
368
368
|
private compareIds;
|
|
369
|
+
private parseParentComponentTypes;
|
|
370
|
+
private matchesAnyParentType;
|
|
369
371
|
private parseParameters;
|
|
370
372
|
private generateId;
|
|
371
373
|
private regenerateInstanceIds;
|
package/dist/index.js
CHANGED
|
@@ -1114,6 +1114,12 @@ var ComponentAdderService = class {
|
|
|
1114
1114
|
}
|
|
1115
1115
|
return id1.toLowerCase() === id2.toLowerCase();
|
|
1116
1116
|
}
|
|
1117
|
+
parseParentComponentTypes(parentComponentType) {
|
|
1118
|
+
return parentComponentType.split("|").map((t) => t.trim()).filter((t) => t.length > 0);
|
|
1119
|
+
}
|
|
1120
|
+
matchesAnyParentType(instanceType, parentTypes, strict) {
|
|
1121
|
+
return parentTypes.some((pt) => this.compareIds(instanceType, pt, strict));
|
|
1122
|
+
}
|
|
1117
1123
|
parseParameters(parameterString) {
|
|
1118
1124
|
const result = {};
|
|
1119
1125
|
if (!parameterString) return result;
|
|
@@ -1187,18 +1193,9 @@ var ComponentAdderService = class {
|
|
|
1187
1193
|
const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
|
|
1188
1194
|
const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
|
|
1189
1195
|
const findOptions = { strict };
|
|
1190
|
-
this.
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
parentComponent.slots = [];
|
|
1194
|
-
}
|
|
1195
|
-
let slotDef = parentComponent.slots.find(
|
|
1196
|
-
(s) => this.compareIds(s.id, slot, strict)
|
|
1197
|
-
);
|
|
1198
|
-
if (!slotDef) {
|
|
1199
|
-
this.logger.info(`Slot "${slot}" not found on component "${parentComponentType}", creating it`);
|
|
1200
|
-
slotDef = { id: slot, name: slot, allowedComponents: [] };
|
|
1201
|
-
parentComponent.slots.push(slotDef);
|
|
1196
|
+
const parentTypes = this.parseParentComponentTypes(parentComponentType);
|
|
1197
|
+
if (parentTypes.length === 0) {
|
|
1198
|
+
throw new TransformError("parentComponentType cannot be empty");
|
|
1202
1199
|
}
|
|
1203
1200
|
this.logger.info(`Validating new component: ${newComponentType}`);
|
|
1204
1201
|
try {
|
|
@@ -1212,35 +1209,50 @@ var ComponentAdderService = class {
|
|
|
1212
1209
|
throw error;
|
|
1213
1210
|
}
|
|
1214
1211
|
let allowedComponentsUpdated = false;
|
|
1215
|
-
const
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
if (!actualSlot.allowedComponents) {
|
|
1221
|
-
actualSlot.allowedComponents = [];
|
|
1212
|
+
for (const parentType of parentTypes) {
|
|
1213
|
+
this.logger.info(`Loading parent component: ${parentType}`);
|
|
1214
|
+
const { component: parentComponent, filePath: parentComponentFilePath } = await this.componentService.loadComponent(fullComponentsDir, parentType, findOptions);
|
|
1215
|
+
if (!parentComponent.slots) {
|
|
1216
|
+
parentComponent.slots = [];
|
|
1222
1217
|
}
|
|
1223
|
-
|
|
1224
|
-
(
|
|
1218
|
+
let slotDef = parentComponent.slots.find(
|
|
1219
|
+
(s) => this.compareIds(s.id, slot, strict)
|
|
1225
1220
|
);
|
|
1226
|
-
if (!
|
|
1227
|
-
this.logger.
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1221
|
+
if (!slotDef) {
|
|
1222
|
+
this.logger.info(`Slot "${slot}" not found on component "${parentType}", creating it`);
|
|
1223
|
+
slotDef = { id: slot, name: slot, allowedComponents: [] };
|
|
1224
|
+
parentComponent.slots.push(slotDef);
|
|
1225
|
+
}
|
|
1226
|
+
const slotIndex = parentComponent.slots?.findIndex(
|
|
1227
|
+
(s) => this.compareIds(s.id, slotDef.id, strict)
|
|
1228
|
+
);
|
|
1229
|
+
if (slotIndex !== void 0 && slotIndex >= 0) {
|
|
1230
|
+
const actualSlot = parentComponent.slots[slotIndex];
|
|
1231
|
+
if (!actualSlot.allowedComponents) {
|
|
1232
|
+
actualSlot.allowedComponents = [];
|
|
1233
|
+
}
|
|
1234
|
+
const isAlreadyAllowed = actualSlot.allowedComponents.some(
|
|
1235
|
+
(c) => this.compareIds(c, newComponentType, strict)
|
|
1231
1236
|
);
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1237
|
+
if (!isAlreadyAllowed) {
|
|
1238
|
+
this.logger.action(
|
|
1239
|
+
whatIf,
|
|
1240
|
+
"UPDATE",
|
|
1241
|
+
`Adding "${newComponentType}" to allowedComponents for slot "${slot}" on component "${parentType}"`
|
|
1242
|
+
);
|
|
1243
|
+
actualSlot.allowedComponents.push(newComponentType);
|
|
1244
|
+
if (!whatIf) {
|
|
1245
|
+
await this.componentService.saveComponent(parentComponentFilePath, parentComponent);
|
|
1246
|
+
}
|
|
1247
|
+
allowedComponentsUpdated = true;
|
|
1235
1248
|
}
|
|
1236
|
-
allowedComponentsUpdated = true;
|
|
1237
1249
|
}
|
|
1238
1250
|
}
|
|
1239
1251
|
const parsedParams = this.parseParameters(paramString);
|
|
1240
1252
|
const newInstance = this.createComponentInstance(newComponentType, parsedParams);
|
|
1241
1253
|
const compositionsResult = await this.addComponentToDirectory(
|
|
1242
1254
|
fullCompositionsDir,
|
|
1243
|
-
|
|
1255
|
+
parentTypes,
|
|
1244
1256
|
slot,
|
|
1245
1257
|
newInstance,
|
|
1246
1258
|
whatIf,
|
|
@@ -1249,7 +1261,7 @@ var ComponentAdderService = class {
|
|
|
1249
1261
|
);
|
|
1250
1262
|
const compositionPatternsResult = await this.addComponentToDirectory(
|
|
1251
1263
|
fullCompositionPatternsDir,
|
|
1252
|
-
|
|
1264
|
+
parentTypes,
|
|
1253
1265
|
slot,
|
|
1254
1266
|
newInstance,
|
|
1255
1267
|
whatIf,
|
|
@@ -1258,7 +1270,7 @@ var ComponentAdderService = class {
|
|
|
1258
1270
|
);
|
|
1259
1271
|
const componentPatternsResult = await this.addComponentToDirectory(
|
|
1260
1272
|
fullComponentPatternsDir,
|
|
1261
|
-
|
|
1273
|
+
parentTypes,
|
|
1262
1274
|
slot,
|
|
1263
1275
|
newInstance,
|
|
1264
1276
|
whatIf,
|
|
@@ -1267,7 +1279,7 @@ var ComponentAdderService = class {
|
|
|
1267
1279
|
);
|
|
1268
1280
|
this.logger.info("");
|
|
1269
1281
|
this.logger.info(
|
|
1270
|
-
`Summary: ${allowedComponentsUpdated ?
|
|
1282
|
+
`Summary: ${allowedComponentsUpdated ? `${parentTypes.length} component definition(s) updated, ` : ""}${compositionsResult} composition(s), ${compositionPatternsResult} composition pattern(s), ${componentPatternsResult} component pattern(s) updated. ${compositionsResult + compositionPatternsResult + componentPatternsResult} instance(s) added.`
|
|
1271
1283
|
);
|
|
1272
1284
|
return {
|
|
1273
1285
|
allowedComponentsUpdated,
|
|
@@ -1298,18 +1310,9 @@ var ComponentAdderService = class {
|
|
|
1298
1310
|
const fullCompositionPatternsDir = this.fileSystem.resolvePath(rootDir, compositionPatternsDir);
|
|
1299
1311
|
const fullComponentPatternsDir = this.fileSystem.resolvePath(rootDir, componentPatternsDir);
|
|
1300
1312
|
const findOptions = { strict };
|
|
1301
|
-
this.
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
parentComponent.slots = [];
|
|
1305
|
-
}
|
|
1306
|
-
let slotDef = parentComponent.slots.find(
|
|
1307
|
-
(s) => this.compareIds(s.id, slot, strict)
|
|
1308
|
-
);
|
|
1309
|
-
if (!slotDef) {
|
|
1310
|
-
this.logger.info(`Slot "${slot}" not found on component "${parentComponentType}", creating it`);
|
|
1311
|
-
slotDef = { id: slot, name: slot, allowedComponents: [] };
|
|
1312
|
-
parentComponent.slots.push(slotDef);
|
|
1313
|
+
const parentTypes = this.parseParentComponentTypes(parentComponentType);
|
|
1314
|
+
if (parentTypes.length === 0) {
|
|
1315
|
+
throw new TransformError("parentComponentType cannot be empty");
|
|
1313
1316
|
}
|
|
1314
1317
|
this.logger.info(`Loading component pattern: ${componentPatternId}`);
|
|
1315
1318
|
const pattern = await this.loadComponentPattern(
|
|
@@ -1323,32 +1326,45 @@ var ComponentAdderService = class {
|
|
|
1323
1326
|
`Component pattern "${componentPatternId}" has no valid definition or missing type`
|
|
1324
1327
|
);
|
|
1325
1328
|
}
|
|
1326
|
-
let allowedComponentsUpdated = false;
|
|
1327
1329
|
const componentTypeInPattern = patternDefinition.type;
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
actualSlot.allowedComponents = [];
|
|
1330
|
+
let allowedComponentsUpdated = false;
|
|
1331
|
+
for (const parentType of parentTypes) {
|
|
1332
|
+
this.logger.info(`Loading parent component: ${parentType}`);
|
|
1333
|
+
const { component: parentComponent, filePath: parentComponentFilePath } = await this.componentService.loadComponent(fullComponentsDir, parentType, findOptions);
|
|
1334
|
+
if (!parentComponent.slots) {
|
|
1335
|
+
parentComponent.slots = [];
|
|
1335
1336
|
}
|
|
1336
|
-
|
|
1337
|
-
(
|
|
1337
|
+
let slotDef = parentComponent.slots.find(
|
|
1338
|
+
(s) => this.compareIds(s.id, slot, strict)
|
|
1338
1339
|
);
|
|
1339
|
-
if (!
|
|
1340
|
-
this.logger.
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1340
|
+
if (!slotDef) {
|
|
1341
|
+
this.logger.info(`Slot "${slot}" not found on component "${parentType}", creating it`);
|
|
1342
|
+
slotDef = { id: slot, name: slot, allowedComponents: [] };
|
|
1343
|
+
parentComponent.slots.push(slotDef);
|
|
1344
|
+
}
|
|
1345
|
+
const slotIndex = parentComponent.slots?.findIndex(
|
|
1346
|
+
(s) => this.compareIds(s.id, slotDef.id, strict)
|
|
1347
|
+
);
|
|
1348
|
+
if (slotIndex !== void 0 && slotIndex >= 0) {
|
|
1349
|
+
const actualSlot = parentComponent.slots[slotIndex];
|
|
1350
|
+
if (!actualSlot.allowedComponents) {
|
|
1351
|
+
actualSlot.allowedComponents = [];
|
|
1352
|
+
}
|
|
1353
|
+
const isAlreadyAllowed = actualSlot.allowedComponents.some(
|
|
1354
|
+
(c) => this.compareIds(c, componentTypeInPattern, strict)
|
|
1344
1355
|
);
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1356
|
+
if (!isAlreadyAllowed) {
|
|
1357
|
+
this.logger.action(
|
|
1358
|
+
whatIf,
|
|
1359
|
+
"UPDATE",
|
|
1360
|
+
`Adding "${componentTypeInPattern}" to allowedComponents for slot "${slot}" on component "${parentType}"`
|
|
1349
1361
|
);
|
|
1362
|
+
actualSlot.allowedComponents.push(componentTypeInPattern);
|
|
1363
|
+
if (!whatIf) {
|
|
1364
|
+
await this.componentService.saveComponent(parentComponentFilePath, parentComponent);
|
|
1365
|
+
}
|
|
1366
|
+
allowedComponentsUpdated = true;
|
|
1350
1367
|
}
|
|
1351
|
-
allowedComponentsUpdated = true;
|
|
1352
1368
|
}
|
|
1353
1369
|
}
|
|
1354
1370
|
const newInstance = {
|
|
@@ -1358,7 +1374,7 @@ var ComponentAdderService = class {
|
|
|
1358
1374
|
};
|
|
1359
1375
|
const compositionsResult = await this.addComponentToDirectory(
|
|
1360
1376
|
fullCompositionsDir,
|
|
1361
|
-
|
|
1377
|
+
parentTypes,
|
|
1362
1378
|
slot,
|
|
1363
1379
|
newInstance,
|
|
1364
1380
|
whatIf,
|
|
@@ -1367,7 +1383,7 @@ var ComponentAdderService = class {
|
|
|
1367
1383
|
);
|
|
1368
1384
|
const compositionPatternsResult = await this.addComponentToDirectory(
|
|
1369
1385
|
fullCompositionPatternsDir,
|
|
1370
|
-
|
|
1386
|
+
parentTypes,
|
|
1371
1387
|
slot,
|
|
1372
1388
|
newInstance,
|
|
1373
1389
|
whatIf,
|
|
@@ -1376,7 +1392,7 @@ var ComponentAdderService = class {
|
|
|
1376
1392
|
);
|
|
1377
1393
|
const componentPatternsResult = await this.addComponentToDirectory(
|
|
1378
1394
|
fullComponentPatternsDir,
|
|
1379
|
-
|
|
1395
|
+
parentTypes,
|
|
1380
1396
|
slot,
|
|
1381
1397
|
newInstance,
|
|
1382
1398
|
whatIf,
|
|
@@ -1385,7 +1401,7 @@ var ComponentAdderService = class {
|
|
|
1385
1401
|
);
|
|
1386
1402
|
this.logger.info("");
|
|
1387
1403
|
this.logger.info(
|
|
1388
|
-
`Summary: ${allowedComponentsUpdated ?
|
|
1404
|
+
`Summary: ${allowedComponentsUpdated ? `${parentTypes.length} component definition(s) updated, ` : ""}${compositionsResult} composition(s), ${compositionPatternsResult} composition pattern(s), ${componentPatternsResult} component pattern(s) updated. ${compositionsResult + compositionPatternsResult + componentPatternsResult} instance(s) added.`
|
|
1389
1405
|
);
|
|
1390
1406
|
return {
|
|
1391
1407
|
allowedComponentsUpdated,
|
|
@@ -1436,7 +1452,7 @@ var ComponentAdderService = class {
|
|
|
1436
1452
|
}
|
|
1437
1453
|
return raw;
|
|
1438
1454
|
}
|
|
1439
|
-
async addComponentToDirectory(directory,
|
|
1455
|
+
async addComponentToDirectory(directory, parentTypes, slot, newInstance, whatIf, strict, dirType) {
|
|
1440
1456
|
const exists = await this.fileSystem.fileExists(directory);
|
|
1441
1457
|
if (!exists) {
|
|
1442
1458
|
this.logger.detail(`${dirType} directory does not exist, skipping`);
|
|
@@ -1469,7 +1485,7 @@ var ComponentAdderService = class {
|
|
|
1469
1485
|
}
|
|
1470
1486
|
const rootInstance = composition.composition;
|
|
1471
1487
|
let modified = false;
|
|
1472
|
-
if (this.
|
|
1488
|
+
if (this.matchesAnyParentType(rootInstance.type, parentTypes, strict)) {
|
|
1473
1489
|
if (!rootInstance.slots) {
|
|
1474
1490
|
rootInstance.slots = {};
|
|
1475
1491
|
}
|
|
@@ -1481,7 +1497,7 @@ var ComponentAdderService = class {
|
|
|
1481
1497
|
if (rootInstance.slots) {
|
|
1482
1498
|
const nestedModified = this.addComponentToNestedSlots(
|
|
1483
1499
|
rootInstance.slots,
|
|
1484
|
-
|
|
1500
|
+
parentTypes,
|
|
1485
1501
|
slot,
|
|
1486
1502
|
newInstance,
|
|
1487
1503
|
strict
|
|
@@ -1515,12 +1531,12 @@ var ComponentAdderService = class {
|
|
|
1515
1531
|
}
|
|
1516
1532
|
return filesModified;
|
|
1517
1533
|
}
|
|
1518
|
-
addComponentToNestedSlots(slots,
|
|
1534
|
+
addComponentToNestedSlots(slots, parentTypes, slot, newInstance, strict) {
|
|
1519
1535
|
let modified = false;
|
|
1520
1536
|
for (const slotInstances of Object.values(slots)) {
|
|
1521
1537
|
if (!Array.isArray(slotInstances)) continue;
|
|
1522
1538
|
for (const instance of slotInstances) {
|
|
1523
|
-
if (this.
|
|
1539
|
+
if (this.matchesAnyParentType(instance.type, parentTypes, strict)) {
|
|
1524
1540
|
if (!instance.slots) {
|
|
1525
1541
|
instance.slots = {};
|
|
1526
1542
|
}
|
|
@@ -1532,7 +1548,7 @@ var ComponentAdderService = class {
|
|
|
1532
1548
|
if (instance.slots) {
|
|
1533
1549
|
const nestedModified = this.addComponentToNestedSlots(
|
|
1534
1550
|
instance.slots,
|
|
1535
|
-
|
|
1551
|
+
parentTypes,
|
|
1536
1552
|
slot,
|
|
1537
1553
|
newInstance,
|
|
1538
1554
|
strict
|