1
1
/* eslint-disable @typescript-eslint/no-shadow */ // yargs
2
2
import * as cxapi from '@aws-cdk/cx-api' ;
3
- import type { DeploymentMethod } from '@aws-cdk/toolkit-lib' ;
3
+ import type { ChangeSetDeployment , DeploymentMethod , DirectDeployment } from '@aws-cdk/toolkit-lib' ;
4
4
import { ToolkitError } from '@aws-cdk/toolkit-lib' ;
5
5
import * as chalk from 'chalk' ;
6
6
import { CdkToolkit , AssetBuildTime } from './cdk-toolkit' ;
@@ -322,43 +322,6 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
322
322
throw new ToolkitError ( 'Can not supply both --[no-]execute and --method at the same time' ) ;
323
323
}
324
324
325
- let deploymentMethod : DeploymentMethod | undefined ;
326
- switch ( args . method ) {
327
- case 'direct' :
328
- if ( args . changeSetName ) {
329
- throw new ToolkitError ( '--change-set-name cannot be used with method=direct' ) ;
330
- }
331
- if ( args . importExistingResources ) {
332
- throw new ToolkitError ( '--import-existing-resources cannot be enabled with method=direct' ) ;
333
- }
334
- deploymentMethod = { method : 'direct' } ;
335
- break ;
336
- case 'change-set' :
337
- deploymentMethod = {
338
- method : 'change-set' ,
339
- execute : true ,
340
- changeSetName : args . changeSetName ,
341
- importExistingResources : args . importExistingResources ,
342
- } ;
343
- break ;
344
- case 'prepare-change-set' :
345
- deploymentMethod = {
346
- method : 'change-set' ,
347
- execute : false ,
348
- changeSetName : args . changeSetName ,
349
- importExistingResources : args . importExistingResources ,
350
- } ;
351
- break ;
352
- case undefined :
353
- deploymentMethod = {
354
- method : 'change-set' ,
355
- execute : args . execute ?? true ,
356
- changeSetName : args . changeSetName ,
357
- importExistingResources : args . importExistingResources ,
358
- } ;
359
- break ;
360
- }
361
-
362
325
return cli . deploy ( {
363
326
selector,
364
327
exclusively : args . exclusively ,
@@ -368,15 +331,14 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
368
331
requireApproval : configuration . settings . get ( [ 'requireApproval' ] ) ,
369
332
reuseAssets : args [ 'build-exclude' ] ,
370
333
tags : configuration . settings . get ( [ 'tags' ] ) ,
371
- deploymentMethod,
334
+ deploymentMethod : determineDeploymentMethod ( args , configuration ) ,
372
335
force : args . force ,
373
336
parameters : parameterMap ,
374
337
usePreviousParameters : args [ 'previous-parameters' ] ,
375
338
outputsFile : configuration . settings . get ( [ 'outputsFile' ] ) ,
376
339
progress : configuration . settings . get ( [ 'progress' ] ) ,
377
340
ci : args . ci ,
378
341
rollback : configuration . settings . get ( [ 'rollback' ] ) ,
379
- hotswap : determineHotswapMode ( args . hotswap , args . hotswapFallback ) ,
380
342
watch : args . watch ,
381
343
traceLogs : args . logs ,
382
344
concurrency : args . concurrency ,
@@ -424,14 +386,10 @@ export async function exec(args: string[], synthesizer?: Synthesizer): Promise<n
424
386
toolkitStackName,
425
387
roleArn : args . roleArn ,
426
388
reuseAssets : args [ 'build-exclude' ] ,
427
- deploymentMethod : {
428
- method : 'change-set' ,
429
- changeSetName : args . changeSetName ,
430
- } ,
389
+ deploymentMethod : determineDeploymentMethod ( args , configuration , true ) ,
431
390
force : args . force ,
432
391
progress : configuration . settings . get ( [ 'progress' ] ) ,
433
392
rollback : configuration . settings . get ( [ 'rollback' ] ) ,
434
- hotswap : determineHotswapMode ( args . hotswap , args . hotswapFallback , true ) ,
435
393
traceLogs : args . logs ,
436
394
concurrency : args . concurrency ,
437
395
} ) ;
@@ -565,6 +523,65 @@ function arrayFromYargs(xs: string[]): string[] | undefined {
565
523
return xs . filter ( ( x ) => x !== '' ) ;
566
524
}
567
525
526
+ function determineDeploymentMethod ( args : any , configuration : Configuration , watch ?: boolean ) : DeploymentMethod {
527
+ let deploymentMethod : ChangeSetDeployment | DirectDeployment | undefined ;
528
+ switch ( args . method ) {
529
+ case 'direct' :
530
+ if ( args . changeSetName ) {
531
+ throw new ToolkitError ( '--change-set-name cannot be used with method=direct' ) ;
532
+ }
533
+ if ( args . importExistingResources ) {
534
+ throw new ToolkitError ( '--import-existing-resources cannot be enabled with method=direct' ) ;
535
+ }
536
+ deploymentMethod = { method : 'direct' } ;
537
+ break ;
538
+ case 'change-set' :
539
+ deploymentMethod = {
540
+ method : 'change-set' ,
541
+ execute : true ,
542
+ changeSetName : args . changeSetName ,
543
+ importExistingResources : args . importExistingResources ,
544
+ } ;
545
+ break ;
546
+ case 'prepare-change-set' :
547
+ deploymentMethod = {
548
+ method : 'change-set' ,
549
+ execute : false ,
550
+ changeSetName : args . changeSetName ,
551
+ importExistingResources : args . importExistingResources ,
552
+ } ;
553
+ break ;
554
+ case undefined :
555
+ default :
556
+ deploymentMethod = {
557
+ method : 'change-set' ,
558
+ execute : watch ? true : args . execute ?? true ,
559
+ changeSetName : args . changeSetName ,
560
+ importExistingResources : args . importExistingResources ,
561
+ } ;
562
+ break ;
563
+ }
564
+
565
+ const hotswapMode = determineHotswapMode ( args . hotswap , args . hotswapFallback , watch ) ;
566
+ const hotswapProperties = configuration . settings . get ( [ 'hotswap' ] ) || { } ;
567
+ switch ( hotswapMode ) {
568
+ case HotswapMode . FALL_BACK :
569
+ return {
570
+ method : 'hotswap' ,
571
+ properties : hotswapProperties ,
572
+ fallback : deploymentMethod ,
573
+ } ;
574
+ case HotswapMode . HOTSWAP_ONLY :
575
+ return {
576
+ method : 'hotswap' ,
577
+ properties : hotswapProperties ,
578
+ } ;
579
+ default :
580
+ case HotswapMode . FULL_DEPLOYMENT :
581
+ return deploymentMethod ;
582
+ }
583
+ }
584
+
568
585
function determineHotswapMode ( hotswap ?: boolean , hotswapFallback ?: boolean , watch ?: boolean ) : HotswapMode {
569
586
if ( hotswap && hotswapFallback ) {
570
587
throw new ToolkitError ( 'Can not supply both --hotswap and --hotswap-fallback at the same time' ) ;
0 commit comments