prismicio / prismic-ts-codegen

A Prismic model-to-TypeScript-type generator.
Apache License 2.0
18 stars 6 forks source link

feat: configure CLI with config file #3

Closed angeloashmore closed 2 years ago

angeloashmore commented 2 years ago

Types of changes

Description

This PR adds the ability to configure the CLI with a configuration file.

Configuration is loaded from the following locations:

Note: The name of the file is up for debate as it feels a bit clunky.

With the new configuration options, the CLI is now able to do the following:

The fully filled out configuration file could look like the following:

// prismicCodegen.config.ts

import { Config } from "prismic-ts-codegen";

const config: Config = {
  repositoryName: "my-repo-name",
  accessToken: "abc123xyz345",
  customTypesAPIToken: "abc123xyz345",

  output: "./types.generated.ts",

  locales: {
    ids: ["en-us", "fr-fr", "en-gb"],
    fetchFromRepository: true,
  },

  models: {
    files: ["./customtypes/**/index.json", "./slices/**/model.json"],
    fetchFromRepository: true,
  },

  fields: {
    embed: {
      providerTypes: {
        YouTube: 'import("./types").OEmbedYouTube',
        Twitter: 'import("./types").OEmbedTwitter',
        Vimeo: 'import("./types").OEmbedVimeo',
      },
    },
    integrationFields: {
      catalogTypes: {
        shop: 'import("./types").IntegrationFieldShop',
      },
    },
  },
};

export default config

All properties are optional. Providing some options require other options. For example, if models.fetchFromRepository is true, then repositoryName and customTypesApiToken are required.

The config object will be validated when the CLI is called.

Checklist:

🐕

github-actions[bot] commented 2 years ago

size-limit report 📦

Path Size
dist/index.js 1.04 MB (+0.01% 🔺)
dist/index.cjs 1.04 MB (-0.01% 🔽)