|
| 1 | +import { mkdtemp } from "node:fs/promises"; |
| 2 | +import { tmpdir } from "node:os"; |
| 3 | +import { join } from "node:path"; |
1 | 4 | import { startSection, updateStatus } from "@cloudflare/cli";
|
2 | 5 | import { blue, brandColor, dim } from "@cloudflare/cli/colors";
|
3 | 6 | import TOML from "@iarna/toml";
|
4 | 7 | import { processArgument } from "helpers/args";
|
5 | 8 | import { C3_DEFAULTS, openInBrowser } from "helpers/cli";
|
6 | 9 | import { quoteShellArgs, runCommand } from "helpers/command";
|
| 10 | +import { readFile } from "helpers/files"; |
7 | 11 | import { detectPackageManager } from "helpers/packageManagers";
|
8 | 12 | import { poll } from "helpers/poll";
|
9 | 13 | import { isInsideGitRepo } from "./git";
|
@@ -99,24 +103,42 @@ export const runDeploy = async (ctx: C3Context) => {
|
99 | 103 | : []),
|
100 | 104 | ];
|
101 | 105 |
|
102 |
| - const result = await runCommand(deployCmd, { |
103 |
| - silent: true, |
| 106 | + const outputFile = join( |
| 107 | + await mkdtemp(join(tmpdir(), "c3-wrangler-deploy-")), |
| 108 | + "output.json", |
| 109 | + ); |
| 110 | + |
| 111 | + await runCommand(deployCmd, { |
104 | 112 | cwd: ctx.project.path,
|
105 | 113 | env: {
|
106 | 114 | CLOUDFLARE_ACCOUNT_ID: ctx.account.id,
|
107 | 115 | NODE_ENV: "production",
|
| 116 | + WRANGLER_OUTPUT_FILE_PATH: outputFile, |
108 | 117 | },
|
109 | 118 | startText: "Deploying your application",
|
110 | 119 | doneText: `${brandColor("deployed")} ${dim(
|
111 | 120 | `via \`${quoteShellArgs(baseDeployCmd)}\``,
|
112 | 121 | )}`,
|
113 | 122 | });
|
114 | 123 |
|
115 |
| - const deployedUrlRegex = /https:\/\/.+\.(pages|workers)\.dev/; |
116 |
| - const deployedUrlMatch = result.match(deployedUrlRegex); |
117 |
| - if (deployedUrlMatch) { |
118 |
| - ctx.deployment.url = deployedUrlMatch[0]; |
119 |
| - } else { |
| 124 | + try { |
| 125 | + const contents = readFile(outputFile); |
| 126 | + |
| 127 | + const entries = contents |
| 128 | + .split("\n") |
| 129 | + .filter(Boolean) |
| 130 | + .map((entry) => JSON.parse(entry)); |
| 131 | + const url: string | undefined = |
| 132 | + entries.find((entry) => entry.type === "deploy")?.targets?.[0] ?? |
| 133 | + entries.find((entry) => entry.type === "pages-deploy")?.url; |
| 134 | + const deployedUrlRegex = /https:\/\/.+\.(pages|workers)\.dev/; |
| 135 | + const deployedUrlMatch = url?.match(deployedUrlRegex); |
| 136 | + if (deployedUrlMatch) { |
| 137 | + ctx.deployment.url = deployedUrlMatch[0]; |
| 138 | + } else { |
| 139 | + throw new Error("Failed to find deployment url."); |
| 140 | + } |
| 141 | + } catch { |
120 | 142 | throw new Error("Failed to find deployment url.");
|
121 | 143 | }
|
122 | 144 |
|
|
0 commit comments