From dec6f22b3313c0a25c726ac767cba0b0c082119f Mon Sep 17 00:00:00 2001 From: raj pandey Date: Fri, 15 May 2026 11:53:52 +0530 Subject: [PATCH 01/45] enhc: use curated official seed stacks instead of GitHub search --- .talismanrc | 2 + packages/contentstack-seed/README.md | 6 +- .../src/seed/github/client.ts | 13 +- packages/contentstack-seed/src/seed/index.ts | 22 +-- .../contentstack-seed/src/seed/interactive.ts | 35 +++++ .../contentstack-seed/src/seed/seed-stacks.ts | 30 ++++ .../test/commands/cm/stacks/seed.test.ts | 34 +++-- .../test/seed/contentstack/client.test.ts | 7 +- .../test/seed/github/client.test.ts | 75 ++-------- .../test/seed/importer.test.ts | 29 ++-- .../contentstack-seed/test/seed/index.test.ts | 140 ++++++++++++++++++ .../test/seed/interactive.test.ts | 85 ++++++++++- .../test/seed/seed-stacks.test.ts | 49 ++++++ 13 files changed, 398 insertions(+), 129 deletions(-) create mode 100644 packages/contentstack-seed/src/seed/seed-stacks.ts create mode 100644 packages/contentstack-seed/test/seed/index.test.ts create mode 100644 packages/contentstack-seed/test/seed/seed-stacks.test.ts diff --git a/.talismanrc b/.talismanrc index 2d965db3f..74fb868ca 100644 --- a/.talismanrc +++ b/.talismanrc @@ -31,4 +31,6 @@ fileignoreconfig: checksum: 163c7e519561f2c1f473f6f0c5303a2a47c9f5c231b638cd90782c37eaa4859e - filename: packages/contentstack-branches/README.md checksum: 2978e9a9c151cbbafb5dd542edf6815ccec12172ae4ca114a6c4e5e73a85a2b5 + - filename: packages/contentstack-seed/README.md + checksum: ee6667dc5ce3a11517663ed19c090cac9ddfadf562a117b1f165220eb61cdc2b version: '1.0' diff --git a/packages/contentstack-seed/README.md b/packages/contentstack-seed/README.md index bafa0e2cf..75faf55f9 100644 --- a/packages/contentstack-seed/README.md +++ b/packages/contentstack-seed/README.md @@ -1,11 +1,11 @@ ## Description The “seed” command in Contentstack CLI allows users to import content to your stack, from Github repositories. It's an effective command that can help you to migrate content to your stack with minimal steps. -To import content to your stack, you can choose from the following two sources: +To import content to your stack, you can use either of the following: -**Contentstack’s organization**: In this organization, we have provided sample content, which you can import directly to your stack using the seed command. +**Curated official stacks**: When you run the seed command without a full `owner/repo` on `--repo`, the CLI offers a fixed list of official Contentstack seed repositories on GitHub (no GitHub search API). -**Github’s repository**: You can import content available on Github’s repository belonging to an organization or an individual. +**Any GitHub repository**: You can also import content from another GitHub repository by passing `--repo` in `owner/repository` form (organization, user, or enterprise account). ## Commands diff --git a/packages/contentstack-seed/src/seed/github/client.ts b/packages/contentstack-seed/src/seed/github/client.ts index 066913fb7..6ce3d4717 100644 --- a/packages/contentstack-seed/src/seed/github/client.ts +++ b/packages/contentstack-seed/src/seed/github/client.ts @@ -9,7 +9,6 @@ import GithubError from './error'; export default class GitHubClient { readonly gitHubRepoUrl: string; - readonly gitHubUserUrl: string; private readonly httpClient: HttpClient; static parsePath(path?: string) { @@ -30,21 +29,11 @@ export default class GitHubClient { return result; } - constructor(public username: string, defaultStackPattern: string) { + constructor(public username: string) { this.gitHubRepoUrl = `https://api.github.com/repos/${username}`; - this.gitHubUserUrl = `https://api.github.com/search/repositories?q=org%3A${username}+in:name+${defaultStackPattern}`; this.httpClient = HttpClient.create(); } - async getAllRepos(count = 100) { - try { - const response = await this.httpClient.get(`${this.gitHubUserUrl}&per_page=${count}`); - return response.data.items; - } catch (error) { - throw this.buildError(error); - } - } - async getLatest(repo: string, destination: string): Promise { const tarballUrl = await this.getLatestTarballUrl(repo); const releaseStream = await this.streamRelease(tarballUrl); diff --git a/packages/contentstack-seed/src/seed/index.ts b/packages/contentstack-seed/src/seed/index.ts index 31e6fb9aa..9ae937e20 100644 --- a/packages/contentstack-seed/src/seed/index.ts +++ b/packages/contentstack-seed/src/seed/index.ts @@ -4,17 +4,17 @@ import { cliux } from '@contentstack/cli-utilities'; import * as importer from '../seed/importer'; import ContentstackClient, { Organization, Stack } from '../seed/contentstack/client'; import { + inquireOfficialSeedStack, inquireOrganization, inquireProceed, - inquireRepo, inquireStack, InquireStackResponse, } from '../seed/interactive'; import GitHubClient from './github/client'; import GithubError from './github/error'; +import { OFFICIAL_SEED_STACKS } from './seed-stacks'; const DEFAULT_OWNER = 'contentstack'; -const DEFAULT_STACK_PATTERN = 'stack-'; export const ENGLISH_LOCALE = 'en-us'; @@ -38,7 +38,7 @@ export default class ContentModelSeeder { private readonly parent: any = null; private readonly csClient: ContentstackClient; - private readonly ghClient: GitHubClient; + private ghClient: GitHubClient; private readonly _options: ContentModelSeederOptions; @@ -61,7 +61,7 @@ export default class ContentModelSeeder { this.managementToken = options.managementToken; this.csClient = new ContentstackClient(options.cmaHost, limit); - this.ghClient = new GitHubClient(this.ghUsername, DEFAULT_STACK_PATTERN); + this.ghClient = new GitHubClient(this.ghUsername); } async run() { @@ -233,15 +233,9 @@ export default class ContentModelSeeder { } async inquireGitHubRepo() { - try { - const allRepos = await this.ghClient.getAllRepos(); - const stackRepos = allRepos.filter((repo: any) => repo.name.startsWith(DEFAULT_STACK_PATTERN)); - const repoResponse = await inquireRepo(stackRepos); - this.ghRepo = repoResponse.choice; - } catch (error) { - cliux.error( - `Unable to find any Stack repositories within the '${this.ghUsername}' GitHub account. Please re-run this command with a GitHub repository in the 'account/repo' format. You can also re-run the command without arguments to pull from the official Stack list.`, - ); - } + const selected = await inquireOfficialSeedStack(OFFICIAL_SEED_STACKS); + this.ghUsername = selected.owner; + this.ghRepo = selected.repo; + this.ghClient = new GitHubClient(this.ghUsername); } } \ No newline at end of file diff --git a/packages/contentstack-seed/src/seed/interactive.ts b/packages/contentstack-seed/src/seed/interactive.ts index af10584ac..35e9733fc 100644 --- a/packages/contentstack-seed/src/seed/interactive.ts +++ b/packages/contentstack-seed/src/seed/interactive.ts @@ -1,6 +1,11 @@ import inquirer from 'inquirer'; +import { cliux } from '@contentstack/cli-utilities'; + +import { OfficialSeedStack } from './seed-stacks'; import { Organization, Stack } from './contentstack/client'; +export const OFFICIAL_SEED_STACK_SELECTION_MESSAGE = 'Select a stack to import'; + export interface InquireStackResponse { isNew: boolean; name: string | null; @@ -8,6 +13,36 @@ export interface InquireStackResponse { api_key: string | null; } +export async function inquireOfficialSeedStack( + stacks: OfficialSeedStack[], +): Promise<{ owner: string; repo: string }> { + if (!stacks || stacks.length === 0) { + throw new Error('Precondition failed: No official seed stacks configured.'); + } + + const choices = stacks.map((s) => ({ + name: s.displayName, + value: s, + })); + + const response = await inquirer.prompt([ + { + type: 'list', + name: 'stack', + message: OFFICIAL_SEED_STACK_SELECTION_MESSAGE, + choices: [...choices, 'Exit'], + }, + ]); + + if (response.stack === 'Exit') { + cliux.print('Exiting...'); + throw new Error('Exit'); + } + + const selected = response.stack as OfficialSeedStack; + return { owner: selected.owner, repo: selected.repo }; +} + export async function inquireRepo(repos: any[]): Promise<{ choice: string }> { if (!repos || repos.length === 0) throw new Error('Precondition failed: No Repositories found.'); diff --git a/packages/contentstack-seed/src/seed/seed-stacks.ts b/packages/contentstack-seed/src/seed/seed-stacks.ts new file mode 100644 index 000000000..399bccff2 --- /dev/null +++ b/packages/contentstack-seed/src/seed/seed-stacks.ts @@ -0,0 +1,30 @@ +export const OFFICIAL_SEED_OWNER = 'contentstack'; + +export interface OfficialSeedStack { + displayName: string; + owner: string; + repo: string; +} + +export const OFFICIAL_SEED_STACKS: OfficialSeedStack[] = [ + { + displayName: 'Kickstart stack seed', + owner: OFFICIAL_SEED_OWNER, + repo: 'kickstart-stack-seed', + }, + { + displayName: 'Kickstart Veda', + owner: OFFICIAL_SEED_OWNER, + repo: 'kickstart-veda-seed', + }, + { + displayName: 'Compass starter stack', + owner: OFFICIAL_SEED_OWNER, + repo: 'compass-starter-stack', + }, + { + displayName: 'Starter app', + owner: OFFICIAL_SEED_OWNER, + repo: 'stack-starter-app', + }, +]; diff --git a/packages/contentstack-seed/test/commands/cm/stacks/seed.test.ts b/packages/contentstack-seed/test/commands/cm/stacks/seed.test.ts index d5a3a9811..c3102246f 100644 --- a/packages/contentstack-seed/test/commands/cm/stacks/seed.test.ts +++ b/packages/contentstack-seed/test/commands/cm/stacks/seed.test.ts @@ -4,18 +4,28 @@ import { isAuthenticated, configHandler, cliux } from '@contentstack/cli-utiliti // Mock dependencies jest.mock('../../../../src/seed/index'); -jest.mock('@contentstack/cli-utilities', () => ({ - ...jest.requireActual('@contentstack/cli-utilities'), - isAuthenticated: jest.fn(), - configHandler: { - get: jest.fn(), - }, - cliux: { - print: jest.fn(), - loader: jest.fn(), - error: jest.fn(), - }, -})); +jest.mock('@contentstack/cli-utilities', () => { + const { Flags, Command } = require('@oclif/core'); + return { + flags: Flags, + Command, + CLIError: class CLIError extends Error { + constructor(message: string) { + super(message); + this.name = 'CLIError'; + } + }, + isAuthenticated: jest.fn(), + configHandler: { + get: jest.fn(), + }, + cliux: { + print: jest.fn(), + loader: jest.fn(), + error: jest.fn(), + }, + }; +}); describe('SeedCommand', () => { let mockSeeder: jest.Mocked; diff --git a/packages/contentstack-seed/test/seed/contentstack/client.test.ts b/packages/contentstack-seed/test/seed/contentstack/client.test.ts index 880db27e6..dfe46a04e 100644 --- a/packages/contentstack-seed/test/seed/contentstack/client.test.ts +++ b/packages/contentstack-seed/test/seed/contentstack/client.test.ts @@ -1,12 +1,13 @@ // Mock utilities before importing anything that uses them jest.mock('@contentstack/cli-utilities', () => { - const actual = jest.requireActual('@contentstack/cli-utilities'); + const { Flags } = require('@oclif/core'); return { - ...actual, + managementSDKClient: jest.fn(), configHandler: { get: jest.fn().mockReturnValue(null), }, - managementSDKClient: jest.fn(), + ContentstackClient: jest.fn(), + flags: Flags, }; }); diff --git a/packages/contentstack-seed/test/seed/github/client.test.ts b/packages/contentstack-seed/test/seed/github/client.test.ts index 59cca5f18..05c8bd910 100644 --- a/packages/contentstack-seed/test/seed/github/client.test.ts +++ b/packages/contentstack-seed/test/seed/github/client.test.ts @@ -1,16 +1,9 @@ -// Mock utilities before importing anything that uses them -jest.mock('@contentstack/cli-utilities', () => { - const actual = jest.requireActual('@contentstack/cli-utilities'); - return { - ...actual, - configHandler: { - get: jest.fn().mockReturnValue(null), - }, - HttpClient: { - create: jest.fn(), - }, - }; -}); +// Shallow mock: avoid jest.requireActual (pulls uuid ESM in Jest without extra transform config). +jest.mock('@contentstack/cli-utilities', () => ({ + HttpClient: { + create: jest.fn(), + }, +})); // Mock dependencies jest.mock('tar'); @@ -30,7 +23,6 @@ import { Stream } from 'stream'; describe('GitHubClient', () => { let mockHttpClient: any; let githubClient: GitHubClient; - const DEFAULT_STACK_PATTERN = 'stack-'; beforeEach(() => { jest.clearAllMocks(); @@ -44,16 +36,14 @@ describe('GitHubClient', () => { (HttpClient.create as jest.Mock) = jest.fn().mockReturnValue(mockHttpClient); - githubClient = new GitHubClient('testuser', DEFAULT_STACK_PATTERN); + githubClient = new GitHubClient('testuser'); }); describe('constructor', () => { - it('should initialize with username and default stack pattern', () => { - const client = new GitHubClient('testuser', DEFAULT_STACK_PATTERN); + it('should initialize with username', () => { + const client = new GitHubClient('testuser'); expect(client.username).toBe('testuser'); expect(client.gitHubRepoUrl).toBe('https://api.github.com/repos/testuser'); - expect(client.gitHubUserUrl).toContain('testuser'); - expect(client.gitHubUserUrl).toContain(DEFAULT_STACK_PATTERN); }); it('should create HttpClient instance', () => { @@ -88,53 +78,6 @@ describe('GitHubClient', () => { }); - describe('getAllRepos', () => { - it('should fetch all repositories successfully', async () => { - const mockRepos = { - data: { - items: [ - { name: 'stack-repo1', html_url: 'https://github.com/testuser/stack-repo1' }, - { name: 'stack-repo2', html_url: 'https://github.com/testuser/stack-repo2' }, - ], - }, - }; - - mockHttpClient.get.mockResolvedValue(mockRepos); - - const result = await githubClient.getAllRepos(); - - expect(mockHttpClient.get).toHaveBeenCalledWith( - expect.stringContaining('testuser'), - ); - expect(result).toEqual(mockRepos.data.items); - }); - - it('should handle custom count parameter', async () => { - const mockRepos = { data: { items: [] } }; - mockHttpClient.get.mockResolvedValue(mockRepos); - - await githubClient.getAllRepos(50); - - expect(mockHttpClient.get).toHaveBeenCalledWith( - expect.stringContaining('per_page=50'), - ); - }); - - it('should throw GithubError on API failure', async () => { - const mockError = { - response: { - status: 404, - statusText: 'Not Found', - data: { error_message: 'Repository not found' }, - }, - }; - - mockHttpClient.get.mockRejectedValue(mockError); - - await expect(githubClient.getAllRepos()).rejects.toThrow(GithubError); - }); - }); - describe('getLatestTarballUrl', () => { it('should fetch latest release tarball URL', async () => { const mockRelease = { diff --git a/packages/contentstack-seed/test/seed/importer.test.ts b/packages/contentstack-seed/test/seed/importer.test.ts index 1527cb8d3..def5db0de 100644 --- a/packages/contentstack-seed/test/seed/importer.test.ts +++ b/packages/contentstack-seed/test/seed/importer.test.ts @@ -1,17 +1,10 @@ -// Mock utilities before importing -jest.mock('@contentstack/cli-utilities', () => { - const actual = jest.requireActual('@contentstack/cli-utilities'); - return { - ...actual, - configHandler: { - get: jest.fn().mockReturnValue(null), - }, - }; -}); - -// Mock dependencies -jest.mock('@contentstack/cli-cm-import'); -jest.mock('@contentstack/cli-utilities'); +jest.mock('@contentstack/cli-utilities', () => ({ + configHandler: { + get: jest.fn().mockReturnValue(null), + }, + pathValidator: jest.fn((p: string) => p), + sanitizePath: jest.fn((p: string) => p), +})); import * as fs from 'fs'; import * as importer from '../../src/seed/importer'; @@ -31,9 +24,9 @@ describe('Importer', () => { beforeEach(() => { jest.clearAllMocks(); - jest.spyOn(cliUtilities, 'pathValidator').mockImplementation((p: any) => p); - jest.spyOn(cliUtilities, 'sanitizePath').mockImplementation((p: any) => p); - (ImportCommand.run as jest.Mock) = jest.fn().mockResolvedValue(undefined); + (ImportCommand.run as jest.Mock).mockResolvedValue(undefined); + (cliUtilities.pathValidator as jest.Mock).mockImplementation((p: any) => p); + (cliUtilities.sanitizePath as jest.Mock).mockImplementation((p: any) => p); // Mock fs.existsSync: stack folder exists (standard repo structure) jest.spyOn(fs, 'existsSync').mockImplementation((checkPath: fs.PathLike) => { const p = typeof checkPath === 'string' ? checkPath : checkPath.toString(); @@ -155,7 +148,7 @@ describe('Importer', () => { it('should handle import command errors', async () => { const mockError = new Error('Import failed'); - (ImportCommand.run as jest.Mock) = jest.fn().mockRejectedValue(mockError); + (ImportCommand.run as jest.Mock).mockRejectedValueOnce(mockError); await expect(importer.run(mockOptions)).rejects.toThrow('Import failed'); }); diff --git a/packages/contentstack-seed/test/seed/index.test.ts b/packages/contentstack-seed/test/seed/index.test.ts new file mode 100644 index 000000000..ce9f56ecc --- /dev/null +++ b/packages/contentstack-seed/test/seed/index.test.ts @@ -0,0 +1,140 @@ +jest.mock('../../src/seed/importer', () => ({ + run: jest.fn().mockResolvedValue(undefined), +})); + +jest.mock('@contentstack/cli-utilities', () => ({ + cliux: { + print: jest.fn(), + loader: jest.fn(), + error: jest.fn(), + }, + HttpClient: { + create: jest.fn(() => ({ + get: jest.fn(), + options: jest.fn().mockReturnThis(), + resetConfig: jest.fn(), + })), + }, + managementSDKClient: jest.fn(), + configHandler: { + get: jest.fn(), + }, + ContentstackClient: jest.fn(), + pathValidator: jest.fn((p: string) => p), + sanitizePath: jest.fn((p: string) => p), +})); + +import ContentModelSeeder from '../../src/seed/index'; +import GitHubClient from '../../src/seed/github/client'; +import * as interactive from '../../src/seed/interactive'; +import { OFFICIAL_SEED_STACKS } from '../../src/seed/seed-stacks'; + +describe('ContentModelSeeder', () => { + const baseOptions = { + parent: null, + cdaHost: 'https://cdn.contentstack.io', + cmaHost: 'https://api.contentstack.io', + gitHubPath: undefined as string | undefined, + orgUid: undefined as string | undefined, + stackUid: 'stack-api-key' as string | undefined, + stackName: undefined as string | undefined, + fetchLimit: undefined as string | undefined, + skipStackConfirmation: true, + isAuthenticated: true, + managementToken: 'management-token', + alias: undefined as string | undefined, + master_locale: 'en-us', + }; + + afterEach(() => { + jest.restoreAllMocks(); + }); + + it('does not define getAllRepos on GitHubClient', () => { + expect((GitHubClient.prototype as unknown as { getAllRepos?: unknown }).getAllRepos).toBeUndefined(); + }); + + describe('getInput when gitHubPath is incomplete', () => { + it('calls inquireOfficialSeedStack with the official catalog', async () => { + const inquireSpy = jest + .spyOn(interactive, 'inquireOfficialSeedStack') + .mockResolvedValue({ owner: 'contentstack', repo: 'stack-starter-app' }); + const makeGetSpy = jest.spyOn(GitHubClient.prototype, 'makeGetApiCall').mockResolvedValue({ + statusCode: 200, + data: {}, + } as never); + + const seeder = new ContentModelSeeder({ + ...baseOptions, + gitHubPath: undefined, + stackUid: 'stack-api-key', + managementToken: 'management-token', + }); + + await seeder.getInput(); + + expect(inquireSpy).toHaveBeenCalledTimes(1); + expect(inquireSpy).toHaveBeenCalledWith(OFFICIAL_SEED_STACKS); + expect(makeGetSpy).toHaveBeenCalledWith('stack-starter-app'); + }); + + it('rebuilds GitHub client for selected owner after official stack selection', async () => { + jest.spyOn(interactive, 'inquireOfficialSeedStack').mockResolvedValue({ + owner: 'contentstack', + repo: 'kickstart-stack-seed', + }); + jest.spyOn(GitHubClient.prototype, 'makeGetApiCall').mockResolvedValue({ + statusCode: 200, + data: {}, + } as never); + + const seeder = new ContentModelSeeder({ + ...baseOptions, + gitHubPath: 'otherorg', + stackUid: 'stack-api-key', + managementToken: 'management-token', + }); + + await seeder.getInput(); + + expect((seeder as unknown as { ghUsername: string }).ghUsername).toBe('contentstack'); + expect((seeder as unknown as { ghRepo: string }).ghRepo).toBe('kickstart-stack-seed'); + }); + + it('does not call makeGetApiCall when user exits from official stack prompt', async () => { + jest.spyOn(interactive, 'inquireOfficialSeedStack').mockRejectedValue(new Error('Exit')); + const makeGetSpy = jest.spyOn(GitHubClient.prototype, 'makeGetApiCall'); + + const seeder = new ContentModelSeeder({ + ...baseOptions, + gitHubPath: undefined, + stackUid: 'stack-api-key', + managementToken: 'management-token', + }); + + await expect(seeder.getInput()).rejects.toThrow('Exit'); + expect(makeGetSpy).not.toHaveBeenCalled(); + }); + }); + + describe('getInput when full gitHubPath is set', () => { + it('does not call inquireOfficialSeedStack', async () => { + const inquireSpy = jest.spyOn(interactive, 'inquireOfficialSeedStack'); + jest.spyOn(GitHubClient.prototype, 'makeGetApiCall').mockResolvedValue({ + statusCode: 200, + data: {}, + } as never); + + const seeder = new ContentModelSeeder({ + ...baseOptions, + gitHubPath: 'acme/custom-seed', + stackUid: 'stack-api-key', + managementToken: 'management-token', + }); + + await seeder.getInput(); + + expect(inquireSpy).not.toHaveBeenCalled(); + }); + }); +}); diff --git a/packages/contentstack-seed/test/seed/interactive.test.ts b/packages/contentstack-seed/test/seed/interactive.test.ts index f3cf43d75..b58d92fc0 100644 --- a/packages/contentstack-seed/test/seed/interactive.test.ts +++ b/packages/contentstack-seed/test/seed/interactive.test.ts @@ -1,6 +1,8 @@ -// Mock inquirer before importing anything +// Mock inquirer before importing anything. +// cli-utilities loads inquirer and calls registerPrompt; the mock must implement it. const mockInquirer = { prompt: jest.fn(), + registerPrompt: jest.fn(), }; jest.mock('inquirer', () => ({ @@ -8,14 +10,95 @@ jest.mock('inquirer', () => ({ default: mockInquirer, })); +jest.mock('@contentstack/cli-utilities', () => ({ + cliux: { + print: jest.fn(), + loader: jest.fn(), + error: jest.fn(), + }, + HttpClient: { + create: jest.fn(() => ({ + get: jest.fn(), + options: jest.fn().mockReturnThis(), + resetConfig: jest.fn(), + })), + }, + managementSDKClient: jest.fn(), + configHandler: { + get: jest.fn(), + }, + ContentstackClient: jest.fn(), +})); + import * as interactive from '../../src/seed/interactive'; import { Organization, Stack } from '../../src/seed/contentstack/client'; +import { cliux } from '@contentstack/cli-utilities'; describe('Interactive', () => { beforeEach(() => { jest.clearAllMocks(); }); + describe('inquireOfficialSeedStack', () => { + const sampleStacks = [ + { displayName: 'Alpha Stack', owner: 'contentstack', repo: 'alpha-repo' }, + { displayName: 'Beta Stack', owner: 'contentstack', repo: 'beta-repo' }, + ]; + + beforeEach(() => { + jest.spyOn(cliux, 'print').mockImplementation(() => undefined); + }); + + afterEach(() => { + jest.restoreAllMocks(); + }); + + it('should throw when catalog is empty', async () => { + await expect(interactive.inquireOfficialSeedStack([])).rejects.toThrow( + 'Precondition failed: No official seed stacks configured.', + ); + }); + + it('should prompt with list and official message', async () => { + mockInquirer.prompt = jest.fn().mockResolvedValue({ + stack: sampleStacks[0], + }); + + const result = await interactive.inquireOfficialSeedStack(sampleStacks); + + expect(mockInquirer.prompt).toHaveBeenCalledWith([ + expect.objectContaining({ + type: 'list', + name: 'stack', + message: interactive.OFFICIAL_SEED_STACK_SELECTION_MESSAGE, + }), + ]); + const promptArg = (mockInquirer.prompt as jest.Mock).mock.calls[0][0][0]; + expect(promptArg.choices).toHaveLength(3); + expect(result).toEqual({ owner: 'contentstack', repo: 'alpha-repo' }); + }); + + it('should include Exit in choices', async () => { + mockInquirer.prompt = jest.fn().mockResolvedValue({ + stack: sampleStacks[1], + }); + + await interactive.inquireOfficialSeedStack(sampleStacks); + + const promptArg = (mockInquirer.prompt as jest.Mock).mock.calls[0][0][0]; + expect(promptArg.choices).toContain('Exit'); + }); + + it('should print and throw on Exit', async () => { + mockInquirer.prompt = jest.fn().mockResolvedValue({ + stack: 'Exit', + }); + + await expect(interactive.inquireOfficialSeedStack(sampleStacks)).rejects.toThrow('Exit'); + expect(cliux.print).toHaveBeenCalledWith('Exiting...'); + }); + }); + describe('inquireRepo', () => { it('should return single repo when only one is provided', async () => { const repos = [ diff --git a/packages/contentstack-seed/test/seed/seed-stacks.test.ts b/packages/contentstack-seed/test/seed/seed-stacks.test.ts new file mode 100644 index 000000000..62e0240ce --- /dev/null +++ b/packages/contentstack-seed/test/seed/seed-stacks.test.ts @@ -0,0 +1,49 @@ +import { + OFFICIAL_SEED_OWNER, + OFFICIAL_SEED_STACKS, +} from '../../src/seed/seed-stacks'; + +describe('seed-stacks', () => { + const expectedRepos = [ + 'kickstart-stack-seed', + 'kickstart-veda-seed', + 'compass-starter-stack', + 'stack-starter-app', + ]; + + it('exports a catalog of four stacks', () => { + expect(Array.isArray(OFFICIAL_SEED_STACKS)).toBe(true); + expect(OFFICIAL_SEED_STACKS).toHaveLength(4); + }); + + it('has exact repo slugs under contentstack', () => { + const repos = OFFICIAL_SEED_STACKS.map((s) => s.repo).sort(); + expect(repos).toEqual([...expectedRepos].sort()); + }); + + it('uses contentstack as owner for every entry', () => { + for (const entry of OFFICIAL_SEED_STACKS) { + expect(entry.owner).toBe(OFFICIAL_SEED_OWNER); + } + }); + + it('has non-empty display names', () => { + for (const entry of OFFICIAL_SEED_STACKS) { + expect(entry.displayName.trim().length).toBeGreaterThan(0); + } + }); + + it('has no duplicate repo slugs', () => { + const repos = OFFICIAL_SEED_STACKS.map((s) => s.repo); + expect(new Set(repos).size).toBe(4); + }); + + it('has stable display names', () => { + expect(OFFICIAL_SEED_STACKS.map((s) => s.displayName)).toEqual([ + 'Kickstart stack seed', + 'Kickstart Veda', + 'Compass starter stack', + 'Starter app', + ]); + }); +}); From 077daa44cfb0a8692bfa0eec10995ac4b162da28 Mon Sep 17 00:00:00 2001 From: naman-contentstack Date: Fri, 15 May 2026 15:51:35 +0530 Subject: [PATCH 02/45] feat: add support for bulk ops --- .talismanrc | 2 ++ .../src/types/cs-assets-api.ts | 32 +++++++++++++++++++ .../src/utils/cs-assets-api-adapter.ts | 28 ++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/.talismanrc b/.talismanrc index ed36e71da..f930544f4 100644 --- a/.talismanrc +++ b/.talismanrc @@ -1,4 +1,6 @@ fileignoreconfig: - filename: pnpm-lock.yaml checksum: 2f6edbc19377e3a857884f00e31c498b660cc4f64b46892aee8eecf2f1ca9978 + - filename: packages/contentstack-asset-management/src/utils/cs-assets-api-adapter.ts + checksum: b887042c89f71914b07e6e5a98f215104ff4ee9da97e0aaa681a3a531cec74c2 version: '1.0' diff --git a/packages/contentstack-asset-management/src/types/cs-assets-api.ts b/packages/contentstack-asset-management/src/types/cs-assets-api.ts index 6c8c379e5..7f7eb7f42 100644 --- a/packages/contentstack-asset-management/src/types/cs-assets-api.ts +++ b/packages/contentstack-asset-management/src/types/cs-assets-api.ts @@ -115,6 +115,28 @@ export type CSAssetsAPIConfig = { context?: Record; }; +// --------------------------------------------------------------------------- +// Bulk mutate (CS Assets / AM API) +// --------------------------------------------------------------------------- + +export type BulkDeleteAssetItem = { uid: string; locale: string }; + +export type BulkDeleteAssetsPayload = { assets: BulkDeleteAssetItem[] }; + +export type BulkDeleteAssetsResponse = { + notice?: string; + job_id?: string; +}; + +export type BulkMoveAssetsPayload = { + asset_uids: string[]; + target_folder_uid: string; +}; + +export type BulkMoveAssetsResponse = { + notice?: string; +}; + /** * Adapter interface for Contentstack Assets API calls. * Used by export and (future) import. @@ -127,6 +149,16 @@ export interface ICSAssetsAdapter { getWorkspaceAssets(spaceUid: string, workspaceUid?: string): Promise; getWorkspaceFolders(spaceUid: string, workspaceUid?: string): Promise; getWorkspaceAssetTypes(spaceUid: string): Promise; + bulkDeleteAssets( + spaceUid: string, + workspaceUid: string | undefined, + payload: BulkDeleteAssetsPayload, + ): Promise; + bulkMoveAssets( + spaceUid: string, + workspaceUid: string | undefined, + payload: BulkMoveAssetsPayload, + ): Promise; } /** diff --git a/packages/contentstack-asset-management/src/utils/cs-assets-api-adapter.ts b/packages/contentstack-asset-management/src/utils/cs-assets-api-adapter.ts index dcdf26a11..5a8384f89 100644 --- a/packages/contentstack-asset-management/src/utils/cs-assets-api-adapter.ts +++ b/packages/contentstack-asset-management/src/utils/cs-assets-api-adapter.ts @@ -5,6 +5,10 @@ import { HttpClient, log, authenticationHandler, handleAndLogError } from '@cont import type { CSAssetsAPIConfig, AssetTypesResponse, + BulkDeleteAssetsPayload, + BulkDeleteAssetsResponse, + BulkMoveAssetsPayload, + BulkMoveAssetsResponse, CreateAssetMetadata, CreateAssetTypePayload, CreateFieldPayload, @@ -364,4 +368,28 @@ export class CSAssetsAdapter implements ICSAssetsAdapter { async createAssetType(payload: CreateAssetTypePayload): Promise<{ asset_type: { uid: string } }> { return this.postJson<{ asset_type: { uid: string } }>('/api/asset_types', payload); } + + /** + * POST /api/spaces/{spaceUid}/assets/bulk/delete — bulk delete assets (per locale entries). + */ + async bulkDeleteAssets( + spaceUid: string, + workspaceUid: string = 'main', + payload: BulkDeleteAssetsPayload, + ): Promise { + const path = `/api/spaces/${encodeURIComponent(spaceUid)}/assets/bulk/delete?workspace=${encodeURIComponent(workspaceUid)}`; + return this.postJson(path, payload, { space_key: spaceUid }); + } + + /** + * POST /api/spaces/{spaceUid}/assets/bulk-move — move assets into a folder. + */ + async bulkMoveAssets( + spaceUid: string, + workspaceUid: string = 'main', + payload: BulkMoveAssetsPayload, + ): Promise { + const path = `/api/spaces/${encodeURIComponent(spaceUid)}/assets/bulk-move?workspace=${encodeURIComponent(workspaceUid)}`; + return this.postJson(path, payload, { space_key: spaceUid }); + } } From bd9caaf73ab3d7b88df1750333ae0229f1e1e834 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 18 May 2026 12:33:16 +0530 Subject: [PATCH 03/45] fix(export-to-csv): paginate org user fetch for organization owners --- .../contentstack-export-to-csv/package.json | 2 +- .../src/utils/api-client.ts | 18 +-- .../test/unit/utils/api-client.test.ts | 125 +++++++++++++++++- 3 files changed, 126 insertions(+), 19 deletions(-) diff --git a/packages/contentstack-export-to-csv/package.json b/packages/contentstack-export-to-csv/package.json index ffdae47cf..c5a243bbc 100644 --- a/packages/contentstack-export-to-csv/package.json +++ b/packages/contentstack-export-to-csv/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-export-to-csv", "description": "Export entries, taxonomies, terms, or organization users to CSV", - "version": "2.0.0-beta.6", + "version": "2.0.0-beta.8", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/packages/contentstack-export-to-csv/src/utils/api-client.ts b/packages/contentstack-export-to-csv/src/utils/api-client.ts index cec010028..fedab6a85 100644 --- a/packages/contentstack-export-to-csv/src/utils/api-client.ts +++ b/packages/contentstack-export-to-csv/src/utils/api-client.ts @@ -138,22 +138,16 @@ export function getOrgUsers(managementAPIClient: ManagementClient, orgUid: strin return reject(new Error('Org UID not found.')); } - if (organization.is_owner === true) { - return managementAPIClient - .organization(organization.uid) - .getInvitations() - .then((data: unknown) => { - resolve(data as OrgUsersResponse); - }) - .catch(reject); - } - - if (!organization.getInvitations && !find(organization.org_roles, 'admin')) { + if (!organization.is_owner && !find(organization.org_roles, 'admin')) { return reject(new Error(messages.ERROR_ADMIN_ACCESS_DENIED)); } try { - const users = await getUsers(managementAPIClient, { uid: organization.uid }, { skip: 0, page: 1, limit: 100 }); + const users = await getUsers( + managementAPIClient, + { uid: organization.uid }, + { skip: 0, page: 1, limit: config.limit }, + ); return resolve({ items: users || [] }); } catch (error) { return reject(error); diff --git a/packages/contentstack-export-to-csv/test/unit/utils/api-client.test.ts b/packages/contentstack-export-to-csv/test/unit/utils/api-client.test.ts index 915218a4c..9a5fbc86e 100644 --- a/packages/contentstack-export-to-csv/test/unit/utils/api-client.test.ts +++ b/packages/contentstack-export-to-csv/test/unit/utils/api-client.test.ts @@ -1,4 +1,8 @@ import { expect } from 'chai'; +import sinon from 'sinon'; +import config from '../../../src/config'; +import { messages } from '../../../src/messages'; +import * as errorHandler from '../../../src/utils/error-handler'; import { getOrganizations, getOrganizationsWhereUserIsAdmin, @@ -18,12 +22,66 @@ import { getTaxonomy, createImportableCSV, } from '../../../src/utils/api-client'; +import type { ManagementClient, OrgUser } from '../../../src/types'; -// API client functions are tightly coupled to the Contentstack SDK -// These tests verify the function signatures and basic structure -// Full integration testing requires actual SDK mocking or E2E tests +const ORG_UID = 'org-uid'; + +function makeUser(index: number): OrgUser { + return { + email: `user${index}@example.com`, + user_uid: `uid-${index}`, + invited_by: 'system', + status: 'accepted', + created_at: '2020-01-01T00:00:00.000Z', + updated_at: '2020-01-01T00:00:00.000Z', + }; +} + +function createPaginatedMockClient( + organization: { + is_owner?: boolean; + org_roles?: Array<{ admin?: boolean }>; + }, + pages: OrgUser[][], +): { client: ManagementClient; getInvitations: sinon.SinonStub; invitationParams: Array> } { + const invitationParams: Array> = []; + const getInvitations = sinon.stub().callsFake(async (params: Record) => { + invitationParams.push({ ...params }); + const callIndex = getInvitations.callCount - 1; + const items = pages[callIndex] ?? []; + return { items }; + }); + + const organizationClient = { getInvitations }; + const organizationStub = sinon.stub().returns(organizationClient); + + const client = { + getUser: sinon.stub().resolves({ + organizations: [ + { + uid: ORG_UID, + name: 'Test Org', + ...organization, + }, + ], + }), + organization: organizationStub, + } as unknown as ManagementClient; + + return { client, getInvitations, invitationParams }; +} describe('api-client', () => { + let waitStub: sinon.SinonStub; + + beforeEach(() => { + waitStub = sinon.stub(errorHandler, 'wait').resolves(); + }); + + afterEach(() => { + waitStub.restore(); + }); + describe('module exports', () => { it('should export all expected functions', () => { expect(getOrganizations).to.be.a('function'); @@ -46,7 +104,62 @@ describe('api-client', () => { }); }); - // Note: Full functional tests for api-client require mocking the @contentstack/management SDK - // This is complex due to the SDK's internal structure. These tests are better suited for - // integration testing with a test stack or using more sophisticated mocking tools. + describe('getOrgUsers', () => { + it('should paginate getInvitations for organization owners', async () => { + const page1 = Array.from({ length: 10 }, (_, i) => makeUser(i)); + const page2 = Array.from({ length: 10 }, (_, i) => makeUser(i + 10)); + const page3 = Array.from({ length: 5 }, (_, i) => makeUser(i + 20)); + + const { client, getInvitations, invitationParams } = createPaginatedMockClient( + { is_owner: true }, + [page1, page2, page3, []], + ); + + const result = await getOrgUsers(client, ORG_UID); + + expect(result.items).to.have.lengthOf(25); + expect(getInvitations.callCount).to.equal(4); + expect(invitationParams[0]).to.deep.equal({ skip: 0, page: 1, limit: config.limit }); + expect(invitationParams[1]).to.deep.equal({ skip: config.limit, page: 2, limit: config.limit }); + expect(invitationParams[2]).to.deep.equal({ + skip: config.limit * 2, + page: 3, + limit: config.limit, + }); + }); + + it('should paginate getInvitations for organization admins', async () => { + const page1 = Array.from({ length: 10 }, (_, i) => makeUser(i)); + const page2 = Array.from({ length: 10 }, (_, i) => makeUser(i + 10)); + const page3 = Array.from({ length: 5 }, (_, i) => makeUser(i + 20)); + + const { client, getInvitations, invitationParams } = createPaginatedMockClient( + { is_owner: false, org_roles: [{ admin: true }] }, + [page1, page2, page3, []], + ); + + const result = await getOrgUsers(client, ORG_UID); + + expect(result.items).to.have.lengthOf(25); + expect(getInvitations.callCount).to.equal(4); + expect(invitationParams[0]).to.deep.equal({ skip: 0, page: 1, limit: config.limit }); + }); + + it('should reject when user is neither owner nor admin', async () => { + const { client, getInvitations } = createPaginatedMockClient( + { is_owner: false, org_roles: [{ admin: false }] }, + [[]], + ); + + try { + await getOrgUsers(client, ORG_UID); + expect.fail('Expected getOrgUsers to reject'); + } catch (error) { + expect(error).to.be.instanceOf(Error); + expect((error as Error).message).to.equal(messages.ERROR_ADMIN_ACCESS_DENIED); + } + + expect(getInvitations.called).to.equal(false); + }); + }); }); From 14e53581bbc373a982a98bdf73c81ae9383c30e6 Mon Sep 17 00:00:00 2001 From: Netraj Patel Date: Mon, 18 May 2026 17:54:35 +0530 Subject: [PATCH 04/45] Snyk fix --- .talismanrc | 2 +- packages/contentstack-audit/README.md | 2 +- packages/contentstack-bootstrap/README.md | 2 +- packages/contentstack-branches/README.md | 2 +- packages/contentstack-bulk-publish/README.md | 2 +- packages/contentstack-clone/README.md | 2 +- packages/contentstack-export/README.md | 2 +- packages/contentstack-import-setup/README.md | 2 +- packages/contentstack-import/README.md | 2 +- packages/contentstack-migration/README.md | 2 +- pnpm-lock.yaml | 20 ++++++++++---------- pnpm-workspace.yaml | 2 +- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.talismanrc b/.talismanrc index adeab6fc8..b7bd9d019 100644 --- a/.talismanrc +++ b/.talismanrc @@ -1,4 +1,4 @@ fileignoreconfig: - filename: pnpm-lock.yaml - checksum: 97c02af1c210f0a8d5486ec114746856c96209132b973199cfed33de8461965c + checksum: 1f7c2b5e595489e1b3f7caea46cd3d22123bdc06018ae1a1baed94a230313421 version: '1.0' diff --git a/packages/contentstack-audit/README.md b/packages/contentstack-audit/README.md index 150d093eb..068227279 100644 --- a/packages/contentstack-audit/README.md +++ b/packages/contentstack-audit/README.md @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit $ csdx COMMAND running command... $ csdx (--version|-v) -@contentstack/cli-audit/1.19.2 darwin-arm64 node-v24.14.0 +@contentstack/cli-audit/1.19.3 darwin-arm64 node-v24.14.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-bootstrap/README.md b/packages/contentstack-bootstrap/README.md index 4a60bc244..49894909c 100644 --- a/packages/contentstack-bootstrap/README.md +++ b/packages/contentstack-bootstrap/README.md @@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-bootstrap/1.19.1 darwin-arm64 node-v24.14.0 +@contentstack/cli-cm-bootstrap/1.19.3 darwin-arm64 node-v24.14.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-branches/README.md b/packages/contentstack-branches/README.md index cc8d77d56..7310b1da2 100755 --- a/packages/contentstack-branches/README.md +++ b/packages/contentstack-branches/README.md @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-branches/1.8.0 darwin-arm64 node-v24.14.0 +@contentstack/cli-cm-branches/1.8.1 darwin-arm64 node-v24.14.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-bulk-publish/README.md b/packages/contentstack-bulk-publish/README.md index 7a94d7035..896990310 100644 --- a/packages/contentstack-bulk-publish/README.md +++ b/packages/contentstack-bulk-publish/README.md @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-cm-bulk-publish $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-bulk-publish/1.11.2 darwin-arm64 node-v24.14.0 +@contentstack/cli-cm-bulk-publish/1.11.3 darwin-arm64 node-v24.14.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-clone/README.md b/packages/contentstack-clone/README.md index fd1603518..37fd87a53 100644 --- a/packages/contentstack-clone/README.md +++ b/packages/contentstack-clone/README.md @@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-clone/1.21.2 darwin-arm64 node-v24.14.0 +@contentstack/cli-cm-clone/1.21.4 darwin-arm64 node-v24.14.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-export/README.md b/packages/contentstack-export/README.md index d96c67eec..13dfc0c70 100755 --- a/packages/contentstack-export/README.md +++ b/packages/contentstack-export/README.md @@ -48,7 +48,7 @@ $ npm install -g @contentstack/cli-cm-export $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-export/1.24.2 darwin-arm64 node-v24.14.0 +@contentstack/cli-cm-export/1.25.0 darwin-arm64 node-v24.14.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-import-setup/README.md b/packages/contentstack-import-setup/README.md index 56bb1ea7b..150c2931c 100644 --- a/packages/contentstack-import-setup/README.md +++ b/packages/contentstack-import-setup/README.md @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import-setup $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-import-setup/1.8.2 darwin-arm64 node-v24.14.0 +@contentstack/cli-cm-import-setup/1.8.3 darwin-arm64 node-v24.14.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-import/README.md b/packages/contentstack-import/README.md index e60a64566..cfa11630a 100644 --- a/packages/contentstack-import/README.md +++ b/packages/contentstack-import/README.md @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-import/1.32.2 darwin-arm64 node-v24.14.0 +@contentstack/cli-cm-import/1.33.0 darwin-arm64 node-v24.14.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-migration/README.md b/packages/contentstack-migration/README.md index 544e4e420..dda6bdd36 100644 --- a/packages/contentstack-migration/README.md +++ b/packages/contentstack-migration/README.md @@ -21,7 +21,7 @@ $ npm install -g @contentstack/cli-migration $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-migration/1.12.1 darwin-arm64 node-v24.14.0 +@contentstack/cli-migration/1.12.2 darwin-arm64 node-v24.14.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3528982ce..3a9f5dca3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,8 +6,8 @@ settings: overrides: tmp: 0.2.4 - axios: 1.15.2 uuid: 14.0.0 + qs: 6.15.2 importers: @@ -5411,8 +5411,8 @@ packages: pure-rand@6.1.0: resolution: {integrity: sha512-bVWawvoZoBYpp6yIoQtQXHZjmz35RSVHnUOTefl8Vcjr8snTPY1wnpSPMWekcFwbxI6gtmT7rSYPFvz71ldiOA==} - qs@6.15.1: - resolution: {integrity: sha512-6YHEFRL9mfgcAvql/XhwTvf5jKcOiiupt2FiJxHkiX1z4j7WL8J/jRHYLluORvc1XxB5rV20KoeK00gVJamspg==} + qs@6.15.2: + resolution: {integrity: sha512-Rzq0KEyX/w/tEybncDgdkZrJgVUsUMk3xjh3t5bv3S1HTAtg+uOYt72+ZfwiQwKdysThkTBdL/rTi6HDmX9Ddw==} engines: {node: '>=0.6'} queue-microtask@1.2.3: @@ -7357,7 +7357,7 @@ snapshots: husky: 9.1.7 lodash: 4.18.1 otplib: 12.0.1 - qs: 6.15.1 + qs: 6.15.2 stream-browserify: 3.0.0 transitivePeerDependencies: - debug @@ -10554,7 +10554,7 @@ snapshots: '@typescript-eslint/parser': 6.21.0(eslint@9.39.4)(typescript@5.9.3) eslint-config-xo-space: 0.35.0(eslint@9.39.4) eslint-import-resolver-typescript: 3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@6.21.0(eslint@9.39.4)(typescript@5.9.3))(eslint@9.39.4))(eslint@9.39.4) - eslint-plugin-import: 2.32.0(@typescript-eslint/parser@6.21.0(eslint@9.39.4)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@6.21.0(eslint@9.39.4)(typescript@5.9.3))(eslint@9.39.4))(eslint@9.39.4))(eslint@9.39.4) + eslint-plugin-import: 2.32.0(@typescript-eslint/parser@6.21.0(eslint@9.39.4)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1)(eslint@9.39.4) eslint-plugin-mocha: 10.5.0(eslint@9.39.4) eslint-plugin-n: 15.7.0(eslint@9.39.4) eslint-plugin-perfectionist: 2.11.0(eslint@9.39.4)(typescript@5.9.3) @@ -10651,7 +10651,7 @@ snapshots: eslint-config-xo: 0.49.0(eslint@9.39.4) eslint-config-xo-space: 0.35.0(eslint@9.39.4) eslint-import-resolver-typescript: 3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@6.21.0(eslint@9.39.4)(typescript@5.9.3))(eslint@9.39.4))(eslint@9.39.4) - eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.59.2(eslint@9.39.4)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@6.21.0(eslint@9.39.4)(typescript@5.9.3))(eslint@9.39.4))(eslint@9.39.4))(eslint@9.39.4) + eslint-plugin-import: 2.32.0(@typescript-eslint/parser@8.59.2(eslint@9.39.4)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1)(eslint@9.39.4) eslint-plugin-jsdoc: 50.8.0(eslint@9.39.4) eslint-plugin-mocha: 10.5.0(eslint@9.39.4) eslint-plugin-n: 17.24.0(eslint@9.39.4)(typescript@5.9.3) @@ -10722,7 +10722,7 @@ snapshots: tinyglobby: 0.2.16 unrs-resolver: 1.11.1 optionalDependencies: - eslint-plugin-import: 2.32.0(@typescript-eslint/parser@6.21.0(eslint@9.39.4)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@6.21.0(eslint@9.39.4)(typescript@5.9.3))(eslint@9.39.4))(eslint@9.39.4))(eslint@9.39.4) + eslint-plugin-import: 2.32.0(@typescript-eslint/parser@6.21.0(eslint@9.39.4)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1)(eslint@9.39.4) transitivePeerDependencies: - supports-color @@ -10866,7 +10866,7 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-plugin-import@2.32.0(@typescript-eslint/parser@6.21.0(eslint@9.39.4)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@6.21.0(eslint@9.39.4)(typescript@5.9.3))(eslint@9.39.4))(eslint@9.39.4))(eslint@9.39.4): + eslint-plugin-import@2.32.0(@typescript-eslint/parser@6.21.0(eslint@9.39.4)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1)(eslint@9.39.4): dependencies: '@rtsao/scc': 1.1.0 array-includes: 3.1.9 @@ -10953,7 +10953,7 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.59.2(eslint@9.39.4)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1(eslint-plugin-import@2.32.0(@typescript-eslint/parser@6.21.0(eslint@9.39.4)(typescript@5.9.3))(eslint@9.39.4))(eslint@9.39.4))(eslint@9.39.4): + eslint-plugin-import@2.32.0(@typescript-eslint/parser@8.59.2(eslint@9.39.4)(typescript@5.9.3))(eslint-import-resolver-typescript@3.10.1)(eslint@9.39.4): dependencies: '@rtsao/scc': 1.1.0 array-includes: 3.1.9 @@ -13493,7 +13493,7 @@ snapshots: pure-rand@6.1.0: {} - qs@6.15.1: + qs@6.15.2: dependencies: side-channel: 1.1.0 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 2daf20671..61488ebfb 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -2,5 +2,5 @@ packages: - 'packages/*' overrides: tmp: 0.2.4 - axios: 1.15.2 uuid: 14.0.0 + qs: 6.15.2 From 6b01505e3d0998628417a99c6faacbe0a6054340 Mon Sep 17 00:00:00 2001 From: harshitha-cstk Date: Tue, 19 May 2026 16:00:38 +0530 Subject: [PATCH 05/45] feat: migrate Apps CLI plugin to cli-plugins monorepo and add related documentation - Moved the `@contentstack/apps-cli` plugin from the external plugin to the `cli-plugins` monorepo. - Updated `AGENTS.md` to include Developer Hub apps in the purpose and added new sections for the Apps CLI plugin. - Created `APPS-CLI-MIGRATION.md` to document the migration process and repository changes. - Added new commands and configuration files for the Apps CLI plugin. - Updated CI workflows to include testing and publishing for the Apps CLI plugin. --- .cursor/rules/apps-cli.mdc | 34 ++ .github/config/release.json | 3 +- .github/workflows/release-v2-beta-plugins.yml | 8 + .github/workflows/unit-test.yml | 4 + AGENTS.md | 12 +- APPS-CLI-MIGRATION.md | 51 ++ MIGRATION.md | 8 + README.md | 1 + packages/contentstack-apps-cli/.eslintignore | 1 + packages/contentstack-apps-cli/.eslintrc | 42 ++ packages/contentstack-apps-cli/.gitignore | 21 + packages/contentstack-apps-cli/.mocharc.json | 12 + packages/contentstack-apps-cli/LICENSE | 21 + packages/contentstack-apps-cli/README.md | 313 ++++++++++++ packages/contentstack-apps-cli/bin/dev | 17 + packages/contentstack-apps-cli/bin/dev.cmd | 3 + packages/contentstack-apps-cli/bin/run | 5 + packages/contentstack-apps-cli/bin/run.cmd | 3 + .../DEPLOY_COMMAND_FLOW_AND_TEST_ISSUES.md | 200 ++++++++ .../examples/create-launch-project.json | 14 + packages/contentstack-apps-cli/package.json | 114 +++++ .../src/app-cli-base-command.ts | 33 ++ .../contentstack-apps-cli/src/base-command.ts | 199 ++++++++ .../src/commands/app/create.ts | 463 +++++++++++++++++ .../src/commands/app/delete.ts | 86 ++++ .../src/commands/app/deploy.ts | 306 +++++++++++ .../src/commands/app/get.ts | 68 +++ .../src/commands/app/index.ts | 39 ++ .../src/commands/app/install.ts | 155 ++++++ .../src/commands/app/reinstall.ts | 137 +++++ .../src/commands/app/uninstall.ts | 82 +++ .../src/commands/app/update.ts | 219 ++++++++ .../contentstack-apps-cli/src/config/index.ts | 13 + .../src/config/manifest.json | 105 ++++ .../src/factories/uninstall-app-factory.ts | 15 + .../src/graphql/queries.ts | 29 ++ .../src/hooks/init/load-chalk.ts | 9 + packages/contentstack-apps-cli/src/index.ts | 1 + .../src/interfaces/uninstall-app.ts | 18 + .../src/messages/index.ts | 173 +++++++ .../src/strategies/uninstall-all.ts | 61 +++ .../src/strategies/uninstall-selected.ts | 63 +++ .../contentstack-apps-cli/src/types/app.ts | 151 ++++++ .../contentstack-apps-cli/src/types/index.ts | 2 + .../contentstack-apps-cli/src/types/utils.ts | 29 ++ .../src/util/api-request-handler.ts | 61 +++ .../src/util/common-utils.ts | 430 ++++++++++++++++ .../src/util/error-helper.ts | 7 + packages/contentstack-apps-cli/src/util/fs.ts | 34 ++ .../contentstack-apps-cli/src/util/index.ts | 4 + .../src/util/inquirer.ts | 471 +++++++++++++++++ .../contentstack-apps-cli/src/util/log.ts | 188 +++++++ .../test/helpers/init.js | 7 + .../contentstack-apps-cli/test/tsconfig.json | 10 + .../test/unit/commands/app/create.test.ts | 473 ++++++++++++++++++ .../test/unit/commands/app/delete.test.ts | 114 +++++ .../test/unit/commands/app/deploy.test.ts | 405 +++++++++++++++ .../test/unit/commands/app/get.test.ts | 206 ++++++++ .../test/unit/commands/app/install.test.ts | 166 ++++++ .../test/unit/commands/app/reinstall.test.ts | 225 +++++++++ .../test/unit/commands/app/uninstall.test.ts | 353 +++++++++++++ .../test/unit/commands/app/update.test.ts | 290 +++++++++++ .../test/unit/config/manifest.json | 28 ++ .../test/unit/config/org_manifest.json | 29 ++ .../test/unit/helpers/auth-stub-helper.ts | 36 ++ .../test/unit/mock/boilerplate.zip | Bin 0 -> 328 bytes .../test/unit/mock/common.mock.json | 154 ++++++ .../test/unit/mock/config.json | 3 + .../test/unit/util/common-utils.test.ts | 144 ++++++ .../test/unit/util/inquirer.test.ts | 177 +++++++ packages/contentstack-apps-cli/tsconfig.json | 24 + skills/apps-cli-framework/SKILL.md | 45 ++ skills/apps-cli-typescript/SKILL.md | 37 ++ skills/contentstack-apps/SKILL.md | 48 ++ skills/dev-workflow/SKILL.md | 15 +- 75 files changed, 7524 insertions(+), 3 deletions(-) create mode 100644 .cursor/rules/apps-cli.mdc create mode 100644 APPS-CLI-MIGRATION.md create mode 100644 packages/contentstack-apps-cli/.eslintignore create mode 100644 packages/contentstack-apps-cli/.eslintrc create mode 100644 packages/contentstack-apps-cli/.gitignore create mode 100644 packages/contentstack-apps-cli/.mocharc.json create mode 100644 packages/contentstack-apps-cli/LICENSE create mode 100644 packages/contentstack-apps-cli/README.md create mode 100755 packages/contentstack-apps-cli/bin/dev create mode 100644 packages/contentstack-apps-cli/bin/dev.cmd create mode 100755 packages/contentstack-apps-cli/bin/run create mode 100644 packages/contentstack-apps-cli/bin/run.cmd create mode 100644 packages/contentstack-apps-cli/docs/DEPLOY_COMMAND_FLOW_AND_TEST_ISSUES.md create mode 100644 packages/contentstack-apps-cli/examples/create-launch-project.json create mode 100644 packages/contentstack-apps-cli/package.json create mode 100644 packages/contentstack-apps-cli/src/app-cli-base-command.ts create mode 100644 packages/contentstack-apps-cli/src/base-command.ts create mode 100644 packages/contentstack-apps-cli/src/commands/app/create.ts create mode 100644 packages/contentstack-apps-cli/src/commands/app/delete.ts create mode 100644 packages/contentstack-apps-cli/src/commands/app/deploy.ts create mode 100644 packages/contentstack-apps-cli/src/commands/app/get.ts create mode 100644 packages/contentstack-apps-cli/src/commands/app/index.ts create mode 100644 packages/contentstack-apps-cli/src/commands/app/install.ts create mode 100644 packages/contentstack-apps-cli/src/commands/app/reinstall.ts create mode 100644 packages/contentstack-apps-cli/src/commands/app/uninstall.ts create mode 100644 packages/contentstack-apps-cli/src/commands/app/update.ts create mode 100644 packages/contentstack-apps-cli/src/config/index.ts create mode 100644 packages/contentstack-apps-cli/src/config/manifest.json create mode 100644 packages/contentstack-apps-cli/src/factories/uninstall-app-factory.ts create mode 100644 packages/contentstack-apps-cli/src/graphql/queries.ts create mode 100644 packages/contentstack-apps-cli/src/hooks/init/load-chalk.ts create mode 100644 packages/contentstack-apps-cli/src/index.ts create mode 100644 packages/contentstack-apps-cli/src/interfaces/uninstall-app.ts create mode 100644 packages/contentstack-apps-cli/src/messages/index.ts create mode 100644 packages/contentstack-apps-cli/src/strategies/uninstall-all.ts create mode 100644 packages/contentstack-apps-cli/src/strategies/uninstall-selected.ts create mode 100644 packages/contentstack-apps-cli/src/types/app.ts create mode 100644 packages/contentstack-apps-cli/src/types/index.ts create mode 100644 packages/contentstack-apps-cli/src/types/utils.ts create mode 100644 packages/contentstack-apps-cli/src/util/api-request-handler.ts create mode 100644 packages/contentstack-apps-cli/src/util/common-utils.ts create mode 100644 packages/contentstack-apps-cli/src/util/error-helper.ts create mode 100644 packages/contentstack-apps-cli/src/util/fs.ts create mode 100644 packages/contentstack-apps-cli/src/util/index.ts create mode 100644 packages/contentstack-apps-cli/src/util/inquirer.ts create mode 100755 packages/contentstack-apps-cli/src/util/log.ts create mode 100755 packages/contentstack-apps-cli/test/helpers/init.js create mode 100755 packages/contentstack-apps-cli/test/tsconfig.json create mode 100644 packages/contentstack-apps-cli/test/unit/commands/app/create.test.ts create mode 100644 packages/contentstack-apps-cli/test/unit/commands/app/delete.test.ts create mode 100644 packages/contentstack-apps-cli/test/unit/commands/app/deploy.test.ts create mode 100644 packages/contentstack-apps-cli/test/unit/commands/app/get.test.ts create mode 100644 packages/contentstack-apps-cli/test/unit/commands/app/install.test.ts create mode 100644 packages/contentstack-apps-cli/test/unit/commands/app/reinstall.test.ts create mode 100644 packages/contentstack-apps-cli/test/unit/commands/app/uninstall.test.ts create mode 100644 packages/contentstack-apps-cli/test/unit/commands/app/update.test.ts create mode 100644 packages/contentstack-apps-cli/test/unit/config/manifest.json create mode 100644 packages/contentstack-apps-cli/test/unit/config/org_manifest.json create mode 100644 packages/contentstack-apps-cli/test/unit/helpers/auth-stub-helper.ts create mode 100644 packages/contentstack-apps-cli/test/unit/mock/boilerplate.zip create mode 100644 packages/contentstack-apps-cli/test/unit/mock/common.mock.json create mode 100644 packages/contentstack-apps-cli/test/unit/mock/config.json create mode 100644 packages/contentstack-apps-cli/test/unit/util/common-utils.test.ts create mode 100644 packages/contentstack-apps-cli/test/unit/util/inquirer.test.ts create mode 100644 packages/contentstack-apps-cli/tsconfig.json create mode 100644 skills/apps-cli-framework/SKILL.md create mode 100644 skills/apps-cli-typescript/SKILL.md create mode 100644 skills/contentstack-apps/SKILL.md diff --git a/.cursor/rules/apps-cli.mdc b/.cursor/rules/apps-cli.mdc new file mode 100644 index 000000000..56c6920d8 --- /dev/null +++ b/.cursor/rules/apps-cli.mdc @@ -0,0 +1,34 @@ +--- +description: 'Contentstack Apps CLI plugin (Developer Hub app lifecycle)' +globs: + [ + 'packages/contentstack-apps-cli/**/*.ts', + 'packages/contentstack-apps-cli/test/**/*.ts', + ] +alwaysApply: false +--- + +# Apps CLI plugin standards + +Canonical docs: [AGENTS.md](../../AGENTS.md) and skills: + +- [skills/contentstack-apps/SKILL.md](../../skills/contentstack-apps/SKILL.md) — manifests, GraphQL, HTTP +- [skills/apps-cli-framework/SKILL.md](../../skills/apps-cli-framework/SKILL.md) — `BaseCommand`, `AppCLIBaseCommand`, flags +- [skills/apps-cli-typescript/SKILL.md](../../skills/apps-cli-typescript/SKILL.md) — TS/ESLint + +## Command layout + +- Commands live under `packages/contentstack-apps-cli/src/commands/app/` +- Topic: `app` (e.g. `csdx app:create`, `csdx app:deploy`) +- Extend `AppCLIBaseCommand` for manifest workflows; otherwise `BaseCommand` + +## Testing + +- Mocha + Chai + sinon + nock; `@oclif/test` for command runs +- Use `stubAuthentication` from `test/unit/helpers/auth-stub-helper.ts` +- No real API credentials; `--forbid-only` in CI + +## Dependencies + +- `@contentstack/cli-command`, `@contentstack/cli-utilities` — version must match the cli-plugins branch (v1 vs v2 beta) +- Chalk v5: loaded via init hook `src/hooks/init/load-chalk.ts` diff --git a/.github/config/release.json b/.github/config/release.json index d3bff31b6..f43492a73 100755 --- a/.github/config/release.json +++ b/.github/config/release.json @@ -9,6 +9,7 @@ "migration": false, "seed": false, "bootstrap": false, - "branches": false + "branches": false, + "apps-cli": false } } diff --git a/.github/workflows/release-v2-beta-plugins.yml b/.github/workflows/release-v2-beta-plugins.yml index 482b0a9bc..fa5a42c6e 100644 --- a/.github/workflows/release-v2-beta-plugins.yml +++ b/.github/workflows/release-v2-beta-plugins.yml @@ -142,3 +142,11 @@ jobs: token: ${{ secrets.NPM_TOKEN }} package: ./packages/contentstack-query-export/package.json tag: beta + + # Apps CLI + - name: Publishing apps-cli (Beta) + uses: JS-DevTools/npm-publish@v3 + with: + token: ${{ secrets.NPM_TOKEN }} + package: ./packages/contentstack-apps-cli/package.json + tag: beta diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 62c048f9b..853bb54e9 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -66,3 +66,7 @@ jobs: - name: Run tests for Contentstack Query Export working-directory: ./packages/contentstack-query-export run: npm run test:unit + + - name: Run tests for Contentstack Apps CLI + working-directory: ./packages/contentstack-apps-cli + run: npm run test:unit:report:json diff --git a/AGENTS.md b/AGENTS.md index c1c1995d0..931eee772 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,7 +7,7 @@ | Field | Detail | | --- | --- | | **Name:** | Contentstack CLI plugins (pnpm monorepo; root package name `csdx`) | -| **Purpose:** | OCLIF plugins that extend the Contentstack CLI (import/export, clone, migration, seed, audit, variants, etc.). | +| **Purpose:** | OCLIF plugins that extend the Contentstack CLI (import/export, clone, migration, seed, audit, variants, Developer Hub apps, etc.). | | **Out of scope (if any):** | The **core** CLI aggregation lives in the separate `cli` monorepo; this repo ships plugin packages only. | ## Tech stack (at a glance) @@ -39,6 +39,16 @@ CI: [.github/workflows/unit-test.yml](.github/workflows/unit-test.yml) and other | Framework | [skills/framework/SKILL.md](skills/framework/SKILL.md) | Utilities, config, logging, errors | | Testing | [skills/testing/SKILL.md](skills/testing/SKILL.md) | Mocha/Chai, coverage, mocks | | Code review | [skills/code-review/SKILL.md](skills/code-review/SKILL.md) | PR review for this monorepo | +| Contentstack Apps (Developer Hub) | [skills/contentstack-apps/SKILL.md](skills/contentstack-apps/SKILL.md) | Manifests, GraphQL, HTTP for `packages/contentstack-apps-cli` | +| Apps CLI framework | [skills/apps-cli-framework/SKILL.md](skills/apps-cli-framework/SKILL.md) | `BaseCommand`, `AppCLIBaseCommand`, oclif flags for apps plugin | +| Apps CLI TypeScript | [skills/apps-cli-typescript/SKILL.md](skills/apps-cli-typescript/SKILL.md) | TS/ESLint conventions for apps plugin | + +## Apps CLI plugin (`@contentstack/apps-cli`) + +- **Package path:** [packages/contentstack-apps-cli](packages/contentstack-apps-cli) +- **npm name:** `@contentstack/apps-cli` (unchanged for consumers) +- **Migrated from:** [contentstack/contentstack-apps-cli](https://github.com/contentstack/contentstack-apps-cli) — see [APPS-CLI-MIGRATION.md](APPS-CLI-MIGRATION.md) +- **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. ## Using Cursor (optional) diff --git a/APPS-CLI-MIGRATION.md b/APPS-CLI-MIGRATION.md new file mode 100644 index 000000000..e71cc74dd --- /dev/null +++ b/APPS-CLI-MIGRATION.md @@ -0,0 +1,51 @@ +# Apps CLI migration: standalone repo → cli-plugins monorepo + +## Summary + +The **@contentstack/apps-cli** plugin (`contentstack-apps-cli`) has moved from the standalone repository [contentstack/contentstack-apps-cli](https://github.com/contentstack/contentstack-apps-cli) into the [contentstack/cli-plugins](https://github.com/contentstack/cli-plugins) monorepo at **`packages/contentstack-apps-cli`**. + +The **npm package name is unchanged**: `@contentstack/apps-cli`. Install and command usage stay the same. + +## Repository and issue tracking + +| Before | After | +| --- | --- | +| Source: `github.com/contentstack/contentstack-apps-cli` | Source: `github.com/contentstack/cli-plugins` → `packages/contentstack-apps-cli` | +| Issues: contentstack-apps-cli repo | Issues: [cli-plugins issues](https://github.com/contentstack/cli-plugins/issues) (label or mention `apps-cli` / `@contentstack/apps-cli`) | + +The standalone **contentstack-apps-cli** repository is **archived** after the first release from cli-plugins. Open PRs and bugs should be recreated or linked in cli-plugins. + +## Version lines (1.x vs 2.x) + +| CLI line | cli-plugins branch | Apps plugin notes | +| --- | --- | --- | +| **1.x** | `v1-dev` / `v1-beta` | `@contentstack/cli-command` and `@contentstack/cli-utilities` on 1.x-compatible ranges | +| **2.x beta** | `v2-dev` / `v2-beta` | Align with 2.x beta core packages (same pattern as export, import, bootstrap) | + +Develop and release each line on its branch; do not mix 1.x and 2.x dependency pins in the same branch. + +## Install (unchanged) + +```bash +csdx plugins:install @contentstack/apps-cli +# or +npm install -g @contentstack/apps-cli +``` + +## Local development + +Clone [cli-dev-workspace](https://github.com/contentstack/cli-dev-workspace) (or cli-plugins only), then: + +```bash +cd cli-plugins +pnpm install +pnpm --filter @contentstack/apps-cli run build +pnpm --filter @contentstack/apps-cli test +``` + +See [AGENTS.md](./AGENTS.md) and [skills/contentstack-apps/SKILL.md](./skills/contentstack-apps/SKILL.md) for contributor docs. + +## Related migrations + +- Core CLI: [cli](https://github.com/contentstack/cli) monorepo +- Other external plugins (bulk operations, migrate-rte): same cli-plugins consolidation effort diff --git a/MIGRATION.md b/MIGRATION.md index 7853bc0d8..d9fe2acfe 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -180,6 +180,14 @@ csdx cm:migrate-rte --help **Migration Action:** Refer to the detailed [Bulk Operations Migration Guide](./BULK-OPERATIONS-MIGRATION.md) for complete command mappings and examples. +### 7. 📱 Apps CLI plugin repository move + +**What Changed:** +- The Apps CLI plugin (`@contentstack/apps-cli`) source moved from the standalone [contentstack-apps-cli](https://github.com/contentstack/contentstack-apps-cli) repository into this **cli-plugins** monorepo at `packages/contentstack-apps-cli` +- The npm package name and `csdx app:*` commands are unchanged + +**Migration Action:** For repository location, branching (1.x vs 2.x), and issue tracking, see the [Apps CLI Migration Guide](./APPS-CLI-MIGRATION.md). + **Quick Example:** ```bash # Before (1.x.x) diff --git a/README.md b/README.md index 6b922e41e..ef8ea5843 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ CLI supports content management scripts through which you can perform the follow - Migrate HTML RTE to JSON RTE content - Change Master Locale - Use Bootstrap plugin +- Manage Developer Hub apps (`app:*` via `@contentstack/apps-cli`) - Use Tsgen plugin diff --git a/packages/contentstack-apps-cli/.eslintignore b/packages/contentstack-apps-cli/.eslintignore new file mode 100644 index 000000000..9b1c8b133 --- /dev/null +++ b/packages/contentstack-apps-cli/.eslintignore @@ -0,0 +1 @@ +/dist diff --git a/packages/contentstack-apps-cli/.eslintrc b/packages/contentstack-apps-cli/.eslintrc new file mode 100644 index 000000000..aa58bce72 --- /dev/null +++ b/packages/contentstack-apps-cli/.eslintrc @@ -0,0 +1,42 @@ +{ + "env": { + "node": true + }, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "tsconfig.json", + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ], + "extends": [ + "plugin:@typescript-eslint/recommended" + ], + "ignorePatterns": [ + "lib/**/*", + "test/**/*" + ], + "rules": { + "@typescript-eslint/no-unused-vars": [ + "error", + { + "args": "none" + } + ], + "@typescript-eslint/prefer-namespace-keyword": "error", + "quotes": "off", + "semi": "off", + "@typescript-eslint/no-redeclare": "off", + "eqeqeq": [ + "error", + "smart" + ], + "id-match": "error", + "no-eval": "error", + "no-var": "error", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-require-imports": "off", + "prefer-const": "error" + } +} \ No newline at end of file diff --git a/packages/contentstack-apps-cli/.gitignore b/packages/contentstack-apps-cli/.gitignore new file mode 100644 index 000000000..976172982 --- /dev/null +++ b/packages/contentstack-apps-cli/.gitignore @@ -0,0 +1,21 @@ +*-debug.log +*-error.log +/.nyc_output +/dist +/lib +/package-lock.json +/tmp +/yarn.lock +node_modules +oclif.manifest.json +.env +*.log +tsconfig.tsbuildinfo +dependabot.yml +.vscode +*.todo +/bkp +.editorconfig +oclif.manifest.json +*.env +.vscode/ diff --git a/packages/contentstack-apps-cli/.mocharc.json b/packages/contentstack-apps-cli/.mocharc.json new file mode 100644 index 000000000..4a09d1446 --- /dev/null +++ b/packages/contentstack-apps-cli/.mocharc.json @@ -0,0 +1,12 @@ +{ + "require": [ + "test/helpers/init.js", + "ts-node/register" + ], + "watch-extensions": [ + "ts" + ], + "recursive": true, + "reporter": "spec", + "timeout": 60000 +} diff --git a/packages/contentstack-apps-cli/LICENSE b/packages/contentstack-apps-cli/LICENSE new file mode 100644 index 000000000..c409861bc --- /dev/null +++ b/packages/contentstack-apps-cli/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Contentstack + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/contentstack-apps-cli/README.md b/packages/contentstack-apps-cli/README.md new file mode 100644 index 000000000..2a21c7384 --- /dev/null +++ b/packages/contentstack-apps-cli/README.md @@ -0,0 +1,313 @@ +> **Source of truth:** [cli-plugins monorepo](https://github.com/contentstack/cli-plugins) — `packages/contentstack-apps-cli` +> Migrated from [contentstack-apps-cli](https://github.com/contentstack/contentstack-apps-cli). See [APPS-CLI-MIGRATION.md](../../APPS-CLI-MIGRATION.md). + + + + +# @contentstack/apps-cli + +Contentstack lets you develop apps in your organization using the Developer Hub portal. With the Apps CLI plugin, Contentstack CLI allows you to perform the CRUD operations on your app in Developer Hub and then use the app in your organization or stack by installing or uninstalling your app as required. + +## How to install this plugin + +```shell +$ csdx plugins:install @contentstack/apps-cli +``` + +## How to use this plugin + +This plugin requires you to be authenticated using [csdx auth:login](https://www.contentstack.com/docs/developers/cli/authenticate-with-the-cli/). + + +```sh-session +$ npm install -g @contentstack/apps-cli +$ csdx COMMAND +running command... +$ csdx (--version|-v) +@contentstack/apps-cli/1.6.1 darwin-arm64 node-v18.20.2 +$ csdx --help [COMMAND] +USAGE + $ csdx COMMAND +... +``` + + +# Commands + + +* [`csdx app`](#csdx-app) +* [`csdx app:create`](#csdx-appcreate) +* [`csdx app:delete`](#csdx-appdelete) +* [`csdx app:deploy`](#csdx-appdeploy) +* [`csdx app:get`](#csdx-appget) +* [`csdx app:install`](#csdx-appinstall) +* [`csdx app:reinstall`](#csdx-appreinstall) +* [`csdx app:uninstall`](#csdx-appuninstall) +* [`csdx app:update`](#csdx-appupdate) + +## `csdx app` + +Apps CLI plugin + +``` +USAGE + $ csdx app + +DESCRIPTION + Apps CLI plugin + +EXAMPLES + $ csdx app:create + + $ csdx app:delete + + $ csdx app:deploy + + $ csdx app:get + + $ csdx app:install + + $ csdx app:reinstall + + $ csdx app:uninstall + + $ csdx app:update +``` + +_See code: [src/commands/app/index.ts](https://github.com/contentstack/apps-cli/blob/v1.6.1/src/commands/app/index.ts)_ + +## `csdx app:create` + +Create a new app in Developer Hub and optionally clone a boilerplate locally. + +``` +USAGE + $ csdx app:create [--org ] [-n ] [--app-type stack|organization] [-c ] [-d ] + [--boilerplate ] + +FLAGS + -c, --config= Path of the external config + -d, --data-dir= Current working directory. + -n, --name= Name of the app to be created + --app-type=