Skip to content
Open
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
22 changes: 22 additions & 0 deletions .cursor/rules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Cursor rules

Context-aware guidance for developing `@contentstack/cli-cm-regex-validate` (Contentstack CLI oclif plugin).

## Rules overview

| File | Scope |
|------|--------|
| `dev-workflow.md` | Core workflow, validation commands, links to skills (always applied) |
| `typescript.mdc` | TypeScript and ESLint conventions |
| `testing.mdc` | Jest + ts-jest tests |
| `oclif-commands.mdc` | Command classes under `src/commands/` |
| `contentstack-cli.mdc` | Utilities under `src/utils/` (SDK, safe-regex, output) |

## How rules apply

- `dev-workflow.md` uses `alwaysApply: true` and broad globs so it loads for most edits.
- `.mdc` rules load when you work in matching paths (see each file’s `globs`).

## Manual references in chat

You can mention rules by context, for example: TypeScript guidance when editing `src/**/*.ts`, testing patterns when editing `**/*.test.ts`.
32 changes: 32 additions & 0 deletions .cursor/rules/contentstack-cli.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
description: "Contentstack Management SDK and regex-validation utilities"
globs: ["**/utils/*.ts"]
alwaysApply: false
---

# Contentstack CLI utilities (this plugin)

## Management client

- Create client with `contentstackSdk.client` and `ContentstackConfig` (`host` from command `cmaHost`).
- Optional `early_access` from `configHandler.get('earlyAccessHeaders')` when configured.
- Obtain stack with `api_key` and `management_token` from token details.

## Stack processing

- Query content types and/or global fields with `.query({}).find()` (see `process-stack.ts`).
- Use `cli.action.start` / `cli.action.stop` from `cli-ux` for timed progress messages.

## Regex validation

- Walk schema recursively in `safe-regex.ts`: handle `group`, `global_field`, `blocks`, and nested `schema` arrays.
- Evaluate `format` fields with the `safe-regex` package; collect invalid patterns into rows for CSV and summary table.

## Output

- Write CSV with `jsonexport`; render summary table with `cli-table3`; print via `cliux` / `sanitizePath` from `@contentstack/cli-utilities` for paths.
- Default results directory is resolved relative to compiled output; optional `-f` / `--filePath` overrides the directory.

## Security

- Never log management tokens or API keys. Errors should use messages from `messages/index.json`.
43 changes: 43 additions & 0 deletions .cursor/rules/dev-workflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
description: "Core development workflow for cli-cm-regex-validate - always applied"
globs: ["**/*.ts", "**/*.js", "**/*.json"]
alwaysApply: true
---

# Development workflow

## Quick reference

Detailed patterns live in project skills:

- `@skills/testing` — Jest tests, mocks, fixtures under `test/data/`
- `@skills/contentstack-cli` — Command flow, Management SDK, `safe-regex`, CSV output
- `@skills/code-review` — PR and release checklist

## Validation commands

- `npm test` — Jest (`jest.config.ts`, ts-jest). This is the canonical test runner; CI uses it in `.github/workflows/unit-tests.yml`.
- `npm run posttest` — ESLint on `.ts` files (same as running eslint after tests).

## Local hooks

If Husky is installed, pre-commit may run Talisman (secrets) and Snyk. Use `SKIP_HOOK=1` only when you understand the bypass.

## TDD (recommended)

1. **Red** — Add or change a failing test in `test/utils/` (or add a fixture in `test/data/`).
2. **Green** — Minimal change in `src/` to pass.
3. **Refactor** — Keep tests green; avoid drive-by refactors outside the task.

## Repository layout

- `src/commands/` — oclif commands (this plugin: `cm/stacks/validate-regex`)
- `src/utils/` — Shared logic (connect stack, process stack, safe-regex, output, prompts)
- `messages/index.json` — User-facing strings for the command
- `test/utils/` — Jest suites mirroring utils
- `test/data/` — JSON fixtures for schema and expected outputs

## Before merging

- Tests pass (`npm test`).
- Lint clean (`npm run posttest` or eslint as configured in `package.json`).
31 changes: 31 additions & 0 deletions .cursor/rules/oclif-commands.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
description: "oclif command patterns for Contentstack CLI plugin commands"
globs: ["**/commands/**/*.ts"]
alwaysApply: false
---

# OCLIF command standards

## Base class

- Commands extend `Command` from `@contentstack/cli-command` (see `src/commands/cm/stacks/validate-regex.ts`).

## Flags

- Build flags with `flags` from `@contentstack/cli-utilities` (e.g. `flags.string`, `flags.boolean`, `flags.help`).
- Keep descriptions aligned with `messages/index.json` under `validateRegex.command` where applicable.

## Run flow

1. `await this.parse(CommandClass)` to get flags.
2. Prompt for missing alias or module selection via `src/utils/interactive.ts` when needed.
3. Resolve token with `this.getToken(alias)`; handle failure with `this.error(..., { ref: ... })` using message keys from `messages/index.json`.
4. Delegate stack work to `src/utils/connect-stack.ts` (and downstream utils).

## User messages

- Centralize copy in `messages/index.json`; avoid hard-coded user strings in the command except where unavoidable.

## Examples

- Maintain `static examples` with realistic `csdx cm:stacks:validate-regex` invocations.
32 changes: 32 additions & 0 deletions .cursor/rules/testing.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
description: "Jest and ts-jest testing patterns for cli-cm-regex-validate"
globs: ["**/*.test.ts", "**/__tests__/**/*.ts"]
alwaysApply: false
---

# Testing standards

## Runner

- **Jest** with **ts-jest** (`jest.config.ts`). Do not document Mocha/Chai/Sinon as the primary stack for this repository.

## Conventions

- Test files live under `test/utils/` and mirror `src/utils/` where applicable.
- Use `describe` / `test` (or `it`) with clear behavior-focused names.
- Prefer `beforeEach(() => jest.restoreAllMocks())` or `jest.clearAllMocks()` when tests share mocks.

## Mocking

- Mock external I/O: `@contentstack/management`, `fs`, `cli-ux`, `@contentstack/cli-utilities` as needed.
- Use `jest.spyOn` for targeted spies; `jest.mock` for module substitution.
- Do not call real Contentstack APIs in unit tests.

## Assertions

- Prefer `toHaveBeenCalled` / `toHaveBeenCalledWith` over deprecated Jest matchers.
- Use fixture JSON from `test/data/` via `require` for documents and expected invalid-regex output.

## Fixtures

- Keep schema samples and expected arrays in `test/data/*.json` to avoid huge inline objects in tests.
31 changes: 31 additions & 0 deletions .cursor/rules/typescript.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
description: "TypeScript and ESLint conventions for cli-cm-regex-validate"
globs: ["**/*.ts", "**/*.tsx"]
alwaysApply: false
---

# TypeScript standards

## Compiler

- Project uses `strict: true` in `tsconfig.json` (root `src/` only for emit).
- Prefer explicit types on public functions and command flags over untyped `any` where practical.

## ESLint (`.eslintrc`)

- Extends `eslint-config-oclif` and `eslint-config-oclif-typescript`.
- Single quotes; no semicolons; `object-curly-spacing: never`.
- `require()` for JSON such as `messages/index.json` is allowed (`@typescript-eslint/no-require-imports` is off).

## Imports

- ES modules for TypeScript sources; `require` is acceptable for JSON message bundles and legacy interop per eslint rules.

## Naming

- Files: kebab-case (e.g. `connect-stack.ts`, `validate-regex.ts`).
- Classes: PascalCase. Functions and variables: camelCase.

## Error handling

- Surface user-facing errors via `this.error()` in commands or localized strings from `messages/index.json` in utilities.
10 changes: 10 additions & 0 deletions .cursor/skills/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Project skills

Authoritative skill packages for this repository live under **`skills/`** at the repo root.

- `skills/README.md` — index and quick reference
- `skills/testing/` — Jest patterns and references
- `skills/contentstack-cli/` — command and SDK patterns for regex validation
- `skills/code-review/` — PR review checklist

Use `@skills/<name>` in Cursor or other agents to point at these folders.
10 changes: 8 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
fileignoreconfig:
- filename: package-lock.json
checksum: 98330174c261d1793f7e44c1889aea8c6bc1f6dfaa9a5cb4f58ad2c402f4db06
- filename: package-lock.json
checksum: 3f663322d950acc49b7e8899ca353456b1e7ac6277ac36fdfcac813644fb07d7
- filename: .cursor/rules/dev-workflow.md
checksum: 9912be426cb15077a67b81bd5801f2a65d367e30204d278c6814ebb1d74661ba
- filename: skills/code-review/references/code-review-checklist.md
checksum: 8bc8e53a9775258ddfadb40f9a6f415508d87aa9c70c95ebf748737e1ef7dbee
- filename: skills/contentstack-cli/references/contentstack-patterns.md
checksum: 3e3f445d01c67577dc91b1ba6ee27dcd1ffc1e907b2fbf33ce9b2905eaba239a
version: ""
41 changes: 41 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# cli-cm-regex-validate

`@contentstack/cli-cm-regex-validate` is a **Contentstack CLI** oclif plugin with a single command, **`csdx cm:stacks:validate-regex`**, which scans content types and/or global fields in a stack for regex `format` values that fail the `safe-regex` check, then writes results to CSV and prints a summary table. User-facing copy lives in `messages/index.json`.

## Layout

| Area | Path |
|------|------|
| Command | `src/commands/cm/stacks/validate-regex.ts` |
| Utils | `src/utils/` (`connect-stack`, `process-stack`, `safe-regex`, `generate-output`, `interactive`) |
| Messages | `messages/index.json` |
| Tests | `test/utils/*.test.ts` |
| Fixtures | `test/data/*.json` |

## Workflow

- Run **`npm test`** (Jest + ts-jest) before pushing; CI uses the same in `.github/workflows/unit-tests.yml`.
- Run ESLint after tests via **`npm run posttest`** (or your team’s eslint invocation from `package.json`).

## Naming

- Source files: kebab-case.
- Tests: describe behavior clearly (what should happen under which condition).

## Universal skills (any agent)

- `@skills/testing` — Jest mocks, fixtures, no live API calls
- `@skills/contentstack-cli` — SDK flow, schema recursion, `safe-regex`, output
- `@skills/code-review` — PR checklist (security, packaging, CI, messages)

## Cursor rules (IDE)

For file-scoped guidance, Cursor loads rules under `.cursor/rules/`. You can reference them in chat by intent, for example:

- TypeScript and ESLint conventions — `typescript.mdc`
- Jest tests — `testing.mdc`
- Command class — `oclif-commands.mdc`
- Utils (SDK, safe-regex, output) — `contentstack-cli.mdc`
- Dev workflow — `dev-workflow.md` (always applied)

See `.cursor/rules/README.md` for the full index.
Loading
Loading