@@ -179,21 +179,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
179179 const cwd = process . cwd ( ) ;
180180 const projectPath = resolve ( cwd , dir ) ;
181181
182- if ( dir !== "." && ! isDirectory ( projectPath ) ) {
183- if ( dir === "staging" || dir === "prod" ) {
184- throw new Error ( `To deploy to ${ dir } , you need to pass "--env ${ dir } ", not just "${ dir } ".` ) ;
185- }
186-
187- if ( dir === "production" ) {
188- throw new Error ( `To deploy to production, you need to pass "--env prod", not "production".` ) ;
189- }
190-
191- if ( dir === "stg" ) {
192- throw new Error ( `To deploy to staging, you need to pass "--env staging", not "stg".` ) ;
193- }
194-
195- throw new Error ( `Directory "${ dir } " not found at ${ projectPath } ` ) ;
196- }
182+ verifyDirectory ( dir , projectPath ) ;
197183
198184 const authorization = await login ( {
199185 embedded : true ,
@@ -228,7 +214,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
228214 options . env === "preview" ? getBranch ( { specified : options . branch , gitMeta } ) : undefined ;
229215 if ( options . env === "preview" && ! branch ) {
230216 throw new Error (
231- "You need to specify a preview branch when deploying to preview, pass --branch <branch>."
217+ "Didn't auto-detect preview branch, so you need to specify one. Pass --branch <branch>."
232218 ) ;
233219 }
234220
@@ -708,3 +694,21 @@ async function failDeploy(
708694 }
709695 }
710696}
697+
698+ export function verifyDirectory ( dir : string , projectPath : string ) {
699+ if ( dir !== "." && ! isDirectory ( projectPath ) ) {
700+ if ( dir === "staging" || dir === "prod" || dir === "preview" ) {
701+ throw new Error ( `To deploy to ${ dir } , you need to pass "--env ${ dir } ", not just "${ dir } ".` ) ;
702+ }
703+
704+ if ( dir === "production" ) {
705+ throw new Error ( `To deploy to production, you need to pass "--env prod", not "production".` ) ;
706+ }
707+
708+ if ( dir === "stg" ) {
709+ throw new Error ( `To deploy to staging, you need to pass "--env staging", not "stg".` ) ;
710+ }
711+
712+ throw new Error ( `Directory "${ dir } " not found at ${ projectPath } ` ) ;
713+ }
714+ }
0 commit comments