@uniformdev/transformer 1.1.1 → 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 CHANGED
@@ -2719,26 +2719,42 @@ var ComponentAdderService = class {
2719
2719
  const jsonPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.json`);
2720
2720
  const yamlPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.yaml`);
2721
2721
  const ymlPath = this.fileSystem.joinPath(componentPatternsDir, `${patternId}.yml`);
2722
+ let raw;
2722
2723
  if (await this.fileSystem.fileExists(jsonPath)) {
2723
- return this.fileSystem.readFile(jsonPath);
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);
2724
2729
  }
2725
- if (await this.fileSystem.fileExists(yamlPath)) {
2726
- return this.fileSystem.readFile(yamlPath);
2727
- }
2728
- if (await this.fileSystem.fileExists(ymlPath)) {
2729
- return this.fileSystem.readFile(ymlPath);
2730
- }
2731
- if (!strict) {
2730
+ if (!raw && !strict) {
2732
2731
  const files = await this.fileSystem.findFiles(componentPatternsDir, "*.{json,yaml,yml}");
2733
2732
  for (const filePath of files) {
2734
2733
  const basename2 = this.fileSystem.getBasename(filePath);
2735
2734
  const nameWithoutExt = basename2.replace(/\.(json|yaml|yml)$/i, "");
2736
2735
  if (nameWithoutExt.toLowerCase() === patternId.toLowerCase()) {
2737
- return this.fileSystem.readFile(filePath);
2736
+ raw = await this.fileSystem.readFile(filePath);
2737
+ break;
2738
2738
  }
2739
2739
  }
2740
2740
  }
2741
- throw new TransformError(`Component pattern "${patternId}" not found in ${componentPatternsDir}`);
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;
2742
2758
  }
2743
2759
  async addComponentToDirectory(directory, parentComponentType, slot, newInstance, whatIf, strict, dirType) {
2744
2760
  const exists = await this.fileSystem.fileExists(directory);