Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .cursor/rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ This is a **CLI plugins** monorepo with plugin packages under `packages/`, inclu
- `contentstack-seed` - Seed stacks with generated data
- `contentstack-variants` - Manage content variants
- `contentstack-apps-cli` - Developer Hub apps (`app:*` commands; npm `@contentstack/apps-cli`)
- `contentstack-cli-tsgen` - TypeScript typings (`csdx tsgen`; npm `contentstack-cli-tsgen`; Jest integration tests)

All plugins depend on:
- `@contentstack/cli-command` - Base Command class
Expand Down
3 changes: 2 additions & 1 deletion .github/config/release.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"launch": false,
"branches": false,
"apps-cli": false,
"core": false
"core": false,
"tsgen": false
}
}
8 changes: 8 additions & 0 deletions .github/workflows/release-production-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ jobs:
package: ./packages/contentstack-query-export/package.json
tag: latest

# Tsgen
- name: Publishing tsgen (Production)
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
package: ./packages/contentstack-cli-tsgen/package.json
tag: latest

- name: Create Production Release
id: create_release
env:
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/tsgen-integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Tsgen Integration Tests

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
tsgen-integration:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.28.0

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build tsgen plugin
run: pnpm --filter contentstack-cli-tsgen run build

- name: Install Contentstack CLI (v1)
run: npm i -g @contentstack/cli

- name: Configure CLI region
run: csdx config:set:region ${{ secrets.REGION }}

- name: Add delivery token
run: csdx auth:tokens:add -a ${{ secrets.TOKEN_ALIAS }} --delivery -k ${{ secrets.APIKEY }} --token ${{ secrets.DELIVERYKEY }} -e ${{ secrets.ENVIRONMENT }}

- name: Link tsgen plugin
working-directory: ./packages/contentstack-cli-tsgen
run: csdx plugins:link

- name: Run integration tests
run: pnpm --filter contentstack-cli-tsgen run test:integration
env:
TOKEN_ALIAS: ${{ secrets.TOKEN_ALIAS }}

- name: Unlink tsgen plugin
working-directory: ./packages/contentstack-cli-tsgen
run: csdx plugins:unlink
if: always()
4 changes: 4 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ jobs:
- name: Run tests for Contentstack Apps CLI
working-directory: ./packages/contentstack-apps-cli
run: npm run test:unit:report:json

