Skip to content

Commit b002d80

Browse files
authored
feat: upload command for worker versions (#559)
1 parent 006104e commit b002d80

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

.changeset/light-insects-kiss.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
feat: `upload` command for worker versions'

packages/cloudflare/src/cli/args.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type Arguments = (
1313
minify: boolean;
1414
}
1515
| {
16-
command: "preview" | "deploy";
16+
command: "preview" | "deploy" | "upload";
1717
passthroughArgs: string[];
1818
}
1919
| {
@@ -53,6 +53,7 @@ export function getArgs(): Arguments {
5353
};
5454
case "preview":
5555
case "deploy":
56+
case "upload":
5657
return {
5758
command: positionals[0],
5859
outputDir,
@@ -69,7 +70,9 @@ export function getArgs(): Arguments {
6970
environment: getWranglerEnvironmentFlag(passthroughArgs),
7071
};
7172
default:
72-
throw new Error("Error: invalid command, expected 'build' | 'preview' | 'deploy' | 'populateCache'");
73+
throw new Error(
74+
"Error: invalid command, expected 'build' | 'preview' | 'deploy' | 'upload' | 'populateCache'"
75+
);
7376
}
7477
}
7578

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { BuildOptions } from "@opennextjs/aws/build/helper.js";
2+
import { OpenNextConfig } from "@opennextjs/aws/types/open-next.js";
3+
4+
import { getWranglerEnvironmentFlag, runWrangler } from "../utils/run-wrangler.js";
5+
import { populateCache } from "./populate-cache.js";
6+
7+
export async function upload(
8+
options: BuildOptions,
9+
config: OpenNextConfig,
10+
uploadOptions: { passthroughArgs: string[] }
11+
) {
12+
await populateCache(options, config, {
13+
target: "remote",
14+
environment: getWranglerEnvironmentFlag(uploadOptions.passthroughArgs),
15+
});
16+
17+
runWrangler(options, ["versions upload", ...uploadOptions.passthroughArgs], { logging: "all" });
18+
}

packages/cloudflare/src/cli/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { createOpenNextConfigIfNotExistent, ensureCloudflareConfig } from "./bui
1313
import { deploy } from "./commands/deploy.js";
1414
import { populateCache } from "./commands/populate-cache.js";
1515
import { preview } from "./commands/preview.js";
16+
import { upload } from "./commands/upload.js";
1617

1718
const nextAppDir = process.cwd();
1819

@@ -43,6 +44,8 @@ async function runCommand(args: Arguments) {
4344
return preview(options, config, args);
4445
case "deploy":
4546
return deploy(options, config, args);
47+
case "upload":
48+
return upload(options, config, args);
4649
case "populateCache":
4750
return populateCache(options, config, args);
4851
}

0 commit comments

Comments
 (0)