@@ -2,48 +2,69 @@ import { mkdirSync, type Stats, statSync } from "node:fs";
22import { resolve } from "node:path" ;
33import { parseArgs } from "node:util" ;
44
5+ import { CacheBindingMode } from "./build/utils/index.js" ;
6+
57export function getArgs ( ) : {
68 skipNextBuild : boolean ;
79 skipWranglerConfigCheck : boolean ;
810 outputDir ?: string ;
911 minify : boolean ;
12+ populateCache ?: { mode : "local" | "remote" ; onlyPopulate : boolean } ;
1013} {
11- const { skipBuild, skipWranglerConfigCheck, output, noMinify } = parseArgs ( {
12- options : {
13- skipBuild : {
14- type : "boolean" ,
15- short : "s" ,
16- default : false ,
17- } ,
18- output : {
19- type : "string" ,
20- short : "o" ,
21- } ,
22- noMinify : {
23- type : "boolean" ,
24- default : false ,
14+ const { skipBuild, skipWranglerConfigCheck, output, noMinify, populateCache, onlyPopulateCache } =
15+ parseArgs ( {
16+ options : {
17+ skipBuild : {
18+ type : "boolean" ,
19+ short : "s" ,
20+ default : false ,
21+ } ,
22+ output : {
23+ type : "string" ,
24+ short : "o" ,
25+ } ,
26+ noMinify : {
27+ type : "boolean" ,
28+ default : false ,
29+ } ,
30+ skipWranglerConfigCheck : {
31+ type : "boolean" ,
32+ default : false ,
33+ } ,
34+ populateCache : {
35+ type : "string" ,
36+ } ,
37+ onlyPopulateCache : {
38+ type : "boolean" ,
39+ default : false ,
40+ } ,
2541 } ,
26- skipWranglerConfigCheck : {
27- type : "boolean" ,
28- default : false ,
29- } ,
30- } ,
31- allowPositionals : false ,
32- } ) . values ;
42+ allowPositionals : false ,
43+ } ) . values ;
3344
3445 const outputDir = output ? resolve ( output ) : undefined ;
3546
3647 if ( outputDir ) {
3748 assertDirArg ( outputDir , "output" , true ) ;
3849 }
3950
51+ if (
52+ ( populateCache !== undefined || onlyPopulateCache ) &&
53+ ( ! populateCache ?. length || ! [ "local" , "remote" ] . includes ( populateCache ) )
54+ ) {
55+ throw new Error ( `Error: missing mode for populate cache flag, expected 'local' | 'remote'` ) ;
56+ }
57+
4058 return {
4159 outputDir,
4260 skipNextBuild : skipBuild || [ "1" , "true" , "yes" ] . includes ( String ( process . env . SKIP_NEXT_APP_BUILD ) ) ,
4361 skipWranglerConfigCheck :
4462 skipWranglerConfigCheck ||
4563 [ "1" , "true" , "yes" ] . includes ( String ( process . env . SKIP_WRANGLER_CONFIG_CHECK ) ) ,
4664 minify : ! noMinify ,
65+ populateCache : populateCache
66+ ? { mode : populateCache as CacheBindingMode , onlyPopulate : ! ! onlyPopulateCache }
67+ : undefined ,
4768 } ;
4869}
4970
0 commit comments