@uniformdev/transformer 1.1.0 → 1.1.2
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 +40 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +40 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -376,6 +376,7 @@ declare class ComponentAdderService {
|
|
|
376
376
|
addComponent(options: AddComponentInternalOptions): Promise<AddComponentResult>;
|
|
377
377
|
addComponentPattern(options: AddComponentInternalOptions): Promise<AddComponentResult>;
|
|
378
378
|
private loadComponentPattern;
|
|
379
|
+
private normalizeComponentPattern;
|
|
379
380
|
private addComponentToDirectory;
|
|
380
381
|
private addComponentToNestedSlots;
|
|
381
382
|
}
|
package/dist/index.js
CHANGED
|
@@ -1205,11 +1205,16 @@ var ComponentAdderService = class {
|
|
|
1205
1205
|
const findOptions = { strict };
|
|
1206
1206
|
this.logger.info(`Loading parent component: ${parentComponentType}`);
|
|
1207
1207
|
const { component: parentComponent, filePath: parentComponentFilePath } = await this.componentService.loadComponent(fullComponentsDir, parentComponentType, findOptions);
|
|
1208
|
-
|
|
1208
|
+
if (!parentComponent.slots) {
|
|
1209
|
+
parentComponent.slots = [];
|
|
1210
|
+
}
|
|
1211
|
+
let slotDef = parentComponent.slots.find(
|
|
1209
1212
|
(s) => this.compareIds(s.id, slot, strict)
|
|
1210
1213
|
);
|
|
1211
1214
|
if (!slotDef) {
|
|
1212
|
-
|
|
1215
|
+
this.logger.info(`Slot "${slot}" not found on component "${parentComponentType}", creating it`);
|
|
1216
|
+
slotDef = { id: slot, name: slot, allowedComponents: [] };
|
|
1217
|
+
parentComponent.slots.push(slotDef);
|
|
1213
1218
|
}
|
|
1214
1219
|
this.logger.info(`Validating new component: ${newComponentType}`);
|
|
1215
1220
|
try {
|
|
@@ -1311,11 +1316,16 @@ var ComponentAdderService = class {
|
|
|
1311
1316
|
const findOptions = { strict };
|
|
1312
1317
|
this.logger.info(`Loading parent component: ${parentComponentType}`);
|
|
1313
1318
|
const { component: parentComponent } = await this.componentService.loadComponent(fullComponentsDir, parentComponentType, findOptions);
|
|
1314
|
-
|
|
1319
|
+
if (!parentComponent.slots) {
|
|
1320
|
+
parentComponent.slots = [];
|
|
1321
|
+
}
|
|
1322
|
+
let slotDef = parentComponent.slots.find(
|
|
1315
1323
|
(s) => this.compareIds(s.id, slot, strict)
|
|
1316
1324
|
);
|
|
1317
1325
|
if (!slotDef) {
|
|
1318
|
-
|
|
1326
|
+
this.logger.info(`Slot "${slot}" not found on component "${parentComponentType}", creating it`);
|
|
1327
|
+
slotDef = { id: slot, name: slot, allowedComponents: [] };
|
|
1328
|
+
parentComponent.slots.push(slotDef);
|
|
1319
1329
|
}
|
|
1320
1330
|
this.logger.info(`Loading component pattern: ${componentPatternId}`);
|
|
1321
1331
|
const pattern = await this.loadComponentPattern(
|
|
@@ -1401,26 +1411,42 @@ var ComponentAdderService = class {
|
|
|
1401
1411
|
const jsonPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.json`);
|
|
1402
1412
|
const yamlPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.yaml`);
|
|
1403
1413
|
const ymlPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.yml`);
|
|
1414
|
+
let raw;
|
|
1404
1415
|
if (await this.fileSystem.fileExists(jsonPath)) {
|
|
1405
|
-
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
if (await this.fileSystem.fileExists(ymlPath)) {
|
|
1411
|
-
return this.fileSystem.readFile(ymlPath);
|
|
1416
|
+
raw = await this.fileSystem.readFile(jsonPath);
|
|
1417
|
+
} else if (await this.fileSystem.fileExists(yamlPath)) {
|
|
1418
|
+
raw = await this.fileSystem.readFile(yamlPath);
|
|
1419
|
+
} else if (await this.fileSystem.fileExists(ymlPath)) {
|
|
1420
|
+
raw = await this.fileSystem.readFile(ymlPath);
|
|
1412
1421
|
}
|
|
1413
|
-
if (!strict) {
|
|
1422
|
+
if (!raw && !strict) {
|
|
1414
1423
|
const files = await this.fileSystem.findFiles(componentPatternsDir, "*.{json,yaml,yml}");
|
|
1415
1424
|
for (const filePath of files) {
|
|
1416
1425
|
const basename2 = this.fileSystem.getBasename(filePath);
|
|
1417
1426
|
const nameWithoutExt = basename2.replace(/\.(json|yaml|yml)$/i, "");
|
|
1418
1427
|
if (nameWithoutExt.toLowerCase() === patternId.toLowerCase()) {
|
|
1419
|
-
|
|
1428
|
+
raw = await this.fileSystem.readFile(filePath);
|
|
1429
|
+
break;
|
|
1420
1430
|
}
|
|
1421
1431
|
}
|
|
1422
1432
|
}
|
|
1423
|
-
|
|
1433
|
+
if (!raw) {
|
|
1434
|
+
throw new TransformError(`Component pattern "${patternId}" not found in ${componentPatternsDir}`);
|
|
1435
|
+
}
|
|
1436
|
+
return this.normalizeComponentPattern(raw, patternId);
|
|
1437
|
+
}
|
|
1438
|
+
normalizeComponentPattern(raw, patternId) {
|
|
1439
|
+
if (raw.definition && typeof raw.definition === "object" && raw.definition.type) {
|
|
1440
|
+
return raw;
|
|
1441
|
+
}
|
|
1442
|
+
if (raw.composition && typeof raw.composition === "object" && raw.composition.type) {
|
|
1443
|
+
const composition = raw.composition;
|
|
1444
|
+
return {
|
|
1445
|
+
componentPatternId: patternId,
|
|
1446
|
+
definition: composition
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
return raw;
|
|
1424
1450
|
}
|
|
1425
1451
|
async addComponentToDirectory(directory, parentComponentType, slot, newInstance, whatIf, strict, dirType) {
|
|
1426
1452
|
const exists = await this.fileSystem.fileExists(directory);
|