@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/cli/index.js
CHANGED
|
@@ -2513,11 +2513,16 @@ var ComponentAdderService = class {
|
|
|
2513
2513
|
const findOptions = { strict };
|
|
2514
2514
|
this.logger.info(`Loading parent component: ${parentComponentType}`);
|
|
2515
2515
|
const { component: parentComponent, filePath: parentComponentFilePath } = await this.componentService.loadComponent(fullComponentsDir, parentComponentType, findOptions);
|
|
2516
|
-
|
|
2516
|
+
if (!parentComponent.slots) {
|
|
2517
|
+
parentComponent.slots = [];
|
|
2518
|
+
}
|
|
2519
|
+
let slotDef = parentComponent.slots.find(
|
|
2517
2520
|
(s) => this.compareIds(s.id, slot, strict)
|
|
2518
2521
|
);
|
|
2519
2522
|
if (!slotDef) {
|
|
2520
|
-
|
|
2523
|
+
this.logger.info(`Slot "${slot}" not found on component "${parentComponentType}", creating it`);
|
|
2524
|
+
slotDef = { id: slot, name: slot, allowedComponents: [] };
|
|
2525
|
+
parentComponent.slots.push(slotDef);
|
|
2521
2526
|
}
|
|
2522
2527
|
this.logger.info(`Validating new component: ${newComponentType}`);
|
|
2523
2528
|
try {
|
|
@@ -2619,11 +2624,16 @@ var ComponentAdderService = class {
|
|
|
2619
2624
|
const findOptions = { strict };
|
|
2620
2625
|
this.logger.info(`Loading parent component: ${parentComponentType}`);
|
|
2621
2626
|
const { component: parentComponent } = await this.componentService.loadComponent(fullComponentsDir, parentComponentType, findOptions);
|
|
2622
|
-
|
|
2627
|
+
if (!parentComponent.slots) {
|
|
2628
|
+
parentComponent.slots = [];
|
|
2629
|
+
}
|
|
2630
|
+
let slotDef = parentComponent.slots.find(
|
|
2623
2631
|
(s) => this.compareIds(s.id, slot, strict)
|
|
2624
2632
|
);
|
|
2625
2633
|
if (!slotDef) {
|
|
2626
|
-
|
|
2634
|
+
this.logger.info(`Slot "${slot}" not found on component "${parentComponentType}", creating it`);
|
|
2635
|
+
slotDef = { id: slot, name: slot, allowedComponents: [] };
|
|
2636
|
+
parentComponent.slots.push(slotDef);
|
|
2627
2637
|
}
|
|
2628
2638
|
this.logger.info(`Loading component pattern: ${componentPatternId}`);
|
|
2629
2639
|
const pattern = await this.loadComponentPattern(
|
|
@@ -2709,26 +2719,42 @@ var ComponentAdderService = class {
|
|
|
2709
2719
|
const jsonPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.json`);
|
|
2710
2720
|
const yamlPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.yaml`);
|
|
2711
2721
|
const ymlPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.yml`);
|
|
2722
|
+
let raw;
|
|
2712
2723
|
if (await this.fileSystem.fileExists(jsonPath)) {
|
|
2713
|
-
|
|
2714
|
-
}
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
if (await this.fileSystem.fileExists(ymlPath)) {
|
|
2719
|
-
return this.fileSystem.readFile(ymlPath);
|
|
2724
|
+
raw = await this.fileSystem.readFile(jsonPath);
|
|
2725
|
+
} else if (await this.fileSystem.fileExists(yamlPath)) {
|
|
2726
|
+
raw = await this.fileSystem.readFile(yamlPath);
|
|
2727
|
+
} else if (await this.fileSystem.fileExists(ymlPath)) {
|
|
2728
|
+
raw = await this.fileSystem.readFile(ymlPath);
|
|
2720
2729
|
}
|
|
2721
|
-
if (!strict) {
|
|
2730
|
+
if (!raw && !strict) {
|
|
2722
2731
|
const files = await this.fileSystem.findFiles(componentPatternsDir, "*.{json,yaml,yml}");
|
|
2723
2732
|
for (const filePath of files) {
|
|
2724
2733
|
const basename2 = this.fileSystem.getBasename(filePath);
|
|
2725
2734
|
const nameWithoutExt = basename2.replace(/\.(json|yaml|yml)$/i, "");
|
|
2726
2735
|
if (nameWithoutExt.toLowerCase() === patternId.toLowerCase()) {
|
|
2727
|
-
|
|
2736
|
+
raw = await this.fileSystem.readFile(filePath);
|
|
2737
|
+
break;
|
|
2728
2738
|
}
|
|
2729
2739
|
}
|
|
2730
2740
|
}
|
|
2731
|
-
|
|
2741
|
+
if (!raw) {
|
|
2742
|
+
throw new TransformError(`Component pattern "${patternId}" not found in ${componentPatternsDir}`);
|
|
2743
|
+
}
|
|
2744
|
+
return this.normalizeComponentPattern(raw, patternId);
|
|
2745
|
+
}
|
|
2746
|
+
normalizeComponentPattern(raw, patternId) {
|
|
2747
|
+
if (raw.definition && typeof raw.definition === "object" && raw.definition.type) {
|
|
2748
|
+
return raw;
|
|
2749
|
+
}
|
|
2750
|
+
if (raw.composition && typeof raw.composition === "object" && raw.composition.type) {
|
|
2751
|
+
const composition = raw.composition;
|
|
2752
|
+
return {
|
|
2753
|
+
componentPatternId: patternId,
|
|
2754
|
+
definition: composition
|
|
2755
|
+
};
|
|
2756
|
+
}
|
|
2757
|
+
return raw;
|
|
2732
2758
|
}
|
|
2733
2759
|
async addComponentToDirectory(directory, parentComponentType, slot, newInstance, whatIf, strict, dirType) {
|
|
2734
2760
|
const exists = await this.fileSystem.fileExists(directory);
|