|
| 1 | +# `contentstack-cli-tsgen` |
| 2 | + |
| 3 | +**Purpose:** Contentstack CLI (**OCLIF**) plugin that adds **`csdx tsgen`** to generate TypeScript typings from a stack. Generation is delegated to the **`@contentstack/types-generator`** npm package (`generateTS` / `graphqlTS`); this repo owns the command surface (flags, auth alias, file output, CLI error formatting). |
| 4 | + |
| 5 | +- **Repository:** [github.com/Contentstack-Solutions/contentstack-cli-tsgen](https://github.com/Contentstack-Solutions/contentstack-cli-tsgen) |
| 6 | +- **Homepage:** [https://github.com/Contentstack-Solutions/contentstack-cli-tsgen](https://github.com/Contentstack-Solutions/contentstack-cli-tsgen) |
| 7 | + |
| 8 | +**Library dependency (separate repo):** [`@contentstack/types-generator`](https://www.npmjs.com/package/@contentstack/types-generator) (see version in [package.json](package.json)). Source for the generator itself: [github.com/contentstack/types-generator](https://github.com/contentstack/types-generator). Do not assume a local sibling folder; treat it as an npm dependency only. |
| 9 | + |
| 10 | +## Tech stack |
| 11 | + |
| 12 | +| Area | Details | |
| 13 | +| --- | --- | |
| 14 | +| Language | TypeScript **5.9** (`strict` in [tsconfig.json](tsconfig.json)) | |
| 15 | +| Runtime | Node (CI **18.x** / **20.x**; release **22.x**) | |
| 16 | +| Build | **`tsc -b`** → **`lib/`**; **`npm run prepack`** runs `tsc -b`, **`oclif manifest`**, **`oclif readme`** | |
| 17 | +| CLI | **OCLIF** — commands compiled to **`lib/commands`** (see `oclif.commands` in [package.json](package.json)) | |
| 18 | +| Tests | **Jest** + **ts-jest** ([jest.config.js](jest.config.js)) | |
| 19 | +| Lint | **ESLint** runs in **`posttest`** after tests ([package.json](package.json) scripts) | |
| 20 | + |
| 21 | +**Main dependencies:** `@contentstack/cli-command`, `@contentstack/cli-utilities`, `@contentstack/types-generator`, `dotenv`. |
| 22 | + |
| 23 | +## Source layout |
| 24 | + |
| 25 | +- **Commands:** [src/commands/](src/commands/) (e.g. `tsgen.ts`) |
| 26 | +- **Helpers / errors:** [src/lib/](src/lib/) |
| 27 | +- **Types:** [src/types/](src/types/) |
| 28 | +- **Build output:** **`lib/`** (not committed as source of truth; produced by `prepack`) |
| 29 | + |
| 30 | +## Common commands |
| 31 | + |
| 32 | +| Command | Purpose | |
| 33 | +| --- | --- | |
| 34 | +| `npm run prepack` | Clean `lib/`, compile TypeScript, generate OCLIF manifest and README | |
| 35 | +| `npm test` | Jest (`--testPathPattern=tests`); then **`posttest`** runs ESLint with fix | |
| 36 | +| `npm run test:integration` | Jest for `tests/integration` only | |
| 37 | + |
| 38 | +There is no dedicated `build` script; **`prepack`** is the canonical compile path. CI may run `npm run build --if-present` (no-op here if no `build` script). |
| 39 | + |
| 40 | +## Credentials and integration tests |
| 41 | + |
| 42 | +Integration tests spawn **`csdx tsgen`** and require a configured **delivery token alias**. Set **`TOKEN_ALIAS`** (e.g. in **`.env`** at the package root; see [tests/integration/tsgen.integration.test.ts](tests/integration/tsgen.integration.test.ts)). |
| 43 | + |
| 44 | +CI uses GitHub secrets such as **`REGION`**, **`TOKEN_ALIAS`**, **`APIKEY`**, **`DELIVERYKEY`**, **`ENVIRONMENT`** (see [.github/workflows/node.js.yml](.github/workflows/node.js.yml)). |
| 45 | + |
| 46 | +--- |
| 47 | + |
| 48 | +## AI guidance index |
| 49 | + |
| 50 | +- [Cursor rules (overview)](.cursor/rules/README.md) |
| 51 | +- [Skills index](skills/README.md) |
0 commit comments