Skip to content

Commit 1c3c525

Browse files
committed
copying cache assets for population
1 parent 5aa1bdc commit 1c3c525

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync } from "node:fs";
1+
import { cpSync, existsSync, mkdirSync } from "node:fs";
22
import path from "node:path";
33

44
import type { BuildOptions } from "@opennextjs/aws/build/helper.js";
@@ -15,6 +15,10 @@ import { tqdm } from "ts-tqdm";
1515
import { unstable_readConfig } from "wrangler";
1616

1717
import { NAME as R2_CACHE_NAME } from "../../api/overrides/incremental-cache/r2-incremental-cache.js";
18+
import {
19+
CACHE_DIR as STATIC_ASSETS_CACHE_DIR,
20+
NAME as STATIC_ASSETS_CACHE_NAME,
21+
} from "../../api/overrides/incremental-cache/static-assets-incremental-cache.js";
1822
import { NAME as D1_TAG_NAME } from "../../api/overrides/tag-cache/d1-next-tag-cache.js";
1923
import type { WranglerTarget } from "../utils/run-wrangler.js";
2024
import { runWrangler } from "../utils/run-wrangler.js";
@@ -100,6 +104,18 @@ export async function populateCache(
100104
logger.info(`Successfully populated cache with ${assets.length} assets`);
101105
break;
102106
}
107+
case STATIC_ASSETS_CACHE_NAME: {
108+
logger.info("\nPopulating Workers static assets...");
109+
110+
const assets = getCacheAssetPaths(options);
111+
for (const { fsPath, destPath } of tqdm(assets)) {
112+
const outputDestPath = path.join(options.outputDir, "assets", STATIC_ASSETS_CACHE_DIR, destPath);
113+
mkdirSync(path.dirname(outputDestPath), { recursive: true });
114+
cpSync(fsPath, outputDestPath);
115+
}
116+
logger.info(`Successfully populated static assets`);
117+
break;
118+
}
103119
default:
104120
logger.info("Incremental cache does not need populating");
105121
}

0 commit comments

Comments
 (0)