@@ -2,7 +2,8 @@ import { mkdirSync, type Stats, statSync } from "node:fs";
22import { resolve } from "node:path" ;
33import { parseArgs } from "node:util" ;
44
5- import { isWranglerTarget , WranglerTarget } from "./utils/run-wrangler.js" ;
5+ import type { WranglerTarget } from "./utils/run-wrangler.js" ;
6+ import { getWranglerEnvironmentFlag , isWranglerTarget } from "./utils/run-wrangler.js" ;
67
78export type Arguments = (
89 | {
@@ -11,8 +12,15 @@ export type Arguments = (
1112 skipWranglerConfigCheck : boolean ;
1213 minify : boolean ;
1314 }
14- | { command : "preview" | "deploy" ; passthroughArgs : string [ ] }
15- | { command : "populateCache" ; target : WranglerTarget }
15+ | {
16+ command : "preview" | "deploy" ;
17+ passthroughArgs : string [ ] ;
18+ }
19+ | {
20+ command : "populateCache" ;
21+ target : WranglerTarget ;
22+ environment ?: string ;
23+ }
1624) & { outputDir ?: string } ;
1725
1826export function getArgs ( ) : Arguments {
@@ -29,6 +37,8 @@ export function getArgs(): Arguments {
2937 const outputDir = values . output ? resolve ( values . output ) : undefined ;
3038 if ( outputDir ) assertDirArg ( outputDir , "output" , true ) ;
3139
40+ const passthroughArgs = getPassthroughArgs ( ) ;
41+
3242 switch ( positionals [ 0 ] ) {
3343 case "build" :
3444 return {
@@ -43,12 +53,21 @@ export function getArgs(): Arguments {
4353 } ;
4454 case "preview" :
4555 case "deploy" :
46- return { command : positionals [ 0 ] , outputDir, passthroughArgs : getPassthroughArgs ( ) } ;
56+ return {
57+ command : positionals [ 0 ] ,
58+ outputDir,
59+ passthroughArgs,
60+ } ;
4761 case "populateCache" :
4862 if ( ! isWranglerTarget ( positionals [ 1 ] ) ) {
4963 throw new Error ( `Error: invalid target for populating the cache, expected 'local' | 'remote'` ) ;
5064 }
51- return { command : "populateCache" , outputDir, target : positionals [ 1 ] } ;
65+ return {
66+ command : "populateCache" ,
67+ outputDir,
68+ target : positionals [ 1 ] ,
69+ environment : getWranglerEnvironmentFlag ( passthroughArgs ) ,
70+ } ;
5271 default :
5372 throw new Error ( "Error: invalid command, expected 'build' | 'preview' | 'deploy' | 'populateCache'" ) ;
5473 }
0 commit comments