@uniformdev/transformer 1.1.1 → 1.1.3
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 +34 -32
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +32 -28
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -119,7 +119,6 @@ interface AddComponentPatternOptions extends GlobalOptions {
|
|
|
119
119
|
parentComponentType: string;
|
|
120
120
|
slot: string;
|
|
121
121
|
componentPatternId: string;
|
|
122
|
-
parameters?: string;
|
|
123
122
|
}
|
|
124
123
|
interface PropagateRootComponentSlotOptions extends GlobalOptions {
|
|
125
124
|
compositionType: string;
|
|
@@ -369,13 +368,13 @@ declare class ComponentAdderService {
|
|
|
369
368
|
private compareIds;
|
|
370
369
|
private parseParameters;
|
|
371
370
|
private generateId;
|
|
372
|
-
private cloneComponentInstance;
|
|
373
371
|
private regenerateInstanceIds;
|
|
374
372
|
private createComponentInstance;
|
|
375
373
|
private addComponentToSlot;
|
|
376
374
|
addComponent(options: AddComponentInternalOptions): Promise<AddComponentResult>;
|
|
377
|
-
addComponentPattern(options: AddComponentInternalOptions): Promise<AddComponentResult>;
|
|
375
|
+
addComponentPattern(options: Omit<AddComponentInternalOptions, 'parameters'>): Promise<AddComponentResult>;
|
|
378
376
|
private loadComponentPattern;
|
|
377
|
+
private normalizeComponentPattern;
|
|
379
378
|
private addComponentToDirectory;
|
|
380
379
|
private addComponentToNestedSlots;
|
|
381
380
|
}
|
package/dist/index.js
CHANGED
|
@@ -1129,25 +1129,9 @@ var ComponentAdderService = class {
|
|
|
1129
1129
|
generateId(baseName) {
|
|
1130
1130
|
return `${baseName}-${randomUUID().slice(0, 8)}`;
|
|
1131
1131
|
}
|
|
1132
|
-
cloneComponentInstance(instance) {
|
|
1133
|
-
const clone = JSON.parse(JSON.stringify(instance));
|
|
1134
|
-
if (clone._id) {
|
|
1135
|
-
clone._id = this.generateId(clone.type);
|
|
1136
|
-
}
|
|
1137
|
-
if (clone.slots) {
|
|
1138
|
-
for (const slotInstances of Object.values(clone.slots)) {
|
|
1139
|
-
if (Array.isArray(slotInstances)) {
|
|
1140
|
-
for (const nestedInstance of slotInstances) {
|
|
1141
|
-
this.regenerateInstanceIds(nestedInstance);
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
return clone;
|
|
1147
|
-
}
|
|
1148
1132
|
regenerateInstanceIds(instance) {
|
|
1149
1133
|
if (instance._id) {
|
|
1150
|
-
instance._id = this.generateId(instance.type);
|
|
1134
|
+
instance._id = instance._pattern ? randomUUID() : this.generateId(instance.type);
|
|
1151
1135
|
}
|
|
1152
1136
|
if (instance.slots) {
|
|
1153
1137
|
for (const slotInstances of Object.values(instance.slots)) {
|
|
@@ -1367,7 +1351,11 @@ var ComponentAdderService = class {
|
|
|
1367
1351
|
allowedComponentsUpdated = true;
|
|
1368
1352
|
}
|
|
1369
1353
|
}
|
|
1370
|
-
const newInstance =
|
|
1354
|
+
const newInstance = {
|
|
1355
|
+
type: componentTypeInPattern,
|
|
1356
|
+
_pattern: pattern.componentPatternId,
|
|
1357
|
+
_id: randomUUID()
|
|
1358
|
+
};
|
|
1371
1359
|
const compositionsResult = await this.addComponentToDirectory(
|
|
1372
1360
|
fullCompositionsDir,
|
|
1373
1361
|
parentComponentType,
|
|
@@ -1411,26 +1399,42 @@ var ComponentAdderService = class {
|
|
|
1411
1399
|
const jsonPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.json`);
|
|
1412
1400
|
const yamlPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.yaml`);
|
|
1413
1401
|
const ymlPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.yml`);
|
|
1402
|
+
let raw;
|
|
1414
1403
|
if (await this.fileSystem.fileExists(jsonPath)) {
|
|
1415
|
-
|
|
1404
|
+
raw = await this.fileSystem.readFile(jsonPath);
|
|
1405
|
+
} else if (await this.fileSystem.fileExists(yamlPath)) {
|
|
1406
|
+
raw = await this.fileSystem.readFile(yamlPath);
|
|
1407
|
+
} else if (await this.fileSystem.fileExists(ymlPath)) {
|
|
1408
|
+
raw = await this.fileSystem.readFile(ymlPath);
|
|
1416
1409
|
}
|
|
1417
|
-
if (
|
|
1418
|
-
return this.fileSystem.readFile(yamlPath);
|
|
1419
|
-
}
|
|
1420
|
-
if (await this.fileSystem.fileExists(ymlPath)) {
|
|
1421
|
-
return this.fileSystem.readFile(ymlPath);
|
|
1422
|
-
}
|
|
1423
|
-
if (!strict) {
|
|
1410
|
+
if (!raw && !strict) {
|
|
1424
1411
|
const files = await this.fileSystem.findFiles(componentPatternsDir, "*.{json,yaml,yml}");
|
|
1425
1412
|
for (const filePath of files) {
|
|
1426
1413
|
const basename2 = this.fileSystem.getBasename(filePath);
|
|
1427
1414
|
const nameWithoutExt = basename2.replace(/\.(json|yaml|yml)$/i, "");
|
|
1428
1415
|
if (nameWithoutExt.toLowerCase() === patternId.toLowerCase()) {
|
|
1429
|
-
|
|
1416
|
+
raw = await this.fileSystem.readFile(filePath);
|
|
1417
|
+
break;
|
|
1430
1418
|
}
|
|
1431
1419
|
}
|
|
1432
1420
|
}
|
|
1433
|
-
|
|
1421
|
+
if (!raw) {
|
|
1422
|
+
throw new TransformError(`Component pattern "${patternId}" not found in ${componentPatternsDir}`);
|
|
1423
|
+
}
|
|
1424
|
+
return this.normalizeComponentPattern(raw, patternId);
|
|
1425
|
+
}
|
|
1426
|
+
normalizeComponentPattern(raw, patternId) {
|
|
1427
|
+
if (raw.definition && typeof raw.definition === "object" && raw.definition.type) {
|
|
1428
|
+
return raw;
|
|
1429
|
+
}
|
|
1430
|
+
if (raw.composition && typeof raw.composition === "object" && raw.composition.type) {
|
|
1431
|
+
const composition = raw.composition;
|
|
1432
|
+
return {
|
|
1433
|
+
componentPatternId: patternId,
|
|
1434
|
+
definition: composition
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
return raw;
|
|
1434
1438
|
}
|
|
1435
1439
|
async addComponentToDirectory(directory, parentComponentType, slot, newInstance, whatIf, strict, dirType) {
|
|
1436
1440
|
const exists = await this.fileSystem.fileExists(directory);
|