Skip to content

Commit d719964

Browse files
committed
update: added unit tests and skills
1 parent 35bb3b1 commit d719964

39 files changed

+3022
-620
lines changed

.cursor/rules/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Cursor rules (contentstack-cli-content-type)
2+
3+
Rules are `.mdc` files under `.cursor/rules/`. For each rule here, **`alwaysApply` is `false`**: Cursor applies it when files matching **`globs`** are in context (open or relevant to the task).
4+
5+
| Rule file | Globs | Purpose | Related skill |
6+
|-----------|--------|---------|----------------|
7+
| [dev-workflow.mdc](dev-workflow.mdc) | `src/**/*.ts`, `tests/**/*.ts`, `package.json`, `jest.config.js` | Run `npm test` / ESLint / `test:coverage` before PR; oclif docs when commands change | [AGENTS.md](../../AGENTS.md), [.cursor/skills/testing/SKILL.md](../skills/testing/SKILL.md) |
8+
| [content-type-plugin.mdc](content-type-plugin.mdc) | `src/commands/**`, `src/core/**`, `src/utils/**`, `src/types/**`, `src/config/**` | OCLIF commands, `ContentTypeCommand`, utils/types/config, Management SDK + axios client, no secret logging, `oclif readme` when commands change | [.cursor/skills/contentstack-cli-content-type/SKILL.md](../skills/contentstack-cli-content-type/SKILL.md) |
9+
| [testing.mdc](testing.mdc) | `tests/**/*.ts`, `jest.config.js` | Jest + ts-jest, mock boundaries, `npm test` / posttest ESLint | [.cursor/skills/testing/SKILL.md](../skills/testing/SKILL.md) |
10+
| [review.mdc](review.mdc) | `compare.ts`, `diagram.ts`, `src/core/contentstack/**`, `package.json` | Security and PR review highlights for high-risk paths and dependency changes | [.cursor/skills/review/SKILL.md](../skills/review/SKILL.md) |
11+
| [typescript-build.mdc](typescript-build.mdc) | `tsconfig.json` | `strict`, `rootDir`/`outDir`, `tsc -b` / prepack alignment | [.cursor/skills/contentstack-cli-content-type/SKILL.md](../skills/contentstack-cli-content-type/SKILL.md) |
12+
| [eslint-config.mdc](eslint-config.mdc) | `.eslintrc` | oclif-typescript style, posttest eslint expectations ||
13+
| [oclif-docs.mdc](oclif-docs.mdc) | `README.md`, `oclif.manifest.json` | Regenerate command docs/manifest via `oclif readme` / `oclif manifest` after command changes | [.cursor/skills/contentstack-cli-content-type/SKILL.md](../skills/contentstack-cli-content-type/SKILL.md) |
14+
15+
See also [.cursor/skills/README.md](../skills/README.md) for the full skill index.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
description: OCLIF content-type plugin — commands, core, utils, types, config (ContentTypeCommand, SDK, CMA client)
3+
globs:
4+
- src/commands/**/*.ts
5+
- src/core/**/*.ts
6+
- src/utils/**/*.ts
7+
- src/types/**/*.ts
8+
- src/config/**/*.ts
9+
alwaysApply: false
10+
---
11+
12+
# content-type plugin
13+
14+
- Commands live under `src/commands/content-type/` and extend **`ContentTypeCommand`** from `src/core/command.ts`. Parse flags, call **`setup(flags)`** (await where the command awaits it), then delegate to **`src/core/content-type/`** and **`src/utils/index.ts`**.
15+
- **utils**: Management SDK helpers (`getStack`, `getContentTypes`, pagination via `src/config/index.ts`); keep **`handleErrorMsg`** / `process.exit` patterns consistent with existing code.
16+
- **types / config**: Shared types and query limits affect commands and core—align changes with consumers under `src/core` and `src/commands`.
17+
- Build **`managementSDKClient`** when using stack/content-type fetches; use **`ContentstackClient`** from `src/core/contentstack/client.ts` for audit logs and references REST paths.
18+
- **Never log** tokens, `authtoken`, `authorization` headers, or raw management credentials.
19+
- User-facing errors for REST failures should follow **`ContentstackError`** / `buildError` patterns in `client.ts`.
20+
- After changing command IDs, flags, or descriptions, regenerate docs with **`oclif readme`** (see `package.json` `prepack` / `version`).
21+
22+
Full detail: `.cursor/skills/contentstack-cli-content-type/SKILL.md` and `references/` there.

