Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit c2d6b02

Browse files
committed
🐛 fix(cdk flags): cleaned cdk args, hotswap off by default, turnable with flag (#78)
Hotswap is turned off by default to avoid confusion and errors for first-time deployment. It's configurable with flag. #78
1 parent 7bf6d05 commit c2d6b02

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

lib/cli.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ program
6464
.option('--domainNamePrefix <prefix>', 'Prefix for creating DNS records, if left undefined, hostedZone will be used (example: app).', undefined)
6565
.option('--customApiDomain <domain>', 'Domain to forward the requests to /api routes, by default API routes will be handled by the server lambda.', undefined)
6666
.option('--redirectFromApex', 'Redirect from apex domain to specified address.', false)
67-
.option('--profile <name>', 'AWS profile to use with CDK', undefined)
67+
.option('--profile <name>', 'AWS profile to use with CDK.', undefined)
68+
.option('--hotswap', 'Hotswap stack to speedup deployment.', false)
6869
.action(async (options) => {
6970
console.log('Our config is: ', options)
7071
const {
@@ -81,6 +82,7 @@ program
8182
domainNamePrefix,
8283
customApiDomain,
8384
redirectFromApex,
85+
hotswap,
8486
profile,
8587
} = options
8688

@@ -99,6 +101,7 @@ program
99101
domainNamePrefix,
100102
customApiDomain,
101103
redirectFromApex,
104+
hotswap,
102105
profile,
103106
}),
104107
)

lib/cli/deploy.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface Props {
1515
domainNamePrefix?: string
1616
redirectFromApex?: boolean
1717
profile?: string
18+
hotswap: boolean
1819
}
1920

2021
const cdkExecutable = require.resolve('aws-cdk/bin/cdk')
@@ -33,11 +34,21 @@ export const deployHandler = async ({
3334
hostedZone,
3435
customApiDomain,
3536
redirectFromApex,
37+
hotswap,
3638
profile,
3739
}: Props) => {
3840
// All paths are absolute.
39-
const cdkApp = `node ${appPath}`
40-
const cdkCiFlags = `--require-approval never --ci --hotswap` + profile ? ` --profile ${profile}` : ``
41+
const cdkBootstrapArgs = [`--app "node ${appPath}"`]
42+
const cdkDeployArgs = [`--app "node ${appPath}"`, '--require-approval never', '--ci']
43+
44+
if (hotswap) {
45+
cdkDeployArgs.push(`--hotswap`)
46+
}
47+
48+
if (profile) {
49+
cdkDeployArgs.push(`--profile ${profile}`)
50+
cdkBootstrapArgs.push(`--profile ${profile}`)
51+
}
4152

4253
const variables = {
4354
STACK_NAME: stackName,
@@ -55,13 +66,13 @@ export const deployHandler = async ({
5566

5667
if (bootstrap) {
5768
await executeAsyncCmd({
58-
cmd: `${cdkExecutable} bootstrap --app "${cdkApp}"`,
69+
cmd: `${cdkExecutable} bootstrap ${cdkBootstrapArgs.join(' ')}`,
5970
env: variables,
6071
})
6172
}
6273

6374
await executeAsyncCmd({
64-
cmd: `${cdkExecutable} deploy --app "${cdkApp}" ${cdkCiFlags}`,
75+
cmd: `${cdkExecutable} deploy ${cdkDeployArgs.join(' ')}`,
6576
env: variables,
6677
})
6778
}

lib/cli/remove.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ interface Props {
1010
const cdkExecutable = require.resolve('aws-cdk/bin/cdk')
1111

1212
export const removeHandler = async ({ appPath, stackName, region, profile }: Props) => {
13-
const cdkApp = `node ${appPath}`
14-
const cdkCiFlags = `--force --ci` + profile ? ` --profile ${profile}` : ``
13+
const cdkRemoveArgs = [`--app "node ${appPath}"`, '--force', '--require-approval never', '--ci']
14+
15+
if (profile) {
16+
cdkRemoveArgs.push(`--profile ${profile}`)
17+
}
1518

1619
const variables = {
1720
STACK_NAME: stackName,
1821
...(region && { AWS_REGION: region }),
1922
}
2023

2124
await executeAsyncCmd({
22-
cmd: `${cdkExecutable} destroy --app "${cdkApp}" ${cdkCiFlags}`,
25+
cmd: `${cdkExecutable} destroy ${cdkRemoveArgs.join(' ')}`,
2326
env: variables,
2427
})
2528
}

lib/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export const executeAsyncCmd = async ({ cmd, path, env }: CommandProps) => {
8888
}
8989

9090
return new Promise((resolve, reject) => {
91+
console.log('Executing command: ', cmd)
9192
const sh = exec(cmd, { env: { ...process.env, ...env } }, (error, stdout, stderr) => {
9293
if (error) {
9394
reject(error)

0 commit comments

Comments
 (0)