enonic-content-type-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Enonic XP Content Type Generator

Enonic XP内容类型生成器

Procedures

操作流程

Step 1: Detect Enonic XP Project
  1. Execute
    node scripts/find-enonic-targets.mjs [workspaceRoot]
    to locate Enonic XP project roots.
  2. If the script returns an empty array, warn that no Enonic XP project markers were found and ask for the target directory.
  3. Store the detected project root for use in subsequent steps.
Step 2: Gather Requirements
  1. Identify the content type name from the request. The name must be lowercase-hyphenated (e.g.,
    blog-post
    ).
  2. Identify the display name — a human-readable label (e.g.,
    Blog Post
    ).
  3. Determine the super-type. Default to
    base:structured
    unless the request specifies a folder (
    base:folder
    ) or another built-in type.
  4. List all requested fields with their input types. Read
    references/content-type-reference.md
    to map natural-language field descriptions to the correct Enonic XP input type and configuration.
  5. Identify any item sets (repeatable grouped fields), option sets (single-select or multi-select choices), or mixin references.
  6. If the request mentions a mixin, determine whether to generate the mixin file or reference an existing one.
  7. If the request mentions x-data, determine whether to generate the x-data file or reference an existing one.
Step 3: Generate the Content Type XML
  1. Read
    assets/content-type.template.xml
    to obtain the starter template.
  2. Replace
    DISPLAY_NAME
    with the display name from Step 2.
  3. Replace
    DESCRIPTION
    with a short description or remove the element if none was provided.
  4. Set the
    <super-type>
    element to the value determined in Step 2.
  5. Populate the
    <form>
    element with the identified inputs, item sets, option sets, field sets, and mixin references.
  6. For each input:
    • Set the
      name
      attribute using camelCase.
    • Set the
      type
      attribute to the exact Enonic XP input type name (case-sensitive).
    • Add
      <label>
      ,
      <occurrences>
      ,
      <help-text>
      ,
      <default>
      , and
      <config>
      as required.
  7. For ComboBox and RadioButton inputs, include all options inside
    <config>
    .
  8. For ContentSelector and ImageSelector inputs, include
    <config>
    with
    allowContentType
    and
    allowPath
    if specified.
  9. If examples are needed for reference, read
    references/examples.md
    .
Step 4: Write the File
  1. Construct the target path:
    [projectRoot]/src/main/resources/site/content-types/[name]/[name].xml
  2. Create the directory if it does not exist.
  3. Write the generated XML to the file.
  4. If a mixin was generated, write it to:
    [projectRoot]/src/main/resources/site/mixins/[name]/[name].xml
  5. If x-data was generated, write it to:
    [projectRoot]/src/main/resources/site/x-data/[name]/[name].xml
Step 5: Validate Output
  1. Verify the generated XML is well-formed.
  2. Confirm every
    <input>
    has a valid
    type
    attribute by cross-referencing
    references/content-type-reference.md
    .
  3. Confirm all
    name
    attributes are unique within their nesting level.
  4. Confirm
    <occurrences>
    values are logically consistent (minimum <= maximum, or maximum = 0 for unlimited).
  5. If the request asks about super-types, input types, or schema structure without requesting file generation, answer the question using
    references/content-type-reference.md
    without creating files.
步骤1:检测Enonic XP项目
  1. 执行
    node scripts/find-enonic-targets.mjs [workspaceRoot]
    定位Enonic XP项目根目录。
  2. 若脚本返回空数组,提示未找到Enonic XP项目标记,并询问目标目录路径。
  3. 存储检测到的项目根目录,供后续步骤使用。
步骤2:收集需求
  1. 从请求中确定内容类型名称,名称必须采用小写连字符格式(例如
    blog-post
    )。
  2. 确定显示名称:即人类可读的标签(例如
    Blog Post
    )。
  3. 确定超类型:除非请求指定文件夹(
    base:folder
    )或其他内置类型,否则默认使用
    base:structured
  4. 列出所有请求的字段及其对应的输入类型,读取
    references/content-type-reference.md
    将自然语言的字段描述映射为正确的Enonic XP输入类型和配置。
  5. 识别所有条目集(可重复的分组字段)、选项集(单选或多选选项)或mixin引用。
  6. 若请求中提到mixin,确定是生成新的mixin文件还是引用现有文件。
  7. 若请求中提到x-data,确定是生成新的x-data文件还是引用现有文件。
步骤3:生成内容类型XML
  1. 读取
    assets/content-type.template.xml
    获取初始模板。
  2. DISPLAY_NAME
    替换为步骤2中得到的显示名称。
  3. DESCRIPTION
    替换为简短描述,若无提供描述则移除该元素。
  4. <super-type>
    元素设置为步骤2中确定的值。
  5. <form>
    元素填充识别到的输入项、条目集、选项集、字段集和mixin引用。
  6. 针对每个输入项:
    • 使用驼峰命名法设置
      name
      属性。
    • type
      属性设置为准确的Enonic XP输入类型名称(区分大小写)。
    • 按需添加
      <label>
      <occurrences>
      <help-text>
      <default>
      <config>
      标签。
  7. 针对ComboBox和RadioButton输入项,在
    <config>
    中包含所有可选选项。
  8. 针对ContentSelector和ImageSelector输入项,若有指定则在
    <config>
    中添加
    allowContentType
    allowPath
    配置。
  9. 若需要参考示例,可读取
    references/examples.md
步骤4:写入文件
  1. 构造目标路径:
    [projectRoot]/src/main/resources/site/content-types/[name]/[name].xml
  2. 若目录不存在则创建对应目录。
  3. 将生成的XML写入目标文件。
  4. 若生成了mixin,将其写入路径:
    [projectRoot]/src/main/resources/site/mixins/[name]/[name].xml
  5. 若生成了x-data,将其写入路径:
    [projectRoot]/src/main/resources/site/x-data/[name]/[name].xml
步骤5:验证输出
  1. 校验生成的XML格式是否规范。
  2. 对照
    references/content-type-reference.md
    确认每个
    <input>
    标签的
    type
    属性均有效。
  3. 确认所有
    name
    属性在其嵌套层级下唯一。
  4. 确认
    <occurrences>
    的值逻辑一致(最小值 ≤ 最大值,或最大值为0代表无限制)。
  5. 若请求仅询问超类型、输入类型或模式结构,不需要生成文件,则参考
    references/content-type-reference.md
    回答问题即可,无需创建文件。

Error Handling

错误处理

  • If
    scripts/find-enonic-targets.mjs
    exits with a non-zero code, report the stderr message and ask for the project root path manually.
  • If the requested input type does not match any known Enonic XP input type, read
    references/content-type-reference.md
    and suggest the closest match. Do not invent input type names.
  • If XML validation fails, read
    references/troubleshooting.md
    to diagnose and correct the error, then regenerate the file.
  • If a mixin reference cannot be resolved, confirm the mixin file path exists before writing the content type.
  • scripts/find-enonic-targets.mjs
    执行返回非0状态码,上报stderr输出的错误信息,并手动询问项目根路径。
  • 若请求的输入类型无匹配的已知Enonic XP输入类型,读取
    references/content-type-reference.md
    并给出最接近的匹配建议,请勿自行编造输入类型名称。
  • 若XML验证失败,读取
    references/troubleshooting.md
    诊断并修正错误后重新生成文件。
  • 若无法解析mixin引用,写入内容类型文件前先确认mixin文件路径存在。