typescript-cli-tsgen
by contentstack
Mental model for the contentstack-cli-tsgen OCLIF plugin and tsgen command.
npx skills add https://github.com/contentstack/contentstack-cli-tsgen --skill typescript-cli-tsgenTypeScript CLI tsgen skill
Role of this repo
- Plugin for
csdx: implementsTypeScriptCodeGeneratorCommandinsrc/commands/tsgen.ts. - Generation is delegated to
@contentstack/types-generator(npm, GitHub)—version ^3.9.3 in package.json. Do not assume a local clone; use npm and published source only.
Change here vs change in the library
| Concern | Where |
|---|---|
New flags, output path, csdx UX, printFormattedError | This repo (src/commands/, src/lib/) |
| Schema mapping, Delivery SDK calls, GraphQL introspection | @contentstack/types-generator |
Helpers
src/lib/helper.ts:sanitizePath,printFormattedError(FormattedError,error_codeswitch).src/types/index.ts:StackConnectionConfigand related CLI types.
OCLIF
- Commands compile to
lib/commands;prepackrefreshesoclif.manifest.jsonand README.
Command shape (tsgen)
- Extends
Commandfrom@contentstack/cli-command(src/commands/tsgen.ts). - Flags include
token-alias(-a, required),output(-o),prefix,doc,branch,include-system-fields,include-editable-tags,include-referenced-entry,api-type(rest|graphql),namespace(GraphQL). - Resolve token via
this.getToken(flags["token-alias"]); warn iftoken.type !== "delivery"(management token can break Delivery/GraphQL flows). - Build
StackConnectionConfig:apiKey,token,region,environment,branch,hostas in existing code. api-type === "graphql"→graphqlTS(...)with delivery token; REST →generateTSwithtokenType: "delivery"; write output withfs.writeFileSyncto the resolved path.- Use
printFormattedErrorfromsrc/lib/helper.tsfor consistent CLI messaging.