Skip to content

Commit 7be5b1e

Browse files
committed
Show Wrangler output from deploy command when verbose=true
1 parent 8b3aa7c commit 7be5b1e

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

packages/cli/src/__tests__/cloudflare.test.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -178,27 +178,23 @@ describe("CloudflareClient", () => {
178178
describe("deploy", () => {
179179
it("should extract worker URL from deploy output", async () => {
180180
vi.mocked($).mockImplementation(() => {
181-
return {
182-
stdout: "Worker deployed to test-worker.test-account.workers.dev",
183-
stderr: "",
184-
exitCode: 0,
181+
return async function* () {
182+
yield "Worker deployed to test-worker.test-account.workers.dev";
185183
};
186184
});
187185

188-
const result = await client.deploy();
186+
const result = await client.deploy(false);
189187
expect(result).toBe("https://test-worker.test-account.workers.dev");
190188
});
191189

192190
it("should return <unknown> if URL not found in output", async () => {
193191
vi.mocked($).mockImplementation(() => {
194-
return {
195-
stdout: "Deployment successful but no URL found",
196-
stderr: "",
197-
exitCode: 0,
192+
return async function* () {
193+
yield "Deployment successful but no URL found";
198194
};
199195
});
200196

201-
const result = await client.deploy();
197+
const result = await client.deploy(false);
202198
expect(result).toBe("<unknown>");
203199
});
204200

@@ -207,7 +203,9 @@ describe("CloudflareClient", () => {
207203
throw new Error("Deployment failed");
208204
});
209205

210-
await expect(client.deploy()).rejects.toThrow("Deployment failed");
206+
await expect(client.deploy(false)).rejects.toThrow(
207+
"Deployment failed",
208+
);
211209
});
212210
});
213211
});

packages/cli/src/cloudflare.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,21 @@ export class CloudflareClient {
7777
return true;
7878
}
7979

80-
async deploy(): Promise<string> {
80+
async deploy(verbose: boolean): Promise<string> {
8181
try {
82-
const result = await $({
82+
const p = $({
8383
quiet: true,
8484
})`npx wrangler deploy --config ${this.configPath}`;
8585

86-
const match = result.stdout.match(
86+
let output = "";
87+
for await (const text of p) {
88+
output += text;
89+
if (verbose) {
90+
console.log(text);
91+
}
92+
}
93+
94+
const match = output.match(
8795
/([a-z0-9-]+\.[a-z0-9-]+\.workers\.dev)/i,
8896
);
8997
return match ? "https://" + match[0] : "<unknown>";

packages/cli/src/install.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,27 @@ Your token needs these permissions:
256256
const promise = new Promise<void>(async (resolve, reject) => {
257257
if (await promptDeploy(serverPkgJson.version)) {
258258
let deployUrl;
259+
259260
let s = spinner();
260-
s.start(`Deploying CounterScale ...`);
261+
s.start(`Deploying Counterscale ...`);
261262

262263
try {
263-
deployUrl = await cloudflare.deploy();
264+
if (opts.verbose) {
265+
s.stop(`Deploying Counterscale ...`);
266+
}
267+
268+
deployUrl = await cloudflare.deploy(
269+
opts.verbose ? true : false,
270+
);
271+
272+
if (!opts.verbose) {
273+
s.stop("Deploying Counterscale ... Done.");
274+
}
264275
} catch (err) {
265-
s.stop("Deploying CounterScale ... Failed!", 1);
276+
s.stop("Deploying Counterscale ... Failed!", 1);
266277
return reject(err);
267278
}
268279

269-
s.stop("Deploying CounterScale ... Done.");
270-
271280
if (deployUrl) {
272281
await tick(() =>
273282
note(

0 commit comments

Comments
 (0)