For AI agents: the complete documentation index is available at /en/llms.txt, the full documentation bundle is available at /en/llms-full.txt, and this page is available as Markdown at /en/reference/sdk/node/config/functions/ensureJson.md.
  • English
  • Function: ensureJson()

    function ensureJson<T>(filePath: string, seed?: T): T;

    Defined in: node/config/index.ts:441

    确保 JSON 文件存在。

    • 存在 → 不动,返回现有内容(或 fallback)
    • 不存在 → 写入 seed(默认 {}),返回 seed

    设计:仓顶服务启动时调用,代替"由 wizard 创建 json"的老模式。 不应该由 wizard 兜底——wizard 只负责交互式填字段,文件骨架应该是 进程启动时一次性就地创建。

    Type Parameters

    Type Parameter
    T

    Parameters

    ParameterType
    filePathstring
    seedT

    Returns

    T