Skip to content

Commit e17d674

Browse files
committed
chore: wip
1 parent 17277cb commit e17d674

File tree

7 files changed

+329
-269
lines changed

7 files changed

+329
-269
lines changed

.stacks/auto-imports.d.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ declare global {
5555
const authPath: typeof import('./core/path/src/index')['authPath']
5656
const autoResetRef: typeof import('./core/utils/src/vendors')['autoResetRef']
5757
const backendEnv: typeof import('./core/validation/src/validate')['backendEnv']
58+
const backendEnvValidation: typeof import('./core/validation/src/validate')['backendEnvValidation']
5859
const backendEnvValidations: typeof import('./core/validation/src/validate')['backendEnvValidations']
5960
const base64Encode: typeof import('./core/security/src/hash')['base64Encode']
6061
const base64Verify: typeof import('./core/security/src/hash')['base64Verify']
@@ -232,12 +233,14 @@ declare global {
232233
const ensurePrefix: typeof import('./core/strings/src/utils')['ensurePrefix']
233234
const ensureSuffix: typeof import('./core/strings/src/utils')['ensureSuffix']
234235
const env: typeof import('./core/validation/src/validate')['env']
236+
const envValidation: typeof import('./core/validation/src/validate')['envValidation']
235237
const envValidations: typeof import('./core/validation/src/validate')['envValidations']
236238
const equal: typeof import('./core/utils/src/currency')['equal']
237239
const err: typeof import('./core/error-handling/src/index')['err']
238240
const errAsync: typeof import('./core/error-handling/src/index')['errAsync']
239241
const errorHandler: typeof import('./core/error-handling/src/index')['errorHandler']
240242
const errorHandlingPath: typeof import('./core/path/src/index')['errorHandlingPath']
243+
const errorMessageOptions: typeof import('./core/validation/src/validate')['errorMessageOptions']
241244
const eslint: typeof import('./core/lint/src/index')['eslint']
242245
const events: typeof import('./core/events/src/index')['events']
243246
const eventsPath: typeof import('./core/path/src/index')['eventsPath']
@@ -264,6 +267,7 @@ declare global {
264267
const fromSafePromise: typeof import('./core/error-handling/src/index')['fromSafePromise']
265268
const fromThrowable: typeof import('./core/error-handling/src/index')['fromThrowable']
266269
const frontendEnv: typeof import('./core/validation/src/validate')['frontendEnv']
270+
const frontendEnvValidation: typeof import('./core/validation/src/validate')['frontendEnvValidation']
267271
const frontendEnvValidations: typeof import('./core/validation/src/validate')['frontendEnvValidations']
268272
const fs: typeof import('./core/storage/src/index')['fs']
269273
const functionsPath: typeof import('./core/path/src/index')['functionsPath']
@@ -285,6 +289,7 @@ declare global {
285289
const green: typeof import('./core/cli/src/utilities')['green']
286290
const gupshup: typeof import('./core/sms/src/index')['gupshup']
287291
const h: typeof import('vue')['h']
292+
const handleError: typeof import('./core/error-handling/src/index')['handleError']
288293
const hasComponents: typeof import('./core/storage/src/index')['hasComponents']
289294
const hasFiles: typeof import('./core/storage/src/index')['hasFiles']
290295
const hasFunctions: typeof import('./core/storage/src/index')['hasFunctions']
@@ -693,6 +698,7 @@ declare global {
693698
const useElementSize: typeof import('./core/utils/src/vendors')['useElementSize']
694699
const useElementVisibility: typeof import('./core/utils/src/vendors')['useElementVisibility']
695700
const useEmail: typeof import('./core/notifications/src/index')['useEmail']
701+
const useEnv: typeof import('./core/validation/src/validate')['useEnv']
696702
const useEvent: typeof import('./core/events/src/index')['useEvent']
697703
const useEventBus: typeof import('./core/utils/src/vendors')['useEventBus']
698704
const useEventListener: typeof import('./core/utils/src/vendors')['useEventListener']
@@ -899,7 +905,7 @@ declare module 'vue' {
899905
readonly authPath: UnwrapRef<typeof import('./core/path/src/index')['authPath']>
900906
readonly autoResetRef: UnwrapRef<typeof import('./core/utils/src/vendors')['autoResetRef']>
901907
readonly backendEnv: UnwrapRef<typeof import('./core/validation/src/validate')['backendEnv']>
902-
readonly backendEnvValidations: UnwrapRef<typeof import('./core/validation/src/validate')['backendEnvValidations']>
908+
readonly backendEnvValidation: UnwrapRef<typeof import('./core/validation/src/validate')['backendEnvValidation']>
903909
readonly base64Encode: UnwrapRef<typeof import('./core/security/src/hash')['base64Encode']>
904910
readonly base64Verify: UnwrapRef<typeof import('./core/security/src/hash')['base64Verify']>
905911
readonly basename: UnwrapRef<typeof import('./core/path/src/index')['basename']>
@@ -1076,12 +1082,12 @@ declare module 'vue' {
10761082
readonly ensurePrefix: UnwrapRef<typeof import('./core/strings/src/utils')['ensurePrefix']>
10771083
readonly ensureSuffix: UnwrapRef<typeof import('./core/strings/src/utils')['ensureSuffix']>
10781084
readonly env: UnwrapRef<typeof import('./core/validation/src/validate')['env']>
1079-
readonly envValidations: UnwrapRef<typeof import('./core/validation/src/validate')['envValidations']>
1085+
readonly envValidation: UnwrapRef<typeof import('./core/validation/src/validate')['envValidation']>
10801086
readonly equal: UnwrapRef<typeof import('./core/utils/src/currency')['equal']>
10811087
readonly err: UnwrapRef<typeof import('./core/error-handling/src/index')['err']>
10821088
readonly errAsync: UnwrapRef<typeof import('./core/error-handling/src/index')['errAsync']>
1083-
readonly errorHandler: UnwrapRef<typeof import('./core/error-handling/src/index')['errorHandler']>
10841089
readonly errorHandlingPath: UnwrapRef<typeof import('./core/path/src/index')['errorHandlingPath']>
1090+
readonly errorMessageOptions: UnwrapRef<typeof import('./core/validation/src/validate')['errorMessageOptions']>
10851091
readonly eslint: UnwrapRef<typeof import('./core/lint/src/index')['eslint']>
10861092
readonly events: UnwrapRef<typeof import('./core/events/src/index')['events']>
10871093
readonly eventsPath: UnwrapRef<typeof import('./core/path/src/index')['eventsPath']>
@@ -1108,7 +1114,7 @@ declare module 'vue' {
11081114
readonly fromSafePromise: UnwrapRef<typeof import('./core/error-handling/src/index')['fromSafePromise']>
11091115
readonly fromThrowable: UnwrapRef<typeof import('./core/error-handling/src/index')['fromThrowable']>
11101116
readonly frontendEnv: UnwrapRef<typeof import('./core/validation/src/validate')['frontendEnv']>
1111-
readonly frontendEnvValidations: UnwrapRef<typeof import('./core/validation/src/validate')['frontendEnvValidations']>
1117+
readonly frontendEnvValidation: UnwrapRef<typeof import('./core/validation/src/validate')['frontendEnvValidation']>
11121118
readonly fs: UnwrapRef<typeof import('./core/storage/src/index')['fs']>
11131119
readonly functionsPath: UnwrapRef<typeof import('./core/path/src/index')['functionsPath']>
11141120
readonly generateAppKey: UnwrapRef<typeof import('./core/security/src/key')['generateAppKey']>
@@ -1129,6 +1135,7 @@ declare module 'vue' {
11291135
readonly green: UnwrapRef<typeof import('./core/cli/src/utilities')['green']>
11301136
readonly gupshup: UnwrapRef<typeof import('./core/sms/src/index')['gupshup']>
11311137
readonly h: UnwrapRef<typeof import('vue')['h']>
1138+
readonly handleError: UnwrapRef<typeof import('./core/error-handling/src/index')['handleError']>
11321139
readonly hasComponents: UnwrapRef<typeof import('./core/storage/src/index')['hasComponents']>
11331140
readonly hasFiles: UnwrapRef<typeof import('./core/storage/src/index')['hasFiles']>
11341141
readonly hasFunctions: UnwrapRef<typeof import('./core/storage/src/index')['hasFunctions']>
@@ -1537,6 +1544,7 @@ declare module 'vue' {
15371544
readonly useElementSize: UnwrapRef<typeof import('./core/utils/src/vendors')['useElementSize']>
15381545
readonly useElementVisibility: UnwrapRef<typeof import('./core/utils/src/vendors')['useElementVisibility']>
15391546
readonly useEmail: UnwrapRef<typeof import('./core/notifications/src/index')['useEmail']>
1547+
readonly useEnv: UnwrapRef<typeof import('./core/validation/src/validate')['useEnv']>
15401548
readonly useEvent: UnwrapRef<typeof import('./core/events/src/index')['useEvent']>
15411549
readonly useEventBus: UnwrapRef<typeof import('./core/utils/src/vendors')['useEventBus']>
15421550
readonly useEventListener: UnwrapRef<typeof import('./core/utils/src/vendors')['useEventListener']>
@@ -1737,7 +1745,7 @@ declare module '@vue/runtime-core' {
17371745
readonly authPath: UnwrapRef<typeof import('./core/path/src/index')['authPath']>
17381746
readonly autoResetRef: UnwrapRef<typeof import('./core/utils/src/vendors')['autoResetRef']>
17391747
readonly backendEnv: UnwrapRef<typeof import('./core/validation/src/validate')['backendEnv']>
1740-
readonly backendEnvValidations: UnwrapRef<typeof import('./core/validation/src/validate')['backendEnvValidations']>
1748+
readonly backendEnvValidation: UnwrapRef<typeof import('./core/validation/src/validate')['backendEnvValidation']>
17411749
readonly base64Encode: UnwrapRef<typeof import('./core/security/src/hash')['base64Encode']>
17421750
readonly base64Verify: UnwrapRef<typeof import('./core/security/src/hash')['base64Verify']>
17431751
readonly basename: UnwrapRef<typeof import('./core/path/src/index')['basename']>
@@ -1914,12 +1922,12 @@ declare module '@vue/runtime-core' {
19141922
readonly ensurePrefix: UnwrapRef<typeof import('./core/strings/src/utils')['ensurePrefix']>
19151923
readonly ensureSuffix: UnwrapRef<typeof import('./core/strings/src/utils')['ensureSuffix']>
19161924
readonly env: UnwrapRef<typeof import('./core/validation/src/validate')['env']>
1917-
readonly envValidations: UnwrapRef<typeof import('./core/validation/src/validate')['envValidations']>
1925+
readonly envValidation: UnwrapRef<typeof import('./core/validation/src/validate')['envValidation']>
19181926
readonly equal: UnwrapRef<typeof import('./core/utils/src/currency')['equal']>
19191927
readonly err: UnwrapRef<typeof import('./core/error-handling/src/index')['err']>
19201928
readonly errAsync: UnwrapRef<typeof import('./core/error-handling/src/index')['errAsync']>
1921-
readonly errorHandler: UnwrapRef<typeof import('./core/error-handling/src/index')['errorHandler']>
19221929
readonly errorHandlingPath: UnwrapRef<typeof import('./core/path/src/index')['errorHandlingPath']>
1930+
readonly errorMessageOptions: UnwrapRef<typeof import('./core/validation/src/validate')['errorMessageOptions']>
19231931
readonly eslint: UnwrapRef<typeof import('./core/lint/src/index')['eslint']>
19241932
readonly events: UnwrapRef<typeof import('./core/events/src/index')['events']>
19251933
readonly eventsPath: UnwrapRef<typeof import('./core/path/src/index')['eventsPath']>
@@ -1946,7 +1954,7 @@ declare module '@vue/runtime-core' {
19461954
readonly fromSafePromise: UnwrapRef<typeof import('./core/error-handling/src/index')['fromSafePromise']>
19471955
readonly fromThrowable: UnwrapRef<typeof import('./core/error-handling/src/index')['fromThrowable']>
19481956
readonly frontendEnv: UnwrapRef<typeof import('./core/validation/src/validate')['frontendEnv']>
1949-
readonly frontendEnvValidations: UnwrapRef<typeof import('./core/validation/src/validate')['frontendEnvValidations']>
1957+
readonly frontendEnvValidation: UnwrapRef<typeof import('./core/validation/src/validate')['frontendEnvValidation']>
19501958
readonly fs: UnwrapRef<typeof import('./core/storage/src/index')['fs']>
19511959
readonly functionsPath: UnwrapRef<typeof import('./core/path/src/index')['functionsPath']>
19521960
readonly generateAppKey: UnwrapRef<typeof import('./core/security/src/key')['generateAppKey']>
@@ -1967,6 +1975,7 @@ declare module '@vue/runtime-core' {
19671975
readonly green: UnwrapRef<typeof import('./core/cli/src/utilities')['green']>
19681976
readonly gupshup: UnwrapRef<typeof import('./core/sms/src/index')['gupshup']>
19691977
readonly h: UnwrapRef<typeof import('vue')['h']>
1978+
readonly handleError: UnwrapRef<typeof import('./core/error-handling/src/index')['handleError']>
19701979
readonly hasComponents: UnwrapRef<typeof import('./core/storage/src/index')['hasComponents']>
19711980
readonly hasFiles: UnwrapRef<typeof import('./core/storage/src/index')['hasFiles']>
19721981
readonly hasFunctions: UnwrapRef<typeof import('./core/storage/src/index')['hasFunctions']>
@@ -2375,6 +2384,7 @@ declare module '@vue/runtime-core' {
23752384
readonly useElementSize: UnwrapRef<typeof import('./core/utils/src/vendors')['useElementSize']>
23762385
readonly useElementVisibility: UnwrapRef<typeof import('./core/utils/src/vendors')['useElementVisibility']>
23772386
readonly useEmail: UnwrapRef<typeof import('./core/notifications/src/index')['useEmail']>
2387+
readonly useEnv: UnwrapRef<typeof import('./core/validation/src/validate')['useEnv']>
23782388
readonly useEvent: UnwrapRef<typeof import('./core/events/src/index')['useEvent']>
23792389
readonly useEventBus: UnwrapRef<typeof import('./core/utils/src/vendors')['useEventBus']>
23802390
readonly useEventListener: UnwrapRef<typeof import('./core/utils/src/vendors')['useEventListener']>

.stacks/core/buddy/src/cli.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22
import { runAction } from '@stacksjs/actions'
3-
import { errorHandler } from '@stacksjs/error-handling'
3+
import { handleError } from '@stacksjs/error-handling'
44
import { command, log } from '@stacksjs/cli'
55
import { frontendEnv } from '@stacksjs/validation'
66
import { frameworkVersion, installIfVersionMismatch, isProjectCreated } from '@stacksjs/utils'
@@ -11,8 +11,8 @@ import { build, changelog, clean, commit, create, dev, example, fresh, generate,
1111
const cli = command('buddy')
1212

1313
// setup global error handlers
14-
process.on('uncaughtException', errorHandler)
15-
process.on('unhandledRejection', errorHandler)
14+
process.on('uncaughtException', handleError)
15+
process.on('unhandledRejection', handleError)
1616

1717
async function main() {
1818
// the following commands are not dependent on the project being initialized
@@ -25,12 +25,12 @@ async function main() {
2525
if (frontendEnv.FRONTEND_APP_ENV !== 'production')
2626
log.info('Project not yet initialized, generating application key...')
2727
else
28-
errorHandler(new Error('Please run `buddy key:generate` to generate an application key'))
28+
handleError(new Error('Please run `buddy key:generate` to generate an application key'))
2929

3030
const result = await runAction(Action.KeyGenerate, { cwd: projectPath() })
3131

3232
if (result.isErr())
33-
errorHandler(result.error as Error)
33+
handleError(result.error as Error)
3434

3535
log.info('Application key generated.')
3636

.stacks/core/build/src/vue-components.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig } from 'vite'
1+
import { defineConfig, loadEnv } from 'vite'
22
import type { ViteConfig } from '@stacksjs/types'
33
import { frameworkPath, libraryEntryPath, libsPath, projectPath } from '@stacksjs/path'
44
import type { ViteDevServer as DevServer, BuildOptions as ViteBuildOptions } from 'vite'
@@ -8,10 +8,12 @@ import mkcert from 'vite-plugin-mkcert'
88
import c from 'picocolors'
99
import { autoImports, components, cssEngine, inspect, uiEngine } from './stacks'
1010

11+
const envPrefix = ['FRONTEND_', 'APP_', 'DB_', 'REDIS_', 'AWS_', 'MAIL_', 'SEARCH_ENGINE_', 'MEILISEARCH_']
12+
1113
export const vueComponentsConfig: ViteConfig = {
1214
root: frameworkPath('libs/components/vue'),
1315
envDir: projectPath(),
14-
envPrefix: 'FRONTEND_',
16+
envPrefix,
1517

1618
server: {
1719
https: true,
@@ -46,8 +48,6 @@ export const vueComponentsConfig: ViteConfig = {
4648
configureServer(server: DevServer) {
4749
// const base = server.config.base || '/'
4850
// const _print = server.printUrls
49-
50-
// Example: wait for a client to connect before sending a message
5151
server.printUrls = () => {
5252
// const url = server.resolvedUrls?.local[0]
5353
//
@@ -66,30 +66,29 @@ export const vueComponentsConfig: ViteConfig = {
6666
const appUrl = app.url
6767
const frontendUrl = `https://${appUrl}`
6868
const backendUrl = `https://api.${appUrl}`
69+
const dashboardUrl = `https://admin.${appUrl}`
6970
const libraryUrl = `https://libs.${appUrl}`
7071
const docsUrl = `https://docs.${appUrl}`
7172
const inspectUrl = `https://${appUrl}/__inspect/`
7273

74+
// const pkg = await storage.readPackageJson(frameworkPath('./package.json')) // TODO: fix this async call placing `press h to show help` on top
75+
const stacksVersion = 'alpha-0.x.x'
76+
77+
// eslint-disable-next-line no-console
78+
console.log(` ${c.blue(c.bold('STACKS'))} ${c.blue(stacksVersion)}`)
7379
// eslint-disable-next-line no-console
7480
console.log(` ${c.green('➜')} ${c.bold('Frontend')}: ${c.green(frontendUrl)}`)
7581
// eslint-disable-next-line no-console
7682
console.log(` ${c.green('➜')} ${c.bold('Backend')}: ${c.green(backendUrl)}`)
7783
// eslint-disable-next-line no-console
84+
console.log(` ${c.green('➜')} ${c.bold('Dashboard')}: ${c.green(dashboardUrl)}`)
85+
// eslint-disable-next-line no-console
7886
console.log(` ${c.green('➜')} ${c.bold('Library')}: ${c.green(libraryUrl)}`)
7987
// eslint-disable-next-line no-console
8088
console.log(` ${c.green('➜')} ${c.bold('Docs')}: ${c.green(docsUrl)}`)
8189
// eslint-disable-next-line no-console
82-
console.log(` ${c.green('➜')} ${c.bold('Inspect')}: ${c.green(inspectUrl)}`)
83-
84-
// if (_open && !isCI) {
85-
// // a delay is added to ensure the app page is opened first
86-
// setTimeout(() => {
87-
// openBrowser(`${host}${base}__inspect/`)
88-
// }, 500)
89-
// }
90+
console.log(` ${c.green('➜')} ${c.dim('Inspect')}: ${c.green(inspectUrl)}`)
9091
}
91-
92-
// return rpcFunctions
9392
},
9493
},
9594
],
@@ -127,7 +126,9 @@ export function vueComponentsBuildOptions(): ViteBuildOptions {
127126
}
128127
}
129128

130-
export default defineConfig(({ command }) => {
129+
export default defineConfig(({ command, mode }) => {
130+
process.env = { ...process.env, ...loadEnv(mode, projectPath(), envPrefix) }
131+
131132
if (command === 'serve')
132133
return vueComponentsConfig
133134

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const configDefaults: ResolvedStacksOptions = {
3030
ui,
3131
}
3232

33-
export async function loadStacksConfig(overrides?: Partial<StacksConfig>, cwd = process.cwd()) {
33+
export async function loadStacksConfig(overrides?: Partial<StacksConfig>, cwd = frameworkPath()) {
3434
const { config } = await loadConfig<StacksConfig>({
3535
name: 'stacks',
3636
defaults: configDefaults,

.stacks/core/error-handling/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class ErrorHandler {
2121

2222
static handleError(err: Error, options?: any) {
2323
// todo: options is currently not used
24+
// eslint-disable-next-line no-console
25+
console.log('here')
2426
log.error(err, options)
2527
this.writeErrorToFile(err, options)
2628
}
@@ -34,6 +36,6 @@ class ErrorHandler {
3436
}
3537
}
3638

37-
export function errorHandler(err: Error, options?: any): void {
39+
export function handleError(err: Error, options?: any): void {
3840
ErrorHandler.handleError(err, options)
3941
}

0 commit comments

Comments
 (0)