- name: Run tests for Contentstack Tsgen plugin
working-directory: ./packages/contentstack-cli-tsgen
run: npm run test
8 changes: 7 additions & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
fileignoreconfig:
- filename: pnpm-lock.yaml
checksum: 89acb731dc98c886694fa4d267c11c188000b8ecbe5ee6e4809e5bc6ec33a2f3
checksum: a5fd5bbb109364fc980359e175fde60bd0fec3241953bb93362928de80f3f0ac
- filename: packages/contentstack-cli-tsgen/AGENTS.md
checksum: 75b4f1414b547d0bd83df5ed4fb80020acc0ed849619bed2639491b565be7a1b
- filename: packages/contentstack-cli-tsgen/src/lib/helper.ts
checksum: a7ead0030ead9d15b6b6e9623f61e7def77b00325e3988f0e3d73a145180dedc
- filename: packages/contentstack-cli-tsgen/src/commands/tsgen.ts
checksum: 054ea78f765edca62c785714cf8962df4fb91529c0851439d1ed61e963467408
version: '1.0'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ To get a more detailed documentation for every command, visit the [CLI section](

## Useful Plugins

- [Generate TypeScript typings from a Stack](https://github.com/Contentstack-Solutions/contentstack-cli-tsgen)
- [Generate TypeScript typings from a Stack](https://github.com/contentstack/cli-plugins/tree/v1-dev/packages/contentstack-cli-tsgen) (`contentstack-cli-tsgen`)
18 changes: 18 additions & 0 deletions packages/contentstack-cli-tsgen/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
},
plugins: ["@typescript-eslint"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
rules: {
"unicorn/prefer-module": "off",
"unicorn/no-abusive-eslint-disable": "off",
"@typescript-eslint/no-use-before-define": "off",
"node/no-missing-import": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-require-imports": "off",
"no-useless-escape": "off",
},
};
15 changes: 15 additions & 0 deletions packages/contentstack-cli-tsgen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*-debug.log
*-error.log
/.nyc_output
/dist
/lib
/tmp
node_modules
.DS_Store
coverage
.env
oclif.manifest.json
talisman_output.log
snyk_output.log
tsconfig.tsbuildinfo
tests/integration/generated.d.ts
53 changes: 53 additions & 0 deletions packages/contentstack-cli-tsgen/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# contentstack-cli-tsgen – Agent guide

**Universal entry point** for contributors and AI agents. Detailed conventions live in **`skills/*/SKILL.md`**.

## What this repo is

| Field | Detail |
| --- | --- |
| **Name:** | `contentstack-cli-tsgen` ([contentstack/cli-plugins](https://github.com/contentstack/cli-plugins) → `packages/contentstack-cli-tsgen`) |
| **Purpose:** | OCLIF plugin that adds **`csdx tsgen`** to generate TypeScript typings from a stack. Generation is delegated to **`@contentstack/types-generator`** (`generateTS` / `graphqlTS`); this package owns flags, auth alias, file output, and CLI error formatting. |
| **Out of scope (if any):** | Core type-generation logic belongs in **`@contentstack/types-generator`** ([npm](https://www.npmjs.com/package/@contentstack/types-generator)), not reimplemented here. |

## Tech stack (at a glance)

| Area | Details |
| --- | --- |
| **Language** | TypeScript **5.9** (`strict` in [tsconfig.json](tsconfig.json)) |
| **Build** | `pnpm run build` → `tsc -b` → `lib/`; OCLIF manifest + readme |
| **Tests** | **Jest** + **ts-jest** ([jest.config.js](jest.config.js)); integration tests under `tests/integration/` |
| **Lint / coverage** | ESLint via `lint` and `posttest` |
| **Other** | OCLIF v4, Node **>= 14**; **v1** `@contentstack/cli-command` ~1.8.2 / `@contentstack/cli-utilities` ~1.18.3 |

**Main dependencies:** `@contentstack/cli-command`, `@contentstack/cli-utilities`, `@contentstack/types-generator`.

## Commands (quick reference)

| Command type | Command |
| --- | --- |
| **Build** | `pnpm run build` (from repo root: `pnpm --filter contentstack-cli-tsgen run build`) |
| **Test** | `pnpm test` (then **`posttest`** → ESLint) |
| **Integration** | `pnpm run test:integration` |
| **Lint** | `pnpm run lint` |

CI: [tsgen-integration-test.yml](../../.github/workflows/tsgen-integration-test.yml) (live stack); tests in [unit-test.yml](../../.github/workflows/unit-test.yml); release via [release-production-plugins.yml](../../.github/workflows/release-production-plugins.yml) on **`main`** (`latest` tag).

## Credentials and integration tests

Integration tests spawn **`csdx tsgen`** and require a **delivery token alias**. Set **`TOKEN_ALIAS`** (e.g. **`.env`** at package root; see [tests/integration/tsgen.integration.test.ts](tests/integration/tsgen.integration.test.ts)). CI uses secrets **`REGION`**, **`TOKEN_ALIAS`**, **`APIKEY`**, **`DELIVERYKEY`**, **`ENVIRONMENT`**.

## Where the documentation lives: skills

| Skill | Path | What it covers |
| --- | --- | --- |
| Development workflow | [skills/dev-workflow/SKILL.md](skills/dev-workflow/SKILL.md) | pnpm, CI, PRs, releases |
| TypeScript CLI tsgen | [skills/typescript-cli-tsgen/SKILL.md](skills/typescript-cli-tsgen/SKILL.md) | OCLIF command, flags, delegation to the library |
| Testing | [skills/testing/SKILL.md](skills/testing/SKILL.md) | Jest, integration env, CI |
| Code review | [skills/code-review/SKILL.md](skills/code-review/SKILL.md) | PR checklist, terminology, semver |

An index with “when to use” hints is in [skills/README.md](skills/README.md).

## Migration from standalone repo

See [TSGEN-MIGRATION.md](../../TSGEN-MIGRATION.md) at the monorepo root.
124 changes: 124 additions & 0 deletions packages/contentstack-cli-tsgen/MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
## Migrating to 4.10.0 (cli-plugins monorepo, CLI 1.x)

The plugin source moved to [contentstack/cli-plugins](https://github.com/contentstack/cli-plugins) at `packages/contentstack-cli-tsgen`. See [TSGEN-MIGRATION.md](../../TSGEN-MIGRATION.md).

| Change | Notes |
| --- | --- |
| Version | **4.10.0** — first release from monorepo on the **1.x** line |
| Install | `csdx plugins:install contentstack-cli-tsgen` |
| Dependencies | `@contentstack/cli-command` ~1.8.2, `@contentstack/cli-utilities` ~1.18.3 |
| Command | `csdx tsgen` unchanged |

For **CLI 2.x beta**, use the `v2-beta` branch and `contentstack-cli-tsgen@beta` (**5.0.0-beta.0**+).

---

## Migrating from v3 to v4

This changelog documents a breaking change to the `ISystemFields` interface, specifically related to the `publish_details` field.

## What Changed

The `publish_details` field is no longer an array of objects. It is now represented as a single `IPublishDetails` object.

This update aligns the generated types with the actual [Contentstack API](https://www.contentstack.com/docs/developers/apis/content-delivery-api) response.

## Before

```typescript
export interface ISystemFields {
uid?: string;
created_at?: string;
updated_at?: string;
created_by?: string;
updated_by?: string;
_content_type_uid?: string;
tags?: string[];
ACL?: any[];
_version?: number;
_in_progress?: boolean;
locale?: string;
publish_details?: IPublishDetails[]; // Incorrect: Array of IPublishDetails
title?: string;
}
```

## After

```typescript
export interface ISystemFields {
uid?: string;
created_at?: string;
updated_at?: string;
created_by?: string;
updated_by?: string;
_content_type_uid?: string;
tags?: string[];
ACL?: any[];
_version?: number;
_in_progress?: boolean;
locale?: string;
publish_details?: IPublishDetails; // Corrected: Single IPublishDetails object
title?: string;
}
```

---

## Migrating from v2 to v3

This document outlines the necessary changes to separate nested modular blocks into distinct interfaces. This update will affect how modular blocks are structured and used throughout the codebase.

## Before

```typescript
export interface Test {
/** Version */
_version?: 2;
/** Title */
title: string;
/** Modular Blocks */
modular_blocks?: {
test: {
/** Multi Line Textbox */
multi_line?: string;
/** Rich Text Editor */
rich_text_editor?: string;
/** Modular Blocks1 */
modular_blocks1?: {
test1: {
/** Multi Line Textbox */
multi_line?: string;
};
}[];
};
}[];
}
```

## After

```typescript
export interface Test {
/** Version */
_version: 2;
/** Title */
title: string;
/** Modular Blocks */
modular_blocks?: ModularBlocks[];
}

export interface ModularBlocks {
/** Multi Line Textbox */
multi_line?: string;
/** Rich Text Editor */
rich_text_editor?: string;
/** Modular Blocks1 */
modular_blocks1?: ModularBlocks1[];
}

export interface ModularBlocks1 {
/** Multi Line Textbox */
multi_line?: string;
}
```
Loading
Loading