adobe / helix-importer-ui

Apache License 2.0
21 stars 27 forks source link

Express Importing using import JSON #355

Open arumsey opened 5 months ago

arumsey commented 5 months ago

Introduce a higher-level Importer API that provides a declarative approach to transformations

Transformer Class

export default class Transformer {
  static transform(rules, source) {
    const {
      root,
      cleanup: {
        start: removeStart = [],
        end: removeEnd = [],
      },
      blocks = [],
    } = rules;

    // phase 1: get main element
    // phase 2: DOM removal - start
    // phase 3: block creation
    // phase 4: DOM removal - end

    return main;
  }

  /**
   * Build a name/value pair block configuration from a selector object.
   *
   * Selector Object:
   * {
   *   name: value_selector | [condition_selector, value_selector]
   * }
   *
   *
   * @param element Root element to query from
   * @param params Object of selector conditions
   */
  static buildBlockConfig(element, params) {}

  /**
   * Build a two-dimensional array of block cells from a selector object.
   * @param element
   * @param cells
   */
  static buildBlockCells(element, cells) {}

}

Importer Factory

const createImporter = (rules) => ({
  transform: (source) => {
    const element = WebImporter.Transformer.transform(rules, source);
    return [{
      element,
      path: generateDocumentPath(source),
    }];
  },
});
kptdobe commented 5 months ago

Who is using / requesting this ? What is the context ?

arumsey commented 5 months ago

Who is using / requesting this ? What is the context ?

The Import as a Service team/project is requesting this feature.

Adding a declarative API on top of the existing import.js feature will enable less technical users to participate in the import of a site. In addition, the proposed JSON configuration structure will also be used by the import service that is being devleoped so that custom code will not need to be executed on the server.

The feature being proposed is fully backwards compatible with the existing AEM Importer features. This means all existing import scripts will still work. The new abstraction layer being proposed will be built on top of the transformation file API. The responsibility of the transformation factory is to create a valid transformation object from the JSON configuration. Additionally, a developer creating an import script could even consume the declarative API if they want to simplify the work they need to do when writing a custom import script.

Finally, the introduction of a JSON configuration object will make it easier to be machine generated from a blueprint detection UI as well as AI prompts.

kptdobe commented 5 months ago

Ok, thanks for the details. Once you have a first draft version, we would need several projects using the declarative approach instead of the current approach. Also, it would be required to get adoption from the project leads or from non-technical users (as this is the target audience).