Skip to content

Commit 4fdd8eb

Browse files
Merge pull request #293 from contentstack/staging
DX | 30-03-2026 | Release
2 parents 24f293a + 062ac60 commit 4fdd8eb

File tree

14 files changed

+684
-352
lines changed

14 files changed

+684
-352
lines changed

.cursor/rules/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Cursor rules for `contentstack-cli-tsgen`
2+
3+
This folder contains project-specific rules. Each `.mdc` file uses YAML frontmatter (`description`, `globs`, `alwaysApply`).
4+
5+
| Rule file | `alwaysApply` | Globs | When it applies | Related skill |
6+
| --- | --- | --- | --- | --- |
7+
| [dev-workflow.mdc](dev-workflow.mdc) | No | `package.json`, `package-lock.json`, `.github/workflows/**/*`, `tsconfig.json`, `jest.config.js`, `.eslintrc.js`, `AGENTS.md` | Workflow, CI, release, package scripts | [testing](../../skills/testing/SKILL.md), [code-review](../../skills/code-review/SKILL.md) |
8+
| [typescript.mdc](typescript.mdc) | No | `src/**/*.ts`, `tests/**/*.ts` | TypeScript and ESLint conventions | [typescript-cli-tsgen](../../skills/typescript-cli-tsgen/SKILL.md) |
9+
| [oclif-tsgen.mdc](oclif-tsgen.mdc) | No | `src/commands/**`, `src/lib/**` | OCLIF command, flags, delegation to `@contentstack/types-generator` | [typescript-cli-tsgen](../../skills/typescript-cli-tsgen/SKILL.md) |
10+
| [testing.mdc](testing.mdc) | No | `tests/**`, `jest.config.js` | Jest and integration tests with `csdx` | [testing](../../skills/testing/SKILL.md) |
11+
| [code-review.mdc](code-review.mdc) | **Yes** || Every change | [code-review](../../skills/code-review/SKILL.md) |
12+
13+
## Referencing rules in Cursor
14+
15+
- Use **@** in chat (e.g. `@oclif-tsgen`, `@dev-workflow`) to pull in rule context.
16+
- `code-review.mdc` applies automatically (`alwaysApply: true`); others match globs or manual @-mentions.

