New to Claude Skills? Learn how to install them →

vercel-labs on GitHub

Code Generation Utilities

OfficialFree

Generate code from UI specs with ease.

Get this skill

Free · Opens the source repo

What Code Generation Utilities does

The @json-render/codegen package provides a set of utilities for generating code from JSON-render UI trees, making it a valuable tool for developers working with frameworks like Next.js and Remix. By leveraging this package, you can create custom code exporters tailored to your specific needs, streamlining the process of translating UI specifications into functional code.

One of the key features of this skill is its ability to traverse a JSON specification depth-first, allowing you to analyze the structure and components used within the spec. This includes functions to collect used components, state paths, and action names, which can be crucial for understanding the data flow and interactions in your application. The ability to extract this information simplifies the process of building and maintaining complex UI structures.

Additionally, the serialization capabilities of the package enable you to convert props into JSX-compatible strings, ensuring that the generated code adheres to the syntax requirements of your chosen framework. This includes functions for serializing individual values, escaping strings, and handling different quote styles, which can help prevent syntax errors and improve code readability.

Overall, @json-render/codegen is designed for developers who need to automate the code generation process from UI specifications, enhancing productivity and reducing the potential for manual coding errors. Whether you're building a new project or maintaining an existing one, these utilities can save you time and effort in translating design into code.

When to use it

Use this skill when you need to generate code from JSON-render UI trees for frameworks like Next.js or Remix.

When not to use it

This skill may not be suitable for projects that do not utilize JSON-render or require highly customized code generation beyond the provided utilities.

What you can build with it

Generating a Next.js Project

Use the utilities to create a complete Next.js project structure from a JSON specification, including pages and components.

Automating UI Code Export

Leverage the skill to automate the export of UI code from design specs, reducing manual coding effort.

Traversing Complex Specs

Utilize the traversal functions to analyze and understand complex JSON specs, identifying components and state paths.

How to install Code Generation Utilities

View source

1. Install with the skills CLI

npx skills add vercel-labs/json-render/codegen --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by vercel-labs

@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;
}

Frequently asked questions about Code Generation Utilities

Similar skills