Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add environment file flag to CLI #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/contentful-typescript-codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ const cli = meow(
$ contentful-typescript-codegen --output <file> <options>

Options
--output, -o Where to write to
--poll, -p Continuously refresh types
--interval N, -i The interval in seconds at which to poll (defaults to 15)
--namespace N, -n Wrap types in namespace N (disabled by default)
--fields-only Output a tree that _only_ ensures fields are valid
and present, and does not provide types for Sys,
Assets, or Rich Text. This is useful for ensuring raw
Contentful responses will be compatible with your code.
--localization -l Output fields with localized values
--output, -o Where to write to
--poll, -p Continuously refresh types
--interval N, -i The interval in seconds at which to poll (defaults to 15)
--namespace N, -n Wrap types in namespace N (disabled by default)
--fields-only Output a tree that _only_ ensures fields are valid
and present, and does not provide types for Sys,
Assets, or Rich Text. This is useful for ensuring raw
Contentful responses will be compatible with your code.
--localization -l Output fields with localized values
--environment-file -e Specify a path to Contentful environment file (defaults to ./getContentfulEnvironment.js)

Examples
$ contentful-typescript-codegen -o src/@types/generated/contentful.d.ts
Expand Down Expand Up @@ -55,12 +56,20 @@ const cli = meow(
alias: "l",
required: false,
},
environmentFile: {
type: "string",
alias: "e",
required: false,
},
},
},
)

async function runCodegen(outputFile: string) {
const getEnvironmentPath = path.resolve(process.cwd(), "./getContentfulEnvironment.js")
const getEnvironmentPathDefault = path.resolve(process.cwd(), "./getContentfulEnvironment.js")
const getEnvironmentPath = cli.flags.environmentFile
? path.resolve(cli.flags.environmentFile)
: getEnvironmentPathDefault
const getEnvironment = require(getEnvironmentPath)
const environment = await getEnvironment()
const contentTypes = await environment.getContentTypes({ limit: 1000 })
Expand Down