Skip to content

Commit 4b62da6

Browse files
committed
add other commands
1 parent 2aab6fb commit 4b62da6

File tree

7 files changed

+37
-19
lines changed

7 files changed

+37
-19
lines changed

packages/cloudflare/src/cli/build/utils/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ export * from "./ensure-cf-config.js";
44
export * from "./extract-project-env-vars.js";
55
export * from "./needs-experimental-react.js";
66
export * from "./normalize-path.js";
7-
export * from "./populate-cache.js";
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
import { BuildOptions } from "@opennextjs/aws/build/helper.js";
22
import { OpenNextConfig } from "@opennextjs/aws/types/open-next.js";
33

4-
export async function deploy(options: BuildOptions, config: OpenNextConfig) {}
4+
import { populateCache } from "../populate-cache/populate-cache.js";
5+
import { runWrangler } from "../utils/run-wrangler.js";
6+
7+
export async function deploy(options: BuildOptions, config: OpenNextConfig) {
8+
await populateCache(options, config, { target: "remote" });
9+
runWrangler(options, ["dev"], { logging: "all" });
10+
}

packages/cloudflare/src/cli/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function runCommand(args: Arguments) {
3636

3737
switch (args.command) {
3838
case "build":
39-
return build(options, config, args);
39+
return build(options, config, { ...args, sourceDir: baseDir });
4040
case "preview":
4141
return preview(options, config);
4242
case "deploy":

packages/cloudflare/src/cli/populate-cache/populate-cache.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ export async function populateCache(
6565
destPath
6666
);
6767

68-
runWrangler(options.packager, { ...populateCacheOptions, excludeRemoteFlag: true }, [
69-
"r2 object put",
70-
JSON.stringify(fullDestPath),
71-
`--file ${JSON.stringify(fsPath)}`,
72-
]);
68+
runWrangler(
69+
options,
70+
["r2 object put", JSON.stringify(fullDestPath), `--file ${JSON.stringify(fsPath)}`],
71+
{ ...populateCacheOptions, excludeRemoteFlag: true, logging: "error" }
72+
);
7373
});
7474
logger.info(`Successfully populated cache with ${assets.length} assets`);
7575
break;
@@ -85,11 +85,15 @@ export async function populateCache(
8585
case "d1-tag-cache": {
8686
logger.info("\nPopulating D1 tag cache...");
8787

88-
runWrangler(options.packager, populateCacheOptions, [
89-
"d1 execute",
90-
"NEXT_CACHE_D1",
91-
`--file ${JSON.stringify(path.join(options.outputDir, "cloudflare/cache-assets-manifest.sql"))}`,
92-
]);
88+
runWrangler(
89+
options,
90+
[
91+
"d1 execute",
92+
"NEXT_CACHE_D1",
93+
`--file ${JSON.stringify(path.join(options.outputDir, "cloudflare/cache-assets-manifest.sql"))}`,
94+
],
95+
{ ...populateCacheOptions, logging: "error" }
96+
);
9397
logger.info("Successfully populated cache");
9498
break;
9599
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
import { BuildOptions } from "@opennextjs/aws/build/helper.js";
22
import { OpenNextConfig } from "@opennextjs/aws/types/open-next.js";
33

4-
export async function preview(options: BuildOptions, config: OpenNextConfig) {}
4+
import { populateCache } from "../populate-cache/populate-cache";
5+
import { runWrangler } from "../utils/run-wrangler";
6+
7+
export async function preview(options: BuildOptions, config: OpenNextConfig) {
8+
await populateCache(options, config, { target: "local" });
9+
runWrangler(options, ["dev"], { logging: "all" });
10+
}

packages/cloudflare/src/cli/project-options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export type ProjectOptions = {
2+
// Next app root folder
3+
sourceDir: string;
24
// Whether the Next.js build should be skipped (i.e. if the `.next` dir is already built)
35
skipNextBuild: boolean;
46
// Whether the check to see if a wrangler config file exists should be skipped

packages/cloudflare/src/cli/utils/run-wrangler.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { spawnSync } from "node:child_process";
22

3+
import type { BuildOptions } from "@opennextjs/aws/build/helper.js";
34
import logger from "@opennextjs/aws/logger.js";
45

56
export type WranglerTarget = "local" | "remote";
67

78
export function runWrangler(
8-
pm: string,
9-
wranglerOpts: { target: WranglerTarget; excludeRemoteFlag?: boolean },
10-
args: string[]
9+
options: BuildOptions,
10+
args: string[],
11+
wranglerOpts: { target?: WranglerTarget; excludeRemoteFlag?: boolean; logging?: "all" | "error" } = {}
1112
) {
1213
const result = spawnSync(
13-
pm,
14+
options.packager,
1415
[
1516
"exec",
1617
"wrangler",
@@ -20,7 +21,7 @@ export function runWrangler(
2021
].filter((v): v is string => !!v),
2122
{
2223
shell: true,
23-
stdio: ["ignore", "ignore", "inherit"],
24+
stdio: wranglerOpts.logging === "error" ? ["ignore", "ignore", "inherit"] : "inherit",
2425
}
2526
);
2627

0 commit comments

Comments
 (0)