.cursor/rules/dev-workflow.mdc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
description: Local validation before PR — tests, ESLint, coverage, oclif docs
3+
globs:
4+
- src/**/*.ts
5+
- tests/**/*.ts
6+
- package.json
7+
- jest.config.js
8+
alwaysApply: true
9+
---
10+
11+
# Development workflow
12+
13+
- Run **`npm test`** before opening a PR; fix failures before review.
14+
- **`npm run posttest`** runs ESLint on `.ts` files (see [package.json](package.json)); keep lint clean when shipping changes.
15+
- When changing behavior in **`src/core/`** or **`src/utils/`**, run **`npm run test:coverage`** and ensure coverage does not drop below [jest.config.js](jest.config.js) thresholds.
16+
- After changing command IDs, flags, or descriptions, regenerate CLI docs with **`npm run prepack`** or the **`version`** script so `README.md` and `oclif.manifest.json` stay aligned.
17+
18+
Full context: [AGENTS.md](../../AGENTS.md) at the repository root.

.cursor/rules/eslint-config.mdc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
description: ESLint configuration and style expectations for contentstack-cli-content-type
3+
globs:
4+
- .eslintrc
5+
alwaysApply: false
6+
---
7+
8+
# ESLint
9+
10+
- Config extends **oclif-typescript** and **`@typescript-eslint/recommended`** (see [`.eslintrc`](.eslintrc)).
11+
- Notable conventions: **single quotes**, **`eqeqeq`** smart, **`@typescript-eslint/no-unused-vars`** (args none), **`no-var`**. New rule overrides should not break **`npm run posttest`** / **`eslint . --ext .ts --config .eslintrc`**.
12+
- Prefer fixing lint in **`src/`** and **`tests/`** rather than disabling rules project-wide without team agreement.

.cursor/rules/oclif-docs.mdc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
description: Oclif-generated README command docs and CLI manifest for contentstack-cli-content-type
3+
globs:
4+
- README.md
5+
- oclif.manifest.json
6+
alwaysApply: false
7+
---
8+
9+
# Oclif docs and manifest
10+
11+
- **README.md** command sections and **oclif.manifest.json** are generated by **`oclif readme`** and **`oclif manifest`** (see [`package.json`](package.json) `prepack`, `version`).
12+
- Prefer changing **`src/commands/**/*.ts`** (descriptions, flags, examples), then run **`npm run prepack`** or the relevant **`oclif`** script so README and manifest stay consistent—avoid hand-editing generated command blocks unless you will regenerate immediately after.
13+
- If you only need doc tweaks without a full prepack, follow the same workflow the team uses for releases so CI and published packages stay aligned.
14+
15+
Full workflow: `.cursor/skills/contentstack-cli-content-type/SKILL.md`.

.cursor/rules/review.mdc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
description: PR and security review context for contentstack-cli-content-type (compare, diagram, client, dependencies)
3+
globs:
4+
- src/core/content-type/compare.ts
5+
- src/core/content-type/diagram.ts
6+
- src/core/contentstack/**/*.ts
7+
- package.json
8+
alwaysApply: false
9+
---
10+
11+
# Review
12+
13+
- **Never log** tokens, `authtoken`, `authorization` headers, or raw management credentials. Stack API keys in user-facing errors should follow existing patterns in `client.ts` / `ContentstackError`.
14+
- **Compare** (`compare.ts`): temp HTML, browser open, and diff pipeline—review for accidental data exposure and path handling.
15+
- **Diagram** (`diagram.ts`): Graphviz / file output paths and large-model behavior when changing layout or IO.
16+
- **Dependencies** (`package.json`): version bumps on axios, diff2html, git-diff, node-graphviz, tmp, cli-ux—check changelog and security advisories.
17+
18+
Full checklist: `.cursor/skills/review/SKILL.md` and `references/checklist.md`.

