@@ -2,9 +2,6 @@ import nodeFsPromises from "node:fs/promises";
22import nodeFs from "node:fs" ;
33import nodePath from "node:path" ;
44import nodeChildProcess from "node:child_process" ;
5- import nodeUtil from "node:util" ;
6-
7- const promiseExec = nodeUtil . promisify ( nodeChildProcess . exec ) ;
85
96await ensureWranglerSetup ( ) ;
107
@@ -61,7 +58,14 @@ export async function buildApp(dir: string): Promise<void> {
6158
6259 const command = `pnpm ${ buildScript } ` ;
6360
64- await promiseExec ( command , { cwd : dir } ) ;
61+ return new Promise ( ( resolve , reject ) => {
62+ nodeChildProcess . exec ( command , { cwd : dir } , ( error ) => {
63+ if ( error ) {
64+ return reject ( error ) ;
65+ }
66+ return resolve ( ) ;
67+ } ) ;
68+ } ) ;
6569}
6670
6771/**
@@ -71,15 +75,21 @@ export async function buildApp(dir: string): Promise<void> {
7175 * @returns the url of the deployed application
7276 */
7377export async function deployBuiltApp ( dir : string ) : Promise < string > {
74- const { stdout } = await promiseExec ( "pnpm exec wrangler deploy" , { cwd : dir } ) ;
78+ return new Promise < string > ( ( resolve , reject ) => {
79+ nodeChildProcess . exec ( "pnpm exec wrangler deploy" , { cwd : dir } , ( error , stdout ) => {
80+ if ( error ) {
81+ return reject ( error ) ;
82+ }
7583
76- const deploymentUrl = stdout . match ( / \b h t t p s : \/ \/ (?: [ a - z A - Z 0 - 9 . \- ] ) * \. w o r k e r s \. d e v \b / ) ?. [ 0 ] ;
84+ const deploymentUrl = stdout . match ( / \b h t t p s : \/ \/ (?: [ a - z A - Z 0 - 9 . \- ] ) * \. w o r k e r s \. d e v \b / ) ?. [ 0 ] ;
7785
78- if ( ! deploymentUrl ) {
79- throw new Error ( `Could not obtain a deployment url for app at "${ dir } "` ) ;
80- }
86+ if ( ! deploymentUrl ) {
87+ return reject ( new Error ( `Could not obtain a deployment url for app at "${ dir } "` ) ) ;
88+ }
8189
82- return deploymentUrl ;
90+ return resolve ( deploymentUrl ) ;
91+ } ) ;
92+ } ) ;
8393}
8494
8595/**
@@ -89,15 +99,25 @@ export async function deployBuiltApp(dir: string): Promise<string> {
8999 * - if they have more than one account they have set a CLOUDFLARE_ACCOUNT_ID env variable
90100 */
91101async function ensureWranglerSetup ( ) : Promise < void > {
92- const { stdout } = await promiseExec ( "pnpm dlx wrangler whoami" ) ;
93-
94- if ( stdout . includes ( "You are not authenticated" ) ) {
95- throw new Error ( "Please log in using wrangler by running `pnpm dlx wrangler login`" ) ;
96- }
97-
98- if ( ! ( process . env as Record < string , unknown > ) [ "CLOUDFLARE_ACCOUNT_ID" ] ) {
99- throw new Error (
100- "Please set the CLOUDFLARE_ACCOUNT_ID environment variable to the id of the account you want to use to deploy the applications"
101- ) ;
102- }
102+ return new Promise ( ( resolve , reject ) => {
103+ nodeChildProcess . exec ( "pnpm dlx wrangler whoami" , ( error , stdout ) => {
104+ if ( error ) {
105+ return reject ( error ) ;
106+ }
107+
108+ if ( stdout . includes ( "You are not authenticated" ) ) {
109+ reject ( new Error ( "Please log in using wrangler by running `pnpm dlx wrangler login`" ) ) ;
110+ }
111+
112+ if ( ! ( process . env as Record < string , unknown > ) [ "CLOUDFLARE_ACCOUNT_ID" ] ) {
113+ reject (
114+ new Error (
115+ "Please set the CLOUDFLARE_ACCOUNT_ID environment variable to the id of the account you want to use to deploy the applications"
116+ )
117+ ) ;
118+ }
119+
120+ return resolve ( ) ;
121+ } ) ;
122+ } ) ;
103123}
0 commit comments