codegen

от vercel

Утилиты генерации кода для json-render. Используйте при генерации кода из UI-спецификаций, создании пользовательских экспортёров кода, обходе спецификаций или сериализации свойств для…

npx skills add https://github.com/vercel-labs/json-render --skill codegen

@json-render/codegen

Framework-agnostic utilities for generating code from json-render UI trees. Use these to build custom code exporters for Next.js, Remix, or other frameworks.

Installation

npm install @json-render/codegen

Tree Traversal

import {
  traverseSpec,
  collectUsedComponents,
  collectStatePaths,
  collectActions,
} from "@json-render/codegen";

// Walk the spec depth-first
traverseSpec(spec, (element, key, depth, parent) => {
  console.log(`${" ".repeat(depth * 2)}${key}: ${element.type}`);
});

// Get all component types used
const components = collectUsedComponents(spec);
// Set { "Card", "Metric", "Button" }

// Get all state paths referenced
const statePaths = collectStatePaths(spec);
// Set { "analytics/revenue", "user/name" }

// Get all action names
const actions = collectActions(spec);
// Set { "submit_form", "refresh_data" }

Serialization

import {
  serializePropValue,
  serializeProps,
  escapeString,
  type SerializeOptions,
} from "@json-render/codegen";

// Serialize a single value
serializePropValue("hello");
// { value: '"hello"', needsBraces: false }

serializePropValue({ $state: "/user/name" });
// { value: '{ $state: "/user/name" }', needsBraces: true }

// Serialize props for JSX
serializeProps({ title: "Dashboard", columns: 3, disabled: true });
// 'title="Dashboard" columns={3} disabled'

// Escape strings for code
escapeString('hello "world"');
// 'hello \"world\"'

SerializeOptions

interface SerializeOptions {
  quotes?: "single" | "double";
  indent?: number;
}

Types

import type { GeneratedFile, CodeGenerator } from "@json-render/codegen";

const myGenerator: CodeGenerator = {
  generate(spec) {
    return [
      { path: "package.json", content: "..." },
      { path: "app/page.tsx", content: "..." },
    ];
  },
};

Building a Custom Generator

import {
  collectUsedComponents,
  collectStatePaths,
  traverseSpec,
  serializeProps,
  type GeneratedFile,
} from "@json-render/codegen";
import type { Spec } from "@json-render/core";

export function generateNextJSProject(spec: Spec): GeneratedFile[] {
  const files: GeneratedFile[] = [];
  const components = collectUsedComponents(spec);
  // Generate package.json, component files, main page...
  return files;
}

Больше skills от vercel

benchmark-sandbox
vercel
Запускает сценарии оценки vercel-plugin в песочницах Vercel вместо локальных панелей WezTerm. Предоставляет эфемерные микроВМ с предустановленными Claude Code и плагином,…
official
emil-design-eng
vercel
Этот навык кодирует философию Эмиля Ковальски в отношении полировки интерфейса, дизайна компонентов, анимационных решений и незаметных деталей, которые делают программное обеспечение приятным в использовании.
official
vercel-react-best-practices
vercel
Рекомендации по оптимизации производительности React и Next.js от инженеров Vercel. Этот навык следует использовать при написании, ревью или рефакторинге React/Next.js…
official
vercel-react-best-practices
vercel
Рекомендации по оптимизации производительности React и Next.js от инженеров Vercel. Этот навык следует использовать при написании, рецензировании или рефакторинге React/Next.js…
official
write-guide
vercel
Создайте техническое руководство, которое обучает реальному примеру использования через последовательные примеры. Концепции вводятся только тогда, когда они нужны читателю.
official
release
vercel
Vercel-plugin — запуск шлюзов, обновление версии, генерация артефактов, коммит и пуш. Используйте, когда вас просят «выпустить релиз», «запустить», «обновить версию и запушить» или «сделать релиз».
official
deepsec
vercel
Запустить DeepSec для проверки проекта Vercel из dev3000. Используется для одношаговой настройки DeepSec, начальной загрузки контекста проекта, ограниченной первичной обработки и…
official
backport-pr
vercel
Выполнить бэкпорт объединённого pull request Next.js из canary в предыдущую ветку релиза, например next-16-2. Используйте, когда пользователь просит выполнить бэкпорт, cherry-pick или открыть…
official