datocms-plugin-scaffold

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

DatoCMS Plugin Scaffold

DatoCMS 插件脚手架

Create the smallest working first version of a new plugin project. Keep the initial scaffold narrow, then hand later incremental edits to
datocms-plugin-builder
.
创建新插件项目的最小可用初始版本。保持初始脚手架的范围精简,后续的增量编辑交由
datocms-plugin-builder
处理。

Step 1: Confirm scaffold mode

步骤1:确认脚手架模式

Silently inspect the current directory.
  1. Check for an existing plugin project (
    package.json
    with
    datocms-plugin-sdk
    , a
    connect()
    entrypoint, and Vite config).
  2. If a plugin already exists and the request is an edit, switch to
    datocms-plugin-builder
    .
  3. Infer the likely starting surface from the request before asking questions.
静默检查当前目录。
  1. 检查是否存在现有插件项目(包含
    datocms-plugin-sdk
    package.json
    connect()
    入口文件以及 Vite 配置)。
  2. 若已存在插件且请求为编辑操作,则切换至
    datocms-plugin-builder
  3. 在提问前,从请求中推断可能的初始界面类型。

Step 2: Ask only for missing essentials

步骤2:仅询问缺失的必要信息

Ask only when the request or repo does not already answer them:
  • plugin name or folder name
  • private vs marketplace distribution
  • initial surface and target model or field scope when that changes the scaffold
  • whether the plugin needs
    currentUserAccessToken
    or other external API access
Skip the question round if those points are already clear enough to scaffold safely.
仅当请求或仓库未明确以下信息时才提问:
  • 插件名称或文件夹名称
  • 私有分发还是市场分发
  • 初始界面以及目标模型或字段范围(若会影响脚手架结构)
  • 插件是否需要
    currentUserAccessToken
    或其他外部 API 访问权限
若上述信息已足够明确可安全搭建脚手架,则跳过提问环节。

Step 3: Load the small reference set

步骤3:加载小型参考集

Always load:
  • references/project-scaffold.md
  • references/surface-starters.md
Stay with these files for the first implementation. Route later feature expansion or maintenance work to
datocms-plugin-builder
.
始终加载以下文件:
  • references/project-scaffold.md
  • references/surface-starters.md
首次实现仅依赖这些文件。后续的功能扩展或维护工作交由
datocms-plugin-builder
处理。

Step 4: Scaffold the project

步骤4:搭建项目

  • Create the plugin directory inside the current working directory.
  • Use the standard Vite/React layout from
    references/project-scaffold.md
    .
  • Add only the entrypoints the requested surfaces need.
  • Keep package metadata minimal for private plugins.
  • For marketplace plugins, set the npm package name, keywords, homepage, and permissions correctly.
  • Add only the optional dependencies required by the first implementation.
  • Install dependencies before verification.
  • 在当前工作目录内创建插件目录。
  • 使用
    references/project-scaffold.md
    中的标准 Vite/React 布局。
  • 仅添加所需界面对应的入口文件。
  • 私有插件的包元数据保持极简。
  • 针对市场插件,正确设置 npm 包名称、关键词、主页和权限。
  • 仅添加首次实现所需的可选依赖。
  • 在验证前安装依赖。

Step 5: Wire the first surface

步骤5:对接第一个界面

Use
references/surface-starters.md
to choose the declaration, render, and execute hooks.
Keep these starter guardrails:
  • Keep exactly one top-level
    connect()
    call.
  • Wrap rendered UI in
    <Canvas ctx={ctx}>
    ; use
    noAutoResizer
    for pages, inspectors, and full-width sidebars.
  • Use
    switch
    for ID-dispatched render hooks.
  • Use
    import type { ... }
    for SDK types.
  • Keep
    ctx.openModal()
    parameters and
    ctx.resolve()
    values JSON-serializable.
  • Do not create editor field extensions for modular content, single block, or structured text fields.
  • Stop at the smallest working first version. Do not pre-build extra surfaces or settings the user did not ask for.
使用
references/surface-starters.md
选择声明、渲染和执行钩子。
遵循以下初始约束:
  • 仅保留一个顶层
    connect()
    调用。
  • 将渲染的 UI 包裹在
    <Canvas ctx={ctx}>
    中;页面、检查器和全宽侧边栏需使用
    noAutoResizer
  • 使用
    switch
    语句处理基于 ID 分发的渲染钩子。
  • 使用
    import type { ... }
    导入 SDK 类型。
  • 确保
    ctx.openModal()
    参数和
    ctx.resolve()
    的值可序列化为 JSON。
  • 不要为模块化内容、单个区块或结构化文本字段创建编辑器字段扩展。
  • 止步于最小可用初始版本,不要预构建用户未要求的额外界面或设置。

Step 6: Verify

步骤6:验证

  1. Install dependencies with the selected package manager.
  2. Run the build script with that same package manager.
  3. Tell the user which dev command to run with that package manager.
  4. Tell the user how to install the local plugin in DatoCMS and name the single manual surface check that matters most.
  1. 使用选定的包管理器安装依赖。
  2. 使用同一包管理器运行构建脚本。
  3. 告知用户使用该包管理器运行的开发命令。
  4. 告知用户如何在 DatoCMS 中安装本地插件,并说明最重要的单个手动界面检查项。

Cross-skill routing

跨技能路由

  • Existing plugin maintenance ->
    datocms-plugin-builder
  • Native DatoCMS plugin UI design, layout restyling, or design-system alignment ->
    datocms-plugin-design-system
  • Standalone CMA scripts or schema work outside the plugin iframe ->
    datocms-cma
  • 现有插件维护 ->
    datocms-plugin-builder
  • 原生 DatoCMS 插件 UI 设计、布局重定义或设计系统对齐 ->
    datocms-plugin-design-system
  • 插件 iframe 外的独立 CMA 脚本或架构工作 ->
    datocms-cma