Skip to content

Codemod for converting Sanity schemas from JavaScript to TypeScript

License

Notifications You must be signed in to change notification settings

dangreaves/sanity-ts-schema-codemod

Repository files navigation

Codemod for converting Sanity schemas from JavaScript to TypeScript

GitHub License

This tool uses jscodeshift to take a set of Sanity CMS schemas in JavaScript format, and convert them to the new TypeScript format supported by Sanity v3.

Example

export default {
  name: "person",
  title: "Person",
  type: "document",
  fields: [
    {
      name: "fullName",
      title: "Full name",
      type: "string",
    },
  ],
};
import { defineField, defineType } from "sanity";

export const person = defineType({
  name: "person",
  title: "Person",
  type: "document",
  fields: [
    defineField({
      name: "fullName",
      title: "Full name",
      type: "string",
    }),
  ],
});

Usage

npm start -- convert-schemas --input ./src/js-schemas --output ./src/ts-schemas

About

Codemod for converting Sanity schemas from JavaScript to TypeScript

Topics

Resources

License

Stars

Watchers

Forks