Skip to content

Commit 6a197f4

Browse files
committed
feat(cli): run build automatically when deploying
Deploy now runs the Catalyst build pipeline before bundling, so users no longer need to manually run `catalyst build && catalyst deploy`.
1 parent 6a23c90 commit 6a197f4

3 files changed

Lines changed: 73 additions & 61 deletions

File tree

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

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,71 @@ import { getWranglerConfig } from '../lib/wrangler-config';
1111

1212
const WRANGLER_VERSION = '4.24.3';
1313

14+
export async function buildCatalystProject(projectUuid: string): Promise<void> {
15+
const coreDir = process.cwd();
16+
const openNextOutDir = join(coreDir, '.open-next');
17+
const bigcommerceDistDir = join(coreDir, '.bigcommerce', 'dist');
18+
19+
const wranglerConfig = getWranglerConfig(projectUuid, 'PLACEHOLDER_KV_ID');
20+
21+
consola.start('Copying templates...');
22+
23+
await copyFile(
24+
join(getModuleCliPath(), 'templates', 'open-next.config.ts'),
25+
join(coreDir, '.bigcommerce', 'open-next.config.ts'),
26+
);
27+
await writeFile(
28+
join(coreDir, '.bigcommerce', 'wrangler.jsonc'),
29+
JSON.stringify(wranglerConfig, null, 2),
30+
);
31+
32+
consola.success('Templates copied');
33+
34+
consola.start('Building project...');
35+
36+
await execa(
37+
'pnpm',
38+
[
39+
'exec',
40+
'opennextjs-cloudflare',
41+
'build',
42+
'--skipWranglerConfigCheck',
43+
'--openNextConfigPath',
44+
join(coreDir, '.bigcommerce', 'open-next.config.ts'),
45+
],
46+
{
47+
stdout: ['pipe', 'inherit'],
48+
cwd: coreDir,
49+
},
50+
);
51+
52+
await execa(
53+
'pnpm',
54+
[
55+
'dlx',
56+
`wrangler@${WRANGLER_VERSION}`,
57+
'deploy',
58+
'--config',
59+
join(coreDir, '.bigcommerce', 'wrangler.jsonc'),
60+
'--keep-vars',
61+
'--outdir',
62+
bigcommerceDistDir,
63+
'--dry-run',
64+
],
65+
{
66+
stdout: ['pipe', 'inherit'],
67+
cwd: coreDir,
68+
},
69+
);
70+
71+
consola.success('Project built');
72+
73+
await cp(join(openNextOutDir, 'assets'), join(bigcommerceDistDir, 'assets'), {
74+
recursive: true,
75+
force: true,
76+
});
77+
}
78+
1479
export const build = new Command('build')
1580
.allowUnknownOption()
1681
// 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.
@@ -53,9 +118,6 @@ export const build = new Command('build')
53118
}
54119

55120
if (framework === 'catalyst') {
56-
const openNextOutDir = join(coreDir, '.open-next');
57-
const bigcommerceDistDir = join(coreDir, '.bigcommerce', 'dist');
58-
59121
const projectUuid = options.projectUuid ?? config.get('projectUuid');
60122

61123
if (!projectUuid) {
@@ -64,64 +126,7 @@ export const build = new Command('build')
64126
);
65127
}
66128

67-
const wranglerConfig = getWranglerConfig(projectUuid, 'PLACEHOLDER_KV_ID');
68-
69-
consola.start('Copying templates...');
70-
71-
await copyFile(
72-
join(getModuleCliPath(), 'templates', 'open-next.config.ts'),
73-
join(coreDir, '.bigcommerce', 'open-next.config.ts'),
74-
);
75-
await writeFile(
76-
join(coreDir, '.bigcommerce', 'wrangler.jsonc'),
77-
JSON.stringify(wranglerConfig, null, 2),
78-
);
79-
80-
consola.success('Templates copied');
81-
82-
consola.start('Building project...');
83-
84-
await execa(
85-
'pnpm',
86-
[
87-
'exec',
88-
'opennextjs-cloudflare',
89-
'build',
90-
'--skipWranglerConfigCheck',
91-
'--openNextConfigPath',
92-
join(coreDir, '.bigcommerce', 'open-next.config.ts'),
93-
],
94-
{
95-
stdout: ['pipe', 'inherit'],
96-
cwd: coreDir,
97-
},
98-
);
99-
100-
await execa(
101-
'pnpm',
102-
[
103-
'dlx',
104-
`wrangler@${WRANGLER_VERSION}`,
105-
'deploy',
106-
'--config',
107-
join(coreDir, '.bigcommerce', 'wrangler.jsonc'),
108-
'--keep-vars',
109-
'--outdir',
110-
bigcommerceDistDir,
111-
'--dry-run',
112-
],
113-
{
114-
stdout: ['pipe', 'inherit'],
115-
cwd: coreDir,
116-
},
117-
);
118-
119-
consola.success('Project built');
120-
121-
await cp(join(openNextOutDir, 'assets'), join(bigcommerceDistDir, 'assets'), {
122-
recursive: true,
123-
force: true,
124-
});
129+
await buildCatalystProject(projectUuid);
125130
}
126131
} catch (error) {
127132
consola.error(error);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ import {
3333

3434
// eslint-disable-next-line import/dynamic-import-chunkname
3535
vi.mock('yocto-spinner', () => import('../../../tests/mocks/spinner'));
36+
vi.mock('./build', async (importOriginal) => {
37+
const actual = await importOriginal<typeof import('./build')>();
38+
39+
return { ...actual, buildCatalystProject: vi.fn() };
40+
});
3641

3742
let exitMock: MockInstance;
3843

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { join } from 'node:path';
55
import yoctoSpinner from 'yocto-spinner';
66
import { z } from 'zod';
77

8+
import { buildCatalystProject } from './build';
89
import { consola } from '../lib/logger';
910
import { getProjectConfig } from '../lib/project-config';
1011
import { Telemetry } from '../lib/telemetry';
@@ -328,6 +329,7 @@ export const deploy = new Command('deploy')
328329
);
329330
}
330331

332+
await buildCatalystProject(projectUuid);
331333
await generateBundleZip();
332334

333335
if (options.dryRun) {

0 commit comments

Comments
 (0)