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