Skip to content

Commit b0fac8d

Browse files
committed
chore: wip
1 parent 19ff0cd commit b0fac8d

File tree

13 files changed

+74
-54
lines changed

13 files changed

+74
-54
lines changed

.stacks/core/buddy/src/commands/dev.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function dev(buddy: CLI) {
8383
log.info('buddy dev:components result', result)
8484

8585
if (result.isErr()) {
86-
await outro('While running the dev:components command, there was an issue', { startTime: perf, useSeconds: true, isError: true }, result.error ?? undefined)
86+
await outro('While running the dev:components command, there was an issue', { startTime: perf, useSeconds: true, isError: true }, result.error)
8787
process.exit()
8888
}
8989

@@ -111,7 +111,7 @@ export function dev(buddy: CLI) {
111111

112112
// check if result is an error
113113
else if (result.isErr()) {
114-
await outro('While running the dev:components command, there was an issue', { startTime: perf, useSeconds: true, isError: true }, result.error ?? undefined)
114+
await outro('While running the dev:components command, there was an issue', { startTime: perf, useSeconds: true, isError: true }, result.error)
115115
process.exit()
116116
}
117117

.stacks/core/cloud/deploy.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
#!/usr/bin/env node
22
import * as cdk from 'aws-cdk-lib'
33
import { app as a, services as s } from '@stacksjs/config'
4-
import { env } from '@stacksjs/env'
4+
import { projectPath } from '@stacksjs/path'
5+
import { env, loadEnv } from '@stacksjs/env'
56
import { StacksCloud } from './src/cloud.js'
67

8+
// console.log('env', )
9+
710
const app = new cdk.App()
8-
const cloudName = `StacksCloud`
11+
const cloudName = `stacks-cloud`
12+
let accountId = env.AWS_ACCOUNT_ID;
13+
let region = env.AWS_DEFAULT_REGION;
14+
15+
if (!accountId || !region) {
16+
console.log('Missing accountId or region in config, fetching from AWS')
17+
console.log('envenv', env)
18+
process.exit(1)
19+
// Fetch accountId and region here
20+
}
21+
22+
let bucketName = `stacks-cloud-${a.env}-assets-${accountId}-${region}`;
923

1024
console.log('env', process.env)
1125

1226
// eslint-disable-next-line no-new
1327
new StacksCloud(app, cloudName, {
28+
// toolkitStackName: `${cloudName}-toolkit`,
1429
description: 'This stack includes all of your Stacks cloud resources.',
1530
env: {
1631
account: s.aws?.accountId,
@@ -19,7 +34,7 @@ new StacksCloud(app, cloudName, {
1934
},
2035
synthesizer: new cdk.DefaultStackSynthesizer({
2136
qualifier: a.env,
22-
fileAssetsBucketName: 'stacks-cloud-${Qualifier}-assets-${AWS::AccountId}-${AWS::Region}',
37+
fileAssetsBucketName: bucketName,
2338
bucketPrefix: '',
2439
}),
2540
})

.stacks/core/cloud/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"constructs": "^10.2.69"
6161
},
6262
"devDependencies": {
63-
"@stacksjs/development": "workspace:*"
63+
"@stacksjs/development": "workspace:*",
64+
"@stacksjs/env": "workspace:*"
6465
}
6566
}

.stacks/core/cloud/src/cloud.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { app } from '@stacksjs/config'
1+
import { app, security } from '@stacksjs/config'
22
// import { publicPath } from '@stacksjs/path'
33
import {
44
Duration,
@@ -65,24 +65,7 @@ export class StacksCloud extends Stack {
6565
cloudWatchMetricsEnabled: true,
6666
metricName: 'webAclMetric',
6767
},
68-
rules: [
69-
{
70-
action: { block: {} },
71-
name: 'RateLimitRule',
72-
priority: 0,
73-
statement: {
74-
rateBasedStatement: {
75-
aggregateKeyType: 'IP',
76-
limit: 2000,
77-
},
78-
},
79-
visibilityConfig: {
80-
sampledRequestsEnabled: true,
81-
cloudWatchMetricsEnabled: true,
82-
metricName: 'rateLimitRuleMetric',
83-
},
84-
},
85-
],
68+
rules: security.appFirewall.rules,
8669
})
8770

8871
const originAccessIdentity = new cloudfront.OriginAccessIdentity(this, 'OAI')

.stacks/core/env/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { log, runCommand } from '@stacksjs/cli'
22

3-
const result = await runCommand('bun build ./src/index.ts --outdir dist --format esm', {
3+
const result = await runCommand('bun build ./src/index.ts --external vite --outdir dist --format esm', {
44
cwd: import.meta.dir,
55
})
66

.stacks/core/env/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"prepublishOnly": "bun --bun run build"
4646
},
4747
"devDependencies": {
48-
"@stacksjs/development": "workspace:*"
48+
"@stacksjs/development": "workspace:*",
49+
"@stacksjs/path": "workspace:*"
4950
}
5051
}

.stacks/core/env/src/index.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import process from 'node:process'
2+
import { loadEnv } from 'vite'
3+
import { projectPath } from '@stacksjs/path'
24

35
export interface Env {
46
APP_NAME: string
@@ -121,6 +123,24 @@ export interface FrontendEnv {
121123
export type EnvKeys = keyof Env
122124
export type FrontendEnvKeys = keyof FrontendEnv
123125

124-
export const env: Partial<Env> = process.env
126+
const handler = {
127+
get(target: NodeJS.ProcessEnv, prop: string) {
128+
console.log('get is called', prop)
129+
process.env = loadEnv(process.env.NODE_ENV || 'development', projectPath(), '')
130+
return target[prop];
131+
}
132+
};
133+
134+
export { loadEnv }
135+
136+
// env('APP_NAME', 'Stacks')
137+
// env().APP_NAME
138+
// env.APP_NAME
139+
// config.app.name
140+
141+
// export function env(key?: EnvKeys): string {
142+
// return process.env[key] ?? process.env
143+
// }
144+
145+
export const env: Partial<Env> = new Proxy(process.env, handler); // fancy way to not have to call env() everywhere
125146

126-
// export { loadEnv } from 'vite'

.stacks/core/types/src/security.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface SecurityOptions {
1313
rules: {
1414
name: string
1515
priority: number
16-
action: 'allow' | 'block'
16+
action: { block?: {}, allow?: {} }
1717
visibilityConfig: {
1818
sampledRequestsEnabled: boolean
1919
cloudWatchMetricsEnabled: boolean

bun.lockb

-516 Bytes
Binary file not shown.

config/app.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { env } from '@stacksjs/env'
99
* you have any questions, feel free to reach out via Discord or GitHub Discussions.
1010
*/
1111
export default {
12-
name: env.APP_NAME ?? 'Stacks',
13-
env: env.APP_ENV ?? 'development',
14-
url: env.APP_URL ?? 'stacks.test',
15-
debug: env.APP_DEBUG ?? false,
12+
name: env.APP_NAME || 'Stacks',
13+
env: env.APP_ENV || 'development',
14+
url: env.APP_URL || 'stacks.test',
15+
debug: env.APP_DEBUG || false,
1616
key: env.APP_KEY,
1717

1818
timezone: 'UTC',

0 commit comments

Comments
 (0)