Skip to content

Commit 2594bc6

Browse files
committed
chore: wip
chore: wip chore: wip chore: wip chore: wip chore: wip
1 parent 84c306c commit 2594bc6

File tree

11 files changed

+133
-38
lines changed

11 files changed

+133
-38
lines changed

bun.lockb

-992 Bytes
Binary file not shown.

storage/framework/core/actions/src/deploy/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ await runCommand('bun zip.ts', {
3636
cwd: p.cloudPath(),
3737
})
3838

39-
log.info('Preparing deployment...')
39+
log.info('Preparing Deployment...')
4040

4141
const profile = process.env.AWS_PROFILE || 'stacks'
4242

storage/framework/core/buddy/src/commands/deploy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function deploy(buddy: CLI) {
3535
process.exit(ExitCode.FatalError)
3636
}
3737

38+
// TODO: we can improve this check at some point, otherwise domains that legitimately include the word localhost will fail
3839
if (domain.includes('localhost')) {
3940
log.info('You are deploying to a local environment.')
4041
log.info('Please set your .env or ./config/app.ts properly.')

storage/framework/core/buddy/src/commands/key.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ export function key(buddy: CLI) {
1616
.option('-p, --project', descriptions.project, { default: false })
1717
.option('--verbose', descriptions.verbose, { default: false })
1818
.action(async (options: KeyOptions) => {
19-
const startTime = await intro('buddy key:generate')
19+
await intro('buddy key:generate')
2020
const result = await runAction(Action.KeyGenerate, options)
2121

2222
if (result.isErr()) {
2323
log.error('Failed to set random application key.', result.error)
2424
process.exit()
2525
}
2626

27-
await outro('Random application key set.', { startTime })
27+
await outro('Random application key set.')
2828
})
2929

3030
buddy.on('key:*', () => {

storage/framework/core/buddy/src/commands/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ async function initializeProject(options: CliOptions): Promise<void> {
101101
// process.exit(ExitCode.FatalError)
102102
// }
103103

104-
// log.success('Configured AWS')
104+
log.success('Configured AWS')
105105

106106
// 1. ensure the IDE is setup by making sure .vscode etc exists, and if not, copy them over
107107
// 2. ensure the project

storage/framework/core/cli/src/helpers.ts

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { handleError } from '@stacksjs/error-handling'
44
import { log } from '@stacksjs/logging'
55
import type { IntroOptions, OutroOptions } from '@stacksjs/types'
66
import { ExitCode } from '@stacksjs/types'
7+
import { bgCyan, bold, cyan, dim, gray, green, italic } from 'kolorist'
78
import { version } from '../package.json'
8-
import { bgCyan, bold, cyan, dim, gray, green, italic } from './utilities'
99

1010
/**
1111
* Prints the intro message.
@@ -34,57 +34,47 @@ export async function intro(command: string, options?: IntroOptions): Promise<nu
3434
/**
3535
* Prints the outro message.
3636
*/
37-
export function outro(text: string, options: OutroOptions, error?: Error | string) {
38-
const message = options?.message || text
37+
export function outro(text: string, options?: OutroOptions, error?: Error | string) {
38+
const opts = {
39+
type: 'success',
40+
useSeconds: true,
41+
...options,
42+
}
43+
44+
opts.message = options?.message || text
3945

4046
return new Promise((resolve) => {
4147
if (error)
4248
return handleError(error)
4349

44-
if (options.startTime) {
45-
let time = performance.now() - options.startTime
50+
if (opts?.startTime) {
51+
let time = performance.now() - opts.startTime
4652

47-
if (options.useSeconds) {
53+
if (opts.useSeconds) {
4854
time = time / 1000
4955
time = Math.round(time * 100) / 100 // https://stackoverflow.com/a/11832950/7811162
5056
}
5157

52-
if (options.quiet === true)
58+
if (opts.quiet === true)
5359
return resolve(ExitCode.Success)
5460

5561
if (error)
56-
log.error(`[${time.toFixed(2)}${options.useSeconds ? 's' : 'ms'}] Failed`)
57-
else if (options.type === 'info')
58-
console.log(`${dim(gray(`[${time.toFixed(2)}${options.useSeconds ? 's' : 'ms'}]`))} ${message ?? 'Complete'}`)
62+
log.error(`[${time.toFixed(2)}${opts.useSeconds ? 's' : 'ms'}] Failed`)
63+
else if (opts.type === 'info')
64+
console.log(`${dim(gray(`[${time.toFixed(2)}${opts.useSeconds ? 's' : 'ms'}]`))} ${opts.message ?? 'Complete'}`)
5965
else
60-
console.log(`${dim(gray(bold(`[${time.toFixed(2)}${options.useSeconds ? 's' : 'ms'}]`)))} ${bold(green(message ?? 'Complete'))}`)
66+
console.log(`${dim(gray(bold(`[${time.toFixed(2)}${opts.useSeconds ? 's' : 'ms'}]`)))} ${bold(green(opts.message ?? 'Complete'))}`)
6167
}
6268

6369
else {
64-
if (options?.type === 'info')
70+
if (opts?.type === 'info')
6571
console.log(text)
6672

6773
// the following condition triggers in the case of "Cleaned up" messages
68-
else if (message !== text)
74+
else if (opts?.type === 'success' && opts?.quiet !== true)
6975
log.success(text)
7076
}
7177

7278
return resolve(ExitCode.Success)
7379
})
7480
}
75-
76-
// export function startSpinner(text?: string) {
77-
// if (!text)
78-
// text = 'Executing...'
79-
80-
// const spin = spinner({
81-
// text,
82-
// }).start()
83-
84-
// setTimeout(() => {
85-
// spin.text = italic('This may take a few moments...')
86-
// spin.spinner = 'clock'
87-
// }, 7500)
88-
89-
// return spin
90-
// }

storage/framework/core/cli/src/run.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,18 @@ export async function runProcess(command: string, options?: CliOptions): Promise
6868
* console.log(result)
6969
* ```
7070
*/
71-
export function runCommandSync(command: string, options?: CliOptions): Result<SyncSubprocess, CommandError> {
71+
export async function runCommandSync(command: string, options?: CliOptions): Promise<string> {
7272
if (options?.verbose)
7373
log.debug('Running command:', underline(italic(command)), 'with options:', options)
7474

75-
const result = execSync(command, options)
75+
const result = await execSync(command, options)
7676

77-
if (result.isErr())
78-
return err(result.error)
77+
// if (result.isErr())
78+
// return err(result.error)
7979

80-
return ok(result.value)
80+
// return ok(result.value)
81+
82+
return result
8183
}
8284

8385
/**

storage/framework/core/cloud/buddy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env bun
2+
import('../buddy/src/cli')
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* eslint-disable no-new */
2+
import { Duration, CfnOutput as Output, aws_lambda as lambda } from 'aws-cdk-lib'
3+
import type { Construct } from 'constructs'
4+
import type { NestedCloudProps } from '../types'
5+
6+
export interface CliStackProps extends NestedCloudProps {
7+
}
8+
9+
export class CliStack {
10+
constructor(scope: Construct, props: CliStackProps) {
11+
const cliSetupFunc = new lambda.Function(scope, 'CliSetupFunction', {
12+
functionName: `${props.slug}-${props.appEnv}-cli-setup`,
13+
description: 'Lambda function that triggers setup script for a Stacks project',
14+
runtime: lambda.Runtime.NODEJS_20_X,
15+
handler: 'index.handler',
16+
code: lambda.Code.fromAsset('src/cloud/lambda/cli-setup'), // path relative to the cloud root package dir
17+
timeout: Duration.seconds(30),
18+
})
19+
20+
// create a Lambda.FunctionUrl to be used in the CloudFront OriginRequestPolicy
21+
// this will be used to trigger the function
22+
const cliSetupUrl = new lambda.FunctionUrl(scope, 'CliSetupFunctionUrl', {
23+
function: cliSetupFunc,
24+
authType: lambda.FunctionUrlAuthType.NONE,
25+
cors: {
26+
allowedOrigins: ['*'],
27+
},
28+
})
29+
30+
new Output(scope, 'CliSetupVanityUrl', {
31+
value: `${cliSetupUrl.url}cli-setup`,
32+
})
33+
34+
// once deployed, need to create logic in the cdn origin request to check if the request is for the cli
35+
// if it is, then we need the to use the function url as the origin
36+
// if it is not, then we need don't adjust the origin
37+
}
38+
}

storage/framework/core/cloud/src/cloud/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Construct } from 'constructs'
44
import type { CloudOptions } from '../types'
55
import { AiStack } from './ai'
66
import { CdnStack } from './cdn'
7+
import { CliStack } from './cli'
78
import { DnsStack } from './dns'
89
import { DocsStack } from './docs'
910
import { StorageStack } from './storage'
@@ -89,5 +90,7 @@ export class Cloud extends Stack {
8990
privateBucket: storage.privateBucket,
9091
cdn: cdn.distribution,
9192
})
93+
94+
new CliStack(this, props)
9295
}
9396
}

0 commit comments

Comments
 (0)