Skip to content

Commit 88d94da

Browse files
committed
chore: wip
1 parent 27c55ea commit 88d94da

File tree

10 files changed

+90
-29
lines changed

10 files changed

+90
-29
lines changed

.stacks/core/actions/src/domains/add.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,31 @@ if (!options.domain) {
2727
}
2828
}
2929

30-
logger.log(`Adding your domain: ${options.domain}`)
31-
3230
const result = await createHostedZone(options.domain)
3331

3432
if (result.isErr()) {
35-
handleError('Failed to add domain', result.error)
33+
handleError(result.error)
3634
process.exit(1)
3735
}
3836

3937
const nameservers = result.value
4038

4139
logger.log('')
42-
logger.log('✅ Added your domain')
43-
logger.log(` Nameservers: ${nameservers.join(', ')}`)
44-
logger.log(` Cached in: ${projectStoragePath('framework/cache/nameservers.txt')}`)
40+
logger.log('✅ Successfully added your domain.')
41+
logger.log('')
42+
logger.log('ℹ️ Please note, before you can you continue your deployment process,')
43+
logger.log(' you will need to update your nameservers to the following:')
44+
45+
const emojis = ['1️⃣', '2️⃣', '3️⃣', '4️⃣']
46+
logger.log('')
47+
nameservers.forEach((nameserver, index) => {
48+
logger.log(` ${emojis[index]} Nameserver: ${nameserver}`)
49+
})
50+
logger.log('')
51+
logger.log(italic(`cached in ${projectStoragePath('framework/cache/nameservers.txt')}`))
52+
logger.log('')
53+
logger.log('Once the nameservers have been updated, re-run the following command:')
54+
logger.log('')
55+
logger.log(`➡️ ${italic('buddy deploy')}`)
56+
logger.log('')
57+
logger.log(italic('If you have any questions, please reach out to us via Discord.'))

.stacks/core/actions/src/domains/remove.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ if (!options.domain) {
2626
}
2727
}
2828

29-
logger.log(`Removing domain: ${options.domain}`)
29+
if (options.verbose)
30+
logger.log(`Removing domain: ${options.domain}`)
3031

3132
const result = await deleteHostedZone(options.domain)
3233

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import process from 'node:process'
22
import type { CLI, DeployOptions } from '@stacksjs/types'
33
import { runAction } from '@stacksjs/actions'
4-
import { intro, outro } from '@stacksjs/cli'
4+
import { intro, italic, outro } from '@stacksjs/cli'
55
import { Action, ExitCode } from '@stacksjs/types'
6+
import { config } from '@stacksjs/config'
7+
import { Route53 } from '@aws-sdk/client-route-53'
68

