Skip to content

Commit ace36eb

Browse files
committed
feat(cli): remove framework config and simplify build command (#2895)
1 parent b90be10 commit ace36eb

7 files changed

Lines changed: 17 additions & 87 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bigcommerce/catalyst": minor
3+
---
4+
5+
Remove `framework` configuration and simplify `catalyst build` to only run the Catalyst build path.
Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,15 @@
11
import { Command } from 'commander';
2-
import { execa } from 'execa';
32
import { expect, test, vi } from 'vitest';
43

5-
import { program } from '../program';
6-
74
import { build } from './build';
85

96
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
107
vi.spyOn(process, 'exit').mockImplementation(() => null as never);
118

12-
vi.mock('node:fs', () => ({
13-
existsSync: vi.fn(() => true),
14-
}));
15-
16-
vi.mock('execa', () => ({
17-
execa: vi.fn(() => Promise.resolve({ stdout: '' })),
18-
__esModule: true,
19-
}));
20-
219
test('properly configured Command instance', () => {
2210
expect(build).toBeInstanceOf(Command);
2311
expect(build.name()).toBe('build');
2412
expect(build.options).toEqual(
25-
expect.arrayContaining([
26-
expect.objectContaining({ long: '--framework' }),
27-
expect.objectContaining({ long: '--project-uuid' }),
28-
]),
29-
);
30-
});
31-
32-
test('calls execa with Next.js build if framework is nextjs', async () => {
33-
await program.parseAsync(['node', 'catalyst', 'build', '--framework', 'nextjs', '--debug']);
34-
35-
expect(execa).toHaveBeenCalledWith(
36-
'node_modules/.bin/next',
37-
['build', '--debug'],
38-
expect.objectContaining({
39-
stdio: 'inherit',
40-
cwd: process.cwd(),
41-
}),
13+
expect.arrayContaining([expect.objectContaining({ long: '--project-uuid' })]),
4214
);
4315
});

packages/catalyst/src/cli/commands/build.ts

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Command, Option } from 'commander';
22
import { execa } from 'execa';
3-
import { existsSync } from 'node:fs';
43
import { copyFile, cp, writeFile } from 'node:fs/promises';
54
import { join } from 'node:path';
65

@@ -77,53 +76,21 @@ export async function buildCatalystProject(projectUuid: string): Promise<void> {
7776
}
7877

7978
export const build = new Command('build')
80-
.allowUnknownOption()
81-
// The unknown options end up in program.args, not in program.opts(). Commander does not take a guess at how to interpret the unknown options.
82-
.argument(
83-
'[next-build-options...]',
84-
'Next.js `build` options (see: https://nextjs.org/docs/app/api-reference/cli/next#next-build-options)',
85-
)
8679
.addOption(
8780
new Option(
8881
'--project-uuid <uuid>',
8982
'Project UUID to be included in the deployment configuration.',
9083
).env('CATALYST_PROJECT_UUID'),
9184
)
92-
.addOption(
93-
new Option('--framework <framework>', 'The framework to use for the build.').choices([
94-
'nextjs',
95-
'catalyst',
96-
]),
97-
)
98-
.action(async (nextBuildOptions, options) => {
99-
const coreDir = process.cwd();
85+
.action(async (options) => {
10086
const config = getProjectConfig();
101-
const framework = options.framework ?? config.get('framework');
102-
103-
if (framework === 'nextjs') {
104-
const nextBin = join('node_modules', '.bin', 'next');
87+
const projectUuid = options.projectUuid ?? config.get('projectUuid');
10588

106-
if (!existsSync(nextBin)) {
107-
throw new Error(
108-
`Next.js is not installed in ${coreDir}. Are you in a valid Next.js project?`,
109-
);
110-
}
111-
112-
await execa(nextBin, ['build', ...nextBuildOptions], {
113-
stdio: 'inherit',
114-
cwd: coreDir,
115-
});
89+
if (!projectUuid) {
90+
throw new Error(
91+
'Project UUID is required. Please run `catalyst project create` or `catalyst project link` or this command again with --project-uuid <uuid>.',
92+
);
11693
}
11794

118-
if (framework === 'catalyst') {
119-
const projectUuid = options.projectUuid ?? config.get('projectUuid');
120-
121-
if (!projectUuid) {
122-
throw new Error(
123-
'Project UUID is required. Please run `catalyst project create` or `catalyst project link` or this command again with --project-uuid <uuid>.',
124-
);
125-
}
126-
127-
await buildCatalystProject(projectUuid);
128-
}
95+
await buildCatalystProject(projectUuid);
12996
});

packages/catalyst/src/cli/commands/project.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ describe('project create', () => {
129129
expect(exitMock).toHaveBeenCalledWith(0);
130130

131131
expect(config.get('projectUuid')).toBe('c23f5785-fd99-4a94-9fb3-945551623925');
132-
expect(config.get('framework')).toBe('catalyst');
133132
expect(config.get('storeHash')).toBe(storeHash);
134133
expect(config.get('accessToken')).toBe(accessToken);
135134

@@ -265,7 +264,6 @@ describe('project link', () => {
265264
);
266265
expect(exitMock).toHaveBeenCalledWith(0);
267266
expect(config.get('projectUuid')).toBe(projectUuid1);
268-
expect(config.get('framework')).toBe('catalyst');
269267
});
270268

271269
test('fetches projects and prompts user to select one', async () => {
@@ -316,7 +314,6 @@ describe('project link', () => {
316314
expect(exitMock).toHaveBeenCalledWith(0);
317315

318316
expect(config.get('projectUuid')).toBe(projectUuid2);
319-
expect(config.get('framework')).toBe('catalyst');
320317
expect(config.get('storeHash')).toBe(storeHash);
321318
expect(config.get('accessToken')).toBe(accessToken);
322319

@@ -371,7 +368,6 @@ describe('project link', () => {
371368
expect(exitMock).toHaveBeenCalledWith(0);
372369

373370
expect(config.get('projectUuid')).toBe(projectUuid3);
374-
expect(config.get('framework')).toBe('catalyst');
375371
expect(config.get('storeHash')).toBe(storeHash);
376372
expect(config.get('accessToken')).toBe(accessToken);
377373

packages/catalyst/src/cli/commands/project.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ const create = new Command('create')
8888

8989
consola.start('Writing project UUID to .bigcommerce/project.json...');
9090
config.set('projectUuid', data.uuid);
91-
config.set('framework', 'catalyst');
9291
config.set('storeHash', storeHash);
9392
config.set('accessToken', accessToken);
9493
consola.success('Project UUID written to .bigcommerce/project.json.');
@@ -130,7 +129,6 @@ export const link = new Command('link')
130129
) => {
131130
consola.start('Writing project UUID to .bigcommerce/project.json...');
132131
config.set('projectUuid', uuid);
133-
config.set('framework', 'catalyst');
134132

135133
if (credentials) {
136134
config.set('storeHash', credentials.storeHash);

packages/catalyst/src/cli/lib/project-config.spec.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,3 @@ test('writes and reads field from .bigcommerce/project.json', async () => {
5050
expect(config.get('storeHash')).toBe('abc123');
5151
expect(config.get('accessToken')).toBe('secret-token');
5252
});
53-
54-
test('sets default framework to nextjs', async () => {
55-
const projectJsonPath = join(tmpDir, '.bigcommerce/project.json');
56-
57-
await mkdir(dirname(projectJsonPath), { recursive: true });
58-
await writeFile(projectJsonPath, JSON.stringify({}));
59-
60-
expect(config.get('framework')).toBe('nextjs');
61-
});

packages/catalyst/src/cli/lib/project-config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { join } from 'path';
33

44
export interface ProjectConfigSchema {
55
projectUuid: string;
6-
framework: 'catalyst' | 'nextjs';
6+
// Reserved for future use
7+
framework: 'catalyst';
78
storeHash?: string;
89
accessToken?: string;
910
telemetry: {
@@ -21,8 +22,8 @@ export function getProjectConfig() {
2122
projectUuid: { type: 'string', format: 'uuid' },
2223
framework: {
2324
type: 'string',
24-
enum: ['catalyst', 'nextjs'],
25-
default: 'nextjs',
25+
enum: ['catalyst'],
26+
default: 'catalyst',
2627
},
2728
storeHash: { type: 'string' },
2829
accessToken: { type: 'string' },

0 commit comments

Comments
 (0)