.cursor/rules/code-review.mdc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
description: PR and change review checklist for contentstack-cli-tsgen
3+
alwaysApply: true
4+
---
5+
6+
# Code review checklist
7+
8+
## API and documentation
9+
10+
- **CLI surface:** Flag names, examples, and help text stay accurate; **`oclif readme`** output remains consistent when commands change.
11+
- **Terminology:** **Delivery** token / **GraphQL** vs REST—do not describe this plugin as a **CMA**-first tool.
12+
13+
## Compatibility
14+
15+
- **Backward compatibility:** Avoid breaking changes to flags, exit behavior, or output file contract without semver intent.
16+
- **Errors:** Align with **`printFormattedError`** and **`FormattedError`** patterns in [`src/lib/helper.ts`](src/lib/helper.ts); preserve stable error codes where used.
17+
18+
## Dependencies
19+
20+
- **`@contentstack/types-generator`:** Pin/bump per semver; do not duplicate library logic in the CLI—delegate to the package ([npm](https://www.npmjs.com/package/@contentstack/types-generator), [repo](https://github.com/contentstack/types-generator)).
21+
22+
## Security and supply chain
23+
24+
- **SCA:** `.github/workflows/sca-scan.yml` runs Snyk on pull requests.
25+
26+
## Tests
27+
28+
- **Integration:** Changes to **`csdx tsgen`** should keep **`tests/integration/`** passing when **`TOKEN_ALIAS`** and stack secrets are available.

.cursor/rules/dev-workflow.mdc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
description: Branches, prepack/test, PR and release workflow for contentstack-cli-tsgen
3+
alwaysApply: false
4+
globs:
5+
- package.json
6+
- package-lock.json
7+
- .github/workflows/**/*
8+
- tsconfig.json
9+
- jest.config.js
10+
- .eslintrc.js
11+
- AGENTS.md
12+
---
13+
14+
# Development workflow
15+
16+
For detail on tests and env, see **[skills/testing](../../skills/testing/SKILL.md)**; for PR expectations, **[skills/code-review](../../skills/code-review/SKILL.md)**.
17+
18+
## Branches
19+
20+
- **CI (Node.js workflow)** runs on **push** and **pull_request** for **`master`**, **`development`**, and **`staging`** (see `.github/workflows/node.js.yml`).
21+
- **Release** runs on **push** to **`master`** (see `.github/workflows/release.yml`), Node **22.x**, artifact **`lib`**, npm publish + GitHub release.
22+
23+
**Maintainer note:** Other Contentstack repos may use different default branches (`main` vs `master`). Align docs and protection rules when convenient—no git config changes implied here.
24+
25+
## Build and compile
26+
27+
- **`npm run prepack`**: removes **`lib/`**, runs **`tsc -b`**, **`oclif manifest`**, **`oclif readme`**. This is the canonical build before pack/publish.
28+
- CI runs **`npm run prepack`** after global **`csdx`** setup and **`plugins:link`**.
29+
30+
## Tests and lint
31+
32+
- **`npm test`**: Jest with `--testPathPattern=tests`.
33+
- **`posttest`** (after `npm test`): ESLint with `.eslintrc.js` and `--fix`.
34+
35+
## Pull requests
36+
37+
- Run **`npm run prepack`** and **`npm test`** (which triggers **`posttest`**) before merge when touching source or tests.
38+
39+
## Releases
40+
41+
- Version in **`package.json`** drives publishing; release workflow builds with **`prepack`** and publishes from **`master`**.

.cursor/rules/oclif-tsgen.mdc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
description: OCLIF tsgen command, flags, and delegation to @contentstack/types-generator
3+
alwaysApply: false
4+
globs:
5+
- src/commands/**
6+
- src/lib/**
7+
---
8+
9+
# OCLIF `tsgen` command
10+
11+
Scope: **CLI only**. Type generation internals live in the **`@contentstack/types-generator`** package ([npm](https://www.npmjs.com/package/@contentstack/types-generator), [repository](https://github.com/contentstack/types-generator))—do not invent library APIs here.
12+
13+
## Command shape
14+
15+
- Extends **`Command`** from **`@contentstack/cli-command`** ([`src/commands/tsgen.ts`](src/commands/tsgen.ts)).
16+
- **Flags:** e.g. **`token-alias`** (`-a`, required), **`output`** (`-o`), **`prefix`**, **`doc`**, **`branch`**, **`include-system-fields`**, **`include-editable-tags`**, **`include-referenced-entry`**, **`api-type`** (`rest` \| `graphql`), **`namespace`** (GraphQL).
17+
- Use **`this.parse`**, **`this.error`**, **`this.log`** / **`cliux`** / **`log`** from **`@contentstack/cli-utilities`** per existing patterns.
18+
19+
## Auth and stack config
20+
21+
- Resolve token via **`this.getToken(flags["token-alias"])`**. Warn if **`token.type !== "delivery"`** (management token may break Delivery/GraphQL flows).
22+
- Build **`StackConnectionConfig`**: **`apiKey`**, **`token`**, **`region`**, **`environment`**, **`branch`**, **`host`** (CDA host from command context).
23+
24+
## Generation paths
25+
26+
- **`api-type === "graphql"`** → **`graphqlTS(...)`** with delivery token required; pass **`logger: log`** where applicable.
27+
- **REST (default)** → **`generateTS({ ...config, tokenType: "delivery", ... })`**.
28+
- Write result with **`fs.writeFileSync`** to the resolved output path.
29+
30+
## Errors
31+
32+
- Use **`printFormattedError`** from [`src/lib/helper.ts`](src/lib/helper.ts) for consistent CLI messaging; **`process.exit(1)`** on failure paths as in the command today.
33+
- **Terminology:** **Delivery** and **GraphQL** as documented in flags—not **CMA** as the primary path.

.cursor/rules/testing.mdc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
description: Jest tests and integration env for contentstack-cli-tsgen
3+
alwaysApply: false
4+
globs:
5+
- tests/**
6+
- jest.config.js
7+
---
8+
9+
# Testing (`contentstack-cli-tsgen`)
10+
11+
- **Runner:** **Jest** with **ts-jest** preset **`node`** ([jest.config.js](jest.config.js)).
12+
- **Match:** `**/tests/**/*.+(ts|tsx)` and standard test patterns.
13+
- **Current layout:** Integration tests under **`tests/integration/`** (e.g. **`spawnSync`** invoking **`csdx tsgen`**).
14+
- **Env:** **`TOKEN_ALIAS`** must be set for integration tests (see **`tests/integration/tsgen.integration.test.ts`**); **`.env`** at package root is loaded via `dotenv` in that file.
15+
- **Commands:** `npm test` (all tests under `tests`), `npm run test:integration` (integration path only).

.cursor/rules/typescript.mdc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
description: TypeScript and ESLint conventions for contentstack-cli-tsgen
3+
alwaysApply: false
4+
globs:
5+
- src/**/*.ts
6+
- tests/**/*.ts
7+
---
8+
9+
# TypeScript (`contentstack-cli-tsgen`)
10+
11+
- **Compiler:** TypeScript **5.9**, **`strict: true`** ([tsconfig.json](tsconfig.json)); output **`lib/`** from **`src/`** via **`tsc -b`**.
12+
- **Layout:** **`src/commands/`** (OCLIF commands), **`src/lib/`** (helpers such as path sanitization and **`printFormattedError`**), **`src/types/`**.
13+
- **Linting:** **ESLint** with **`eslint-config-oclif`** / **`eslint-config-oclif-typescript`** (see **`.eslintrc.js`**). **`posttest`** runs `eslint . --ext .ts --config .eslintrc.js --fix` after Jest.

.talismanrc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ fileignoreconfig:
33
ignore_detectors:
44
- filecontent
55
- filename: package-lock.json
6-
checksum: fadad20d6e5ea2efd20595a8262b5f18ab59db802c18f4b1c1faec0c325ab2ac
6+
checksum: 9cf2ec1b73a078e9f3c974f1a9b7f70864f0307115d1f965b57752ba5a9dcdf2
7+
- filename: .cursor/rules/oclif-tsgen.mdc
8+
checksum: 83d43465e1b0d7d8c4fd3a13ca4cde13fc5ea2b578186891e3b268ede0e7d97c
9+
- filename: AGENTS.md
10+
checksum: 7cce7645c9ebd051f971ea157fc85b691b23c963211debf31729d9ee607c081f
711
version: "1.0"

AGENTS.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
 (0)