.cursor/rules/testing.mdc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
description: Jest tests and config for contentstack-cli-content-type
3+
globs:
4+
- tests/**/*.ts
5+
- jest.config.js
6+
alwaysApply: false
7+
---
8+
9+
# Testing
10+
11+
- Use **Jest** with **ts-jest** per `jest.config.js`. Tests live under **`tests/`** (and may match `*.test.ts` at repo root per config).
12+
- **Mock HTTP and SDK boundaries** — mock `ContentstackClient`, axios, or fake `managementSDKClient` chains. **No live Contentstack API** calls in unit tests.
13+
- Run **`npm test`**; **`npm run test:coverage`** for coverage against [jest.config.js](jest.config.js) thresholds; **`posttest`** runs ESLint on `.ts` files — keep both green when shipping changes.
14+
- Add or update tests for behavioral changes in `src/core/` and `src/utils/` when practical.
15+
16+
Full detail: `.cursor/skills/testing/SKILL.md`; `references/conventions.md` and `references/jest-mocking.md`.

.cursor/rules/typescript-build.mdc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
description: TypeScript compiler options and build layout for contentstack-cli-content-type
3+
globs:
4+
- tsconfig.json
5+
alwaysApply: false
6+
---
7+
8+
# TypeScript build
9+
10+
- Preserve [`tsconfig.json`](tsconfig.json) intent: **`strict: true`**, **`rootDir: src`**, **`outDir: lib`**, **`module: commonjs`**, **`target: es2017`**.
11+
- Changes to **`include`**, **`compilerOptions.paths`**, or **`rootDir`/`outDir`** affect the whole package and published `lib/` output—validate with **`tsc -b`** (as in `prepack`).
12+
- Source of truth for app code is **`src/`**; compiled JS lives under **`lib/`** (do not treat `lib/` as hand-edited).
13+
14+
See `.cursor/skills/contentstack-cli-content-type/SKILL.md` for release/prepack workflow.

.cursor/skills/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Project skills (contentstack-cli-content-type)
2+
3+
Cursor loads **project skills** from `.cursor/skills/<skill-name>/SKILL.md`. Each folder below is one skill; open `SKILL.md` for instructions and follow links into `references/` for detail.
4+
5+
| Skill folder | Purpose | When to load |
6+
|--------------|---------|----------------|
7+
| [contentstack-cli-content-type](contentstack-cli-content-type/SKILL.md) | Plugin architecture, `ContentTypeCommand`, CMA client, commands, build/readme workflow | Editing `src/commands`, `src/core`, `src/utils`, auth, compare/diagram behavior, oclif |
8+
| [testing](testing/SKILL.md) | Jest, `tests/`, mocking, `npm test` / `test:coverage` / ESLint posttest; see `references/conventions.md` | Adding or changing tests, Jest config, mocks |
9+
| [review](review/SKILL.md) | PR review checklist and risk areas | Reviewing PRs, dependency bumps, security-sensitive edits |
10+
11+
Use the skill whose **description** frontmatter best matches the task; combine **testing** with **contentstack-cli-content-type** when implementing features that need tests.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
name: contentstack-cli-content-type
3+
description: >-
4+
Develops and maintains the contentstack-cli-content-type csdx plugin (content-type list,
5+
details, audit, compare, compare-remote, diagram). Use when editing this repository,
6+
ContentTypeCommand setup and flags, CMA/Management SDK usage, axios audit/references calls,
7+
diff/compare HTML output, Graphviz diagrams, or oclif readme/manifest workflows.
8+
---
9+
10+
# contentstack-cli-content-type
11+
12+
## Repository role
13+
14+
npm package `contentstack-cli-content-type`: a **Contentstack CLI** (`csdx`) plugin that reads Content Type metadata from a stack—list, field details, audit log lines, version or cross-stack comparison, and stack content-model diagrams.
15+
16+
## Code layout
17+
18+
| Area | Path |
19+
|------|------|
20+
| Command classes (oclif) | `src/commands/content-type/*.ts` |
21+
| Shared base | `src/core/command.ts``ContentTypeCommand` extends `@contentstack/cli-command` `Command` |
22+
| Core output / logic | `src/core/content-type/*.ts` |
23+
| HTTP client (axios CMA) | `src/core/contentstack/client.ts`, `src/core/contentstack/error.ts` |
24+
| Stack / CT fetch helpers | `src/utils/index.ts` (uses Management SDK from `@contentstack/cli-utilities`) |
25+
| Types | `src/types/index.ts` |
26+
| Config (pagination limits) | `src/config/index.ts` |
27+
28+
Commands **parse flags**, call **`setup(flags)`** (see below), build **`managementSDKClient`**, then call utils + core builders. See [references/architecture.md](references/architecture.md) and [references/commands.md](references/commands.md).
29+
30+
## Authentication and stack identity
31+
32+
1. `authenticationHandler.getAuthDetails()`; must have **access token** or command exits with `auth:login` message (`exit: 2`).
33+
2. User must pass **either** a **management token alias** (`-a` / `--alias` or `--token-alias`) **or** **stack API key** (`-k` / `--stack-api-key`) or deprecated `--stack` (maps to stack key). If neither: error and `process.exit(1)` (message references “token alias or stack UID”).
34+
3. Token alias: `getToken(alias)``apiKey` from token; warns if token type is not `management`.
35+
4. `ContentTypeCommand` constructs **`ContentstackClient(this.cmaHost, authToken)`** for REST calls that use `api_key` in headers.
36+
37+
**Do not log** tokens, `authorization` / `authtoken` headers, or full CLI credentials.
38+
39+
## Two ways to call APIs
40+
41+
- **Axios `ContentstackClient`**: `GET https://{cmaHost}/v3/...` with default headers `authorization` (if Bearer) or `authtoken`, plus per-request `headers: { api_key }`. Used for audit logs and references. Errors → `ContentstackError` via `buildError`.
42+
- **Management SDK** (`managementSDKClient({ host, 'X-CS-CLI': ... })`): stack fetch, content types, global fields, content type by version—see `src/utils/index.ts`.
43+
44+
## Build and CLI metadata
45+
46+
From `package.json`:
47+
48+
- **`prepack`**: `rm -rf lib && tsc -b && oclif manifest && oclif readme` — publishable `lib/`, manifest, and README command docs.
49+
- **`version`**: `oclif readme && git add README.md`.
50+
51+
After changing commands, flags, or descriptions, run the appropriate script so **README** and **oclif.manifest.json** stay in sync.
52+
53+
## Short command names (csdx)
54+
55+
`package.json``csdxConfig.shortCommandName`:
56+
57+
| Command id | Short name |
58+
|------------|------------|
59+
| `content-type:audit` | CTAUDIT |
60+
| `content-type:compare` | CTCMP |
61+
| `content-type:compare-remote` | CTCMP-R |
62+
| `content-type:details` | CTDET |
63+
| `content-type:diagram` | CTDIAG |
64+
| `content-type:list` | CTLS |
65+
66+
## Further reading
67+
68+
- [references/architecture.md](references/architecture.md) — command → core mapping, auth flow, CMA shape.
69+
- [references/commands.md](references/commands.md) — flags, UX notes, files to edit per command.

0 commit comments

Comments
 (0)