@@ -4,8 +4,10 @@ import { intro, italic, log, outro, runCommand } from '@stacksjs/cli'
4
4
import { app } from '@stacksjs/config'
5
5
import { addDomain , hasUserDomainBeenAddedToCloud } from '@stacksjs/dns'
6
6
import { Action } from '@stacksjs/enums'
7
+ import { path as p } from '@stacksjs/path'
7
8
import { ExitCode } from '@stacksjs/types'
8
9
import type { CLI , DeployOptions } from '@stacksjs/types'
10
+ import { $ } from 'bun'
9
11
10
12
export function deploy ( buddy : CLI ) {
11
13
const descriptions = {
@@ -35,6 +37,7 @@ export function deploy(buddy: CLI) {
35
37
log . info ( `Deploying to ${ italic ( domain ) } ` )
36
38
37
39
await checkIfAwsIsConfigured ( )
40
+ await checkIfAwsIsBootstrapped ( )
38
41
39
42
options . domain = await configureDomain ( domain , options , startTime )
40
43
@@ -130,3 +133,33 @@ async function checkIfAwsIsConfigured() {
130
133
131
134
log . success ( 'AWS is configured' )
132
135
}
136
+
137
+ async function checkIfAwsIsBootstrapped ( ) {
138
+ try {
139
+ log . info ( 'Ensuring AWS is bootstrapped...' )
140
+ // const toolkitName = 'stacks-toolkit'
141
+ await runCommand ( 'aws cloudformation describe-stacks --stack-name stacks-toolkit' , { silent : true } )
142
+ // await $`aws cloudformation describe-stacks --stack-name stacks-toolkit`.quiet()
143
+ log . success ( 'AWS is bootstrapped' )
144
+
145
+ return true
146
+ } catch ( err : any ) {
147
+ log . debug ( `Not yet bootstrapped. Failed with code ${ err . exitCode } ` )
148
+ log . debug ( err . stdout . toString ( ) )
149
+ log . debug ( err . stderr . toString ( ) )
150
+
151
+ log . info ( 'AWS is not bootstrapped yet' )
152
+ log . info ( 'Bootstrapping. This may take a few moments...' )
153
+
154
+ try {
155
+ $ . cwd ( p . frameworkPath ( 'cloud' ) )
156
+ const result = await $ `bun run bootstrap`
157
+ console . log ( result )
158
+ return true
159
+ } catch ( error ) {
160
+ log . error ( 'Failed to bootstrap AWS' )
161
+ console . error ( error )
162
+ process . exit ( ExitCode . FatalError )
163
+ }
164
+ }
165
+ }
0 commit comments