@@ -11,6 +11,71 @@ import { getWranglerConfig } from '../lib/wrangler-config';
1111
1212const 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+
1479export 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 ) ;
0 commit comments