prismicio / prismic-ts-codegen

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

feat: add `init` CLI command #4

Closed angeloashmore closed 2 years ago

angeloashmore commented 2 years ago

Types of changes

Description

This PR adds an init command to the CLI. It bootstraps a config file.

npx prismic-ts-codegen init

By default, it will create a file at prismicCodegen.config.ts, which is the default location the CLI will read when generating types. This path can be configured using the --config (-c) flag.

npx prismic-ts-codegen init -c custom.config.ts

It will generate the following contents by default:

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

const config: Config = {
  output: "./types.generated.ts",
};

export default config;

If the CLI detects that the project a Slice Machine project, it will generate the following contents:

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

const config: Config = {
  output: "./types.generated.ts",

  models: ["./customtypes/**/index.json", "./slices/**/model.json"],
};

export default config;

This gives Slice Machine users a quick way to generate types without hiding behind Slice Machine-specific flags (e.g. config.sliceMachine: true).

In the future, this init command could be more sophisticated by reading sm.json to extract the repository name and Slice Library locations. The current simple contents will work for now.

Checklist:

🚃

github-actions[bot] commented 2 years ago

size-limit report 📦

Path Size
dist/index.js 1.04 MB (0%)
dist/index.cjs 1.04 MB (0%)