79
export function deploy(buddy: CLI) {
810
const descriptions = {
@@ -12,33 +14,73 @@ export function deploy(buddy: CLI) {
1214

1315
buddy
1416
.command('deploy', descriptions.deploy)
17+
.option('--domain', 'Specify a domain to deploy to', { default: '' })
1518
.option('--verbose', descriptions.verbose, { default: false })
1619
.action(async (options: DeployOptions) => {
1720
const perf = await intro('buddy deploy')
18-
const result = await runAction(Action.Deploy, options)
21+
const domain = options.domain || config.app.url
1922

20-
if (result.isErr()) {
21-
await outro('While running the `buddy deploy`, there was an issue', { startTime: perf, useSeconds: true, isError: true }, result.error)
22-
process.exit()
23+
if (await hasUserDomainBeenAddedToCloud(domain)) {
24+
options.domain = domain
2325
}
2426

25-
await outro('Deployment succeeded.', { startTime: perf, useSeconds: true })
26-
process.exit(ExitCode.Success)
27-
})
27+
// if the domain hasn't been added to the user's (AWS) cloud, we will add it for them
28+
// and then exit the process with prompts for the user to update their nameservers
29+
else {
30+
// eslint-disable-next-line no-console
31+
console.log('')
32+
// eslint-disable-next-line no-console
33+
console.log(`ℹ️ It appears to be your first ${domain} deployment.`)
34+
// eslint-disable-next-line no-console
35+
console.log('')
36+
// eslint-disable-next-line no-console
37+
console.log(italic('Let’s ensure your it is connected properly.'))
38+
// eslint-disable-next-line no-console
39+
console.log(italic('One moment...'))
40+
// eslint-disable-next-line no-console
41+
console.log('')
2842

29-
buddy
30-
.command('deploy:domains', descriptions.deploy)
31-
.option('--verbose', descriptions.verbose, { default: false })
32-
.action(async (options: DeployOptions) => {
33-
const perf = await intro('buddy deploy:domains')
34-
const result = await runAction(Action.Deploy, { ...options, domains: true, verbose: options.verbose })
43+
options.domain = domain
44+
await addDomain(options, perf)
45+
process.exit(ExitCode.Success)
46+
}
47+
48+
// now that we know the domain has been added to the users (AWS) cloud, we can deploy
49+
const result = await runAction(Action.Deploy, options)
3550

3651
if (result.isErr()) {
3752
await outro('While running the `buddy deploy`, there was an issue', { startTime: perf, useSeconds: true, isError: true }, result.error)
38-
process.exit()
53+
process.exit(ExitCode.FatalError)
3954
}
4055

4156
await outro('Deployment succeeded.', { startTime: perf, useSeconds: true })
57+
4258
process.exit(ExitCode.Success)
4359
})
4460
}
61+
62+
async function hasUserDomainBeenAddedToCloud(domainName?: string) {
63+
const route53 = new Route53()
64+
65+
// Check if the hosted zone already exists
66+
const existingHostedZones = await route53.listHostedZonesByName({ DNSName: domainName })
67+
if (!existingHostedZones || !existingHostedZones.HostedZones)
68+
return false
69+
70+
const existingHostedZone = existingHostedZones.HostedZones.find(zone => zone.Name === `${domainName}.`)
71+
if (existingHostedZone)
72+
return true
73+
74+
return false
75+
}
76+
77+
async function addDomain(options: DeployOptions, startTime: number) {
78+
const result = await runAction(Action.DomainsAdd, options)
79+
80+
if (result.isErr()) {
81+
await outro('While running the `buddy deploy`, there was an issue', { startTime, useSeconds: true, isError: true }, result.error)
82+
process.exit(ExitCode.FatalError)
83+
}
84+
85+
await outro('Added your domain.', { startTime, useSeconds: true })
86+
}

.stacks/core/cloud/src/cloud.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export class StacksCloud extends Stack {
278278

279279
if (config.cloud.cdn?.enableLogging) {
280280
logBucket = new s3.Bucket(this, 'LogBucket', {
281-
bucketName: `${this.domain}-logs-${config.app.env}`,
281+
bucketName: `${this.domain}-logs-${config.app.env}-${Date.now()}`,
282282
removalPolicy: RemovalPolicy.DESTROY,
283283
autoDeleteObjects: true,
284284
objectOwnership: s3.ObjectOwnership.BUCKET_OWNER_PREFERRED,

.stacks/core/config/src/defaults.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export default {
177177
],
178178

179179
messages: {
180-
type: 'Select the type of change that you\'re committing:',
180+
type: 'Select the type of change that youre committing:',
181181
scope: 'Select the SCOPE of this change (optional):',
182182
customScope: 'Select the SCOPE of this change:',
183183
subject: 'Write a SHORT, IMPERATIVE tense description of the change:\n',
@@ -199,7 +199,7 @@ export default {
199199
{ value: 'test', name: 'test: ✅ Adding missing tests or adjusting existing tests', emoji: ':white_check_mark:' },
200200
{ value: 'build', name: 'build: 📦️ Changes that affect the build system or external dependencies', emoji: ':package:' },
201201
{ value: 'ci', name: 'ci: 🎡 Changes to our CI configuration files and scripts', emoji: ':ferris_wheel:' },
202-
{ value: 'chore', name: 'chore: 🔨 Other changes that don\'t modify src or test files', emoji: ':hammer:' },
202+
{ value: 'chore', name: 'chore: 🔨 Other changes that dont modify src or test files', emoji: ':hammer:' },
203203
{ value: 'revert', name: 'revert: ⏪️ Reverts a previous commit', emoji: ':rewind:' },
204204
],
205205
},

.stacks/core/storage/src/fs.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ import { mkdirSync, writeFileSync } from 'node:fs'
22
import * as fs from 'fs-extra'
33
import { pathExists as existsSync } from 'fs-extra'
44

5+
export async function exists(path: string): Promise<boolean> {
6+
return await existsSync(path)
7+
}
8+
59
export { fs, existsSync, mkdirSync, writeFileSync }

.stacks/core/types/src/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ import { type CliOptions } from './cli'
88
* you have any questions, feel free to reach out via Discord or GitHub Discussions.
99
*/
1010
export interface DeployOptions extends CliOptions {
11-
domains?: boolean
11+
domain?: string
1212
}

.stacks/core/types/src/git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export interface GitOptions {
7272
* @example
7373
* ```ts
7474
* messages: {
75-
* type: 'Select the type of change that you\'re committing:',
75+
* type: 'Select the type of change that youre committing:',
7676
* scope: 'Denote the SCOPE of this change:',
7777
* subject: 'Write a SHORT, IMPERATIVE tense description of the change:\n',
7878
* body: 'Provide a LONGER description of the change (optional). Use "|" to break new line:\n',

.stacks/ide/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ minzipped
142142
mkdirs
143143
mkdist
144144
mult
145+
nameserver
145146
netcore
146147
neverthrow
147148
nexe

config/git.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default {
2121
],
2222

2323
messages: {
24-
type: 'Select the type of change that you\'re committing:',
24+
type: 'Select the type of change that youre committing:',
2525
scope: 'Select the SCOPE of this change (optional):',
2626
customScope: 'Select the SCOPE of this change:',
2727
subject: 'Write a SHORT, IMPERATIVE tense description of the change:\n',
@@ -43,7 +43,7 @@ export default {
4343
{ value: 'test', name: 'test: ✅ Adding missing tests or adjusting existing tests', emoji: ':white_check_mark:' },
4444
{ value: 'build', name: 'build: 📦️ Changes that affect the build system or external dependencies', emoji: ':package:' },
4545
{ value: 'ci', name: 'ci: 🎡 Changes to our CI configuration files and scripts', emoji: ':ferris_wheel:' },
46-
{ value: 'chore', name: 'chore: 🔨 Other changes that don\'t modify src or test files', emoji: ':hammer:' },
46+
{ value: 'chore', name: 'chore: 🔨 Other changes that dont modify src or test files', emoji: ':hammer:' },
4747
{ value: 'revert', name: 'revert: ⏪️ Reverts a previous commit', emoji: ':rewind:' },
4848
],
4949
} satisfies GitConfig

0 commit comments

Comments
 (0)