Skip to content

Commit 99fee1c

Browse files
refactor: enhance documentation for Apps CLI and remove obsolete files
1 parent aefa70f commit 99fee1c

9 files changed

Lines changed: 183 additions & 138 deletions

File tree

.talismanrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
fileignoreconfig:
22
- filename: pnpm-lock.yaml
33
checksum: e5b5f8ab64f4f27a1483e426cc01d7388482263e1d6fe3baf1caafcf2878ebb2
4+
- filename: skills/framework/SKILL.md
5+
checksum: c5746de64b1e7d1df051c4337de5eb32de6a4c85c7297aa408838d304bb2d771
46
version: '1.0'

AGENTS.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,18 @@ CI: [.github/workflows/unit-test.yml](.github/workflows/unit-test.yml) and other
3535
| Skill | Path | What it covers |
3636
| --- | --- | --- |
3737
| Development workflow | [skills/dev-workflow/SKILL.md](skills/dev-workflow/SKILL.md) | pnpm commands, CI, TDD expectations, PR checklist |
38-
| Contentstack CLI | [skills/contentstack-cli/SKILL.md](skills/contentstack-cli/SKILL.md) | Plugin commands, OCLIF, Contentstack APIs |
39-
| Framework | [skills/framework/SKILL.md](skills/framework/SKILL.md) | Utilities, config, logging, errors |
38+
| Contentstack CLI | [skills/contentstack-cli/SKILL.md](skills/contentstack-cli/SKILL.md) | Plugin commands, OCLIF, Contentstack APIs (incl. `app:*` / `@contentstack/apps-cli`) |
39+
| Framework | [skills/framework/SKILL.md](skills/framework/SKILL.md) | Utilities, config, logging, errors (incl. Developer Hub SDK, manifests, GraphQL) |
4040
| Testing | [skills/testing/SKILL.md](skills/testing/SKILL.md) | Mocha/Chai, coverage, mocks |
4141
| Code review | [skills/code-review/SKILL.md](skills/code-review/SKILL.md) | PR review for this monorepo |
42-
| Contentstack Apps (Developer Hub) | [skills/contentstack-apps/SKILL.md](skills/contentstack-apps/SKILL.md) | Manifests, GraphQL, HTTP for `packages/contentstack-apps-cli` |
43-
| Apps CLI framework | [skills/apps-cli-framework/SKILL.md](skills/apps-cli-framework/SKILL.md) | `BaseCommand`, `AppCLIBaseCommand`, oclif flags for apps plugin |
44-
| Apps CLI TypeScript | [skills/apps-cli-typescript/SKILL.md](skills/apps-cli-typescript/SKILL.md) | TS/ESLint conventions for apps plugin |
4542

4643
## Apps CLI plugin (`@contentstack/apps-cli`)
4744

4845
- **Package path:** [packages/contentstack-apps-cli](packages/contentstack-apps-cli)
4946
- **npm name:** `@contentstack/apps-cli` (unchanged for consumers)
5047
- **Migrated from:** [contentstack/contentstack-apps-cli](https://github.com/contentstack/contentstack-apps-cli) — see [APPS-CLI-MIGRATION.md](APPS-CLI-MIGRATION.md)
5148
- **v1 / v2:** Maintain on `v1-dev` (1.x CLI deps) and `v2-dev` / `v2-beta` (2.x beta deps) branches; align `@contentstack/cli-command` and `@contentstack/cli-utilities` versions with the target CLI line.
49+
- **Docs:** OCLIF / `app:*` commands → [contentstack-cli](skills/contentstack-cli/SKILL.md#apps-cli-commands-app); SDK, manifests, GraphQL, HTTP → [framework](skills/framework/SKILL.md#apps-cli-plugin-contentstackapps-cli)
5250

5351
## Using Cursor (optional)
5452

APPS-CLI-MIGRATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pnpm --filter @contentstack/apps-cli run build
4343
pnpm --filter @contentstack/apps-cli test
4444
```
4545

46-
See [AGENTS.md](./AGENTS.md) and [skills/contentstack-apps/SKILL.md](./skills/contentstack-apps/SKILL.md) for contributor docs.
46+
See [AGENTS.md](./AGENTS.md), [skills/contentstack-cli/SKILL.md](./skills/contentstack-cli/SKILL.md#apps-cli-commands-app), and [skills/framework/SKILL.md](./skills/framework/SKILL.md#apps-cli-plugin-contentstackapps-cli) for contributor docs.
4747

4848
## Related migrations
4949

skills/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
Source of truth for detailed guidance. Read **[AGENTS.md](../../AGENTS.md)** for the skill index, then open the SKILL.md that matches your task. Each folder contains SKILL.md with YAML frontmatter (name, description).
2+
3+
**Apps CLI (`@contentstack/apps-cli`):** [contentstack-cli](contentstack-cli/SKILL.md#apps-cli-commands-app) for commands; [framework](framework/SKILL.md#apps-cli-plugin-contentstackapps-cli) for SDK, manifests, GraphQL, and HTTP.

skills/apps-cli-framework/SKILL.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

skills/apps-cli-typescript/SKILL.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

skills/contentstack-apps/SKILL.md

Lines changed: 0 additions & 48 deletions
This file was deleted.

skills/contentstack-cli/SKILL.md

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
name: contentstack-cli
3-
description: Contentstack CLI development patterns, OCLIF commands, API integration, and authentication/configuration workflows. Use when working with Contentstack CLI plugins, OCLIF commands, CLI commands, or Contentstack API integration.
3+
description: >-
4+
Contentstack CLI development patterns, OCLIF commands, API integration, and auth/config
5+
workflows. Use for CLI plugins, OCLIF commands, or API integration—including Developer
6+
Hub apps (packages/contentstack-apps-cli, app:* commands).
47
---
58

69
# Contentstack CLI Development
@@ -477,3 +480,103 @@ cliux.print('🔄 Processing...', { color: 'blue' });
477480
// ... operation ...
478481
cliux.success('✅ Completed successfully');
479482
```
483+
484+
## Apps CLI commands (`app:*`)
485+
486+
Package: **`packages/contentstack-apps-cli`** (`@contentstack/apps-cli`). SDK, config, HTTP, manifests, GraphQL: [framework](../framework/SKILL.md#apps-cli-plugin-contentstackapps-cli).
487+
488+
### Command layout
489+
490+
| Path | Command id | Purpose |
491+
| --- | --- | --- |
492+
| `src/commands/app/index.ts` | `app` | Topic help |
493+
| `src/commands/app/create.ts` | `app:create` | Create app + optional boilerplate |
494+
| `src/commands/app/get.ts` | `app:get` | Fetch app details |
495+
| `src/commands/app/update.ts` | `app:update` | Update from manifest |
496+
| `src/commands/app/delete.ts` | `app:delete` | Delete from marketplace |
497+
| `src/commands/app/install.ts` | `app:install` | Install on stack |
498+
| `src/commands/app/reinstall.ts` | `app:reinstall` | Reinstall on stack |
499+
| `src/commands/app/uninstall.ts` | `app:uninstall` | Uninstall (factory + strategy) |
500+
| `src/commands/app/deploy.ts` | `app:deploy` | Deploy (Launch / custom hosting) |
501+
502+
OCLIF topic: `app` (`oclif.topics.app` in `package.json`). Short names in `csdxConfig.shortCommandName` (e.g. `app:create``APCRT`).
503+
504+
### Base command hierarchy
505+
506+
```typescript
507+
import { BaseCommand } from "../../base-command";
508+
import { AppCLIBaseCommand } from "../../app-cli-base-command";
509+
510+
// Org-level or SDK-only commands
511+
export default class AppInstall extends BaseCommand<typeof AppInstall> {
512+
static flags = { /* ... */, ...BaseCommand.baseFlags };
513+
async run() { /* this.flags, this.managementSdk, this.marketplaceAppSdk ready after init */ }
514+
}
515+
516+
// Commands that read manifest.json from cwd
517+
export default class AppUpdate extends AppCLIBaseCommand {
518+
async run() {
519+
// this.manifestData, this.manifestPath set in AppCLIBaseCommand.init
520+
}
521+
}
522+
```
523+
524+
- **`BaseCommand`** (`src/base-command.ts`) — `init()` parses flags/args, `registerConfig`, logger, `validateRegionAndAuth`, SDK init. **`baseFlags`**: `org`, `yes`. Also: `getValPrompt`, `messages` / `$t`, `catch` / `finally` (nonexistent flag → exit 2).
525+
- **`AppCLIBaseCommand`** — After `super.init()`, `getManifestData()` from `{cwd}/manifest.json`.
526+
527+
Always call `await super.init()` first in `init()` overrides.
528+
529+
### Command responsibilities
530+
531+
- **CLI layer** — static `flags` / `examples`, prompts (`cliux`, `getValPrompt`, `src/util/inquirer.ts`), `this.log`, `this.error` / exit.
532+
- **Business logic**`src/util/`, `src/factories/`, `src/strategies/`; keep `run()` small.
533+
534+
### Parse and flags
535+
536+
Parse runs inside **`BaseCommand.init`** only; do not re-parse in `run()`. After `init`, use `this.flags` and `this.args`. Inherit `BaseCommand.baseFlags` when `org` / `--yes` apply.
537+
538+
OCLIF hook: `src/hooks/init/load-chalk.ts` (registered in `package.json` `oclif.hooks.init`).
539+
540+
### Apps command example
541+
542+
```typescript
543+
export default class AppGet extends BaseCommand<typeof AppGet> {
544+
static description = "Get details of an app in developer hub";
545+
546+
static flags = {
547+
"app-uid": Flags.string({ description: "App UID" }),
548+
"app-type": Flags.string({
549+
options: ["stack", "organization"],
550+
default: "stack",
551+
}),
552+
...BaseCommand.baseFlags,
553+
};
554+
555+
async run(): Promise<void> {
556+
const { org, "app-uid": appUid } = this.flags;
557+
// Use this.marketplaceAppSdk / GraphQL / apiRequestHandler — see framework Apps CLI section
558+
this.log(this.$t(this.messages.APP_FETCH_SUCCESS), "info");
559+
}
560+
}
561+
```
562+
563+
### External config and deploy
564+
565+
- **`--config`** — JSON merged into `sharedConfig` (see `registerConfig` in `base-command.ts`). Used by create/deploy for Launch project settings.
566+
- **`--data-dir`** — Working directory for boilerplate clone and manifest paths.
567+
568+
### Errors
569+
570+
`BaseCommand.catch` handles `NonExistent flag` with exit code 2. Prefer actionable messages via `messages` / `$t` and existing util error helpers.
571+
572+
### Build and test
573+
574+
| Command | Purpose |
575+
| --- | --- |
576+
| `pnpm --filter @contentstack/apps-cli run build` | `tsc``lib/` |
577+
| `pnpm --filter @contentstack/apps-cli test` | Mocha + ESLint (`posttest`) |
578+
| `pnpm --filter @contentstack/apps-cli run test:unit:report` | Unit tests with nyc |
579+
580+
### Testing apps commands
581+
582+
Unit tests under `test/unit/commands/app/`. Use `stubAuthentication` from `test/unit/helpers/auth-stub-helper.ts` and nock Developer Hub hosts from `getDeveloperHubUrl()`. See [testing](../testing/SKILL.md) and [dev-workflow](../dev-workflow/SKILL.md).

skills/framework/SKILL.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
name: framework
3-
description: Core utilities, configuration, logging, and framework patterns for CLI development. Use when working with utilities, configuration management, error handling, or core framework components.
3+
description: >-
4+
Core utilities, configuration, logging, and framework patterns for CLI development.
5+
Use when working with utilities, config, errors, or core framework components—including
6+
the Apps CLI plugin (packages/contentstack-apps-cli).
47
---
58

69
# Framework Patterns
@@ -402,3 +405,70 @@ export class MyService {
402405
const service = new MyService(configHandler, log, httpClient);
403406
await service.execute();
404407
```
408+
409+
## Apps CLI plugin (`@contentstack/apps-cli`)
410+
411+
Package: **`packages/contentstack-apps-cli`**. Developer Hub–specific patterns extend the utilities above. OCLIF commands: [contentstack-cli](../contentstack-cli/SKILL.md#apps-cli-commands-app). Migration: [APPS-CLI-MIGRATION.md](../../APPS-CLI-MIGRATION.md).
412+
413+
### SDK clients in `BaseCommand`
414+
415+
Apps commands use **`BaseCommand`** (`src/base-command.ts`), which initializes three clients in `init()`:
416+
417+
| Client | Initiator | Host | Use |
418+
| --- | --- | --- | --- |
419+
| `managementSdk` | `managementSDKInitiator` / `managementSDKClient` | `this.cmaHost` | Standard CMA |
420+
| `managementAppSdk` | `managementSDKClient` | `developerHubBaseUrl` | Developer Hub CMA |
421+
| `marketplaceAppSdk` | `marketplaceSDKInitiator` / `marketplaceSDKClient` | `developerHubBaseUrl` | Marketplace / app CRUD |
422+
423+
Resolve Developer Hub host via `getDeveloperHubUrl()` in `src/util/inquirer.ts` when region config does not supply `developerHubBaseUrl`.
424+
425+
### Apps-specific configuration
426+
427+
- **`src/config/index.ts`**`defaultAppFileName` (`manifest`), `defaultAppName`, `manifestPath` (template), `developerHubBaseUrl`, `appBoilerplateGithubUrl`, `boilerplatesUrl`.
428+
- **`src/config/manifest.json`** — Reference manifest schema for create/update flows.
429+
- **`registerConfig()`** on `BaseCommand` — merges external JSON from `--config` into `sharedConfig` (omits `manifestPath`, `boilerplateName`, `developerHubUrls`).
430+
- **`sharedConfig`**`projectBasePath` defaults to `process.cwd()`; passed to the local `Logger` (`src/util/log.ts`), which binds `this.log` on commands.
431+
432+
### Manifest and app data
433+
434+
- Typings: **`src/types/`** (e.g. `AppManifest` in `src/types/app.ts`).
435+
- On-disk file: `{cwd}/manifest.json` via `config.defaultAppFileName`.
436+
- Manifest commands extend **`AppCLIBaseCommand`** (`src/app-cli-base-command.ts`), which loads `manifestData` after `super.init()`.
437+
438+
### HTTP for Developer Hub
439+
440+
- **`src/util/api-request-handler.ts`**`apiRequestHandler({ orgUid, method, url, queryParams, payload })`; wraps `HttpClient` with `organization_uid` and `authtoken` from `configHandler`; uses `formatErrors` from `error-helper.ts`. Do not scatter raw HTTP in commands.
441+
- **`src/util/inquirer.ts`**`getDeveloperHubUrl()`, org/app/stack prompts; nock this host in unit tests.
442+
- **`src/util/common-utils.ts`** — App CRUD helpers, boilerplate download, zip handling.
443+
444+
### GraphQL
445+
446+
- **`src/graphql/queries.ts`** — e.g. `projectsQuery` for Launch deploy (`gql` from `@contentstack/cli-launch`). Add new queries here; align with Developer Hub / Launch APIs used by deploy and install flows.
447+
448+
### Auth guard
449+
450+
`validateRegionAndAuth()` runs in `init`: if a region is set, `isAuthenticated()` must pass or the command exits with `CLI_APP_CLI_LOGIN_FAILED`. Unit tests stub via `test/unit/helpers/auth-stub-helper.ts` (`stubAuthentication`); never require real credentials in tests.
451+
452+
### Code layout (business logic)
453+
454+
Keep commands thin; put logic in:
455+
456+
- `src/util/` — shared helpers (`common-utils`, `inquirer`, `fs`, `api-request-handler`)
457+
- `src/factories/` — object construction (e.g. uninstall flows)
458+
- `src/strategies/` — variant behavior (e.g. uninstall-all vs uninstall-selected)
459+
- `src/types/``AppManifest` and related typings
460+
- `src/graphql/queries.ts` — Developer Hub / Launch GraphQL (`@contentstack/cli-launch` `gql`)
461+
462+
### User-visible strings
463+
464+
Apps plugin uses local **`messages`** and **`$t`** from `src/messages/index.ts` (not only `messageHandler` from utilities). Reuse `commonMsg` for shared flag descriptions (`org`, `yes`).
465+
466+
### Rate limits and retries
467+
468+
Follow existing error formatting in `error-helper.ts` and patterns in `api-request-handler` / `common-utils` rather than blocking the CLI without user feedback.
469+
470+
### TypeScript and lint (Apps CLI)
471+
472+
- **`packages/contentstack-apps-cli/tsconfig.json`**`strict: true`, `noUnusedLocals`, `noUnusedParameters`, `composite: true`, `rootDir` `src/`, `outDir` `lib/`.
473+
- **`.eslintrc`** — lints `src/` only (`lib/**`, `test/**` ignored).
474+
- Naming: kebab-case files, PascalCase classes, camelCase functions, `SCREAMING_SNAKE_CASE` for module-level constants.

0 commit comments

Comments
 (0)