Skip to content

Commit 803b2fa

Browse files
committed
chore: wip
chore: wip chore: wip
1 parent dec308b commit 803b2fa

File tree

20 files changed

+219
-101
lines changed

20 files changed

+219
-101
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ APP_DEBUG=true
55
APP_URL=stacks.localhost
66
APP_PORT=3333
77

8-
DB_CONNECTION=mysql
8+
DB_CONNECTION=sqlite
99
DB_HOST=127.0.0.1
1010
DB_PORT=3306
1111
DB_DATABASE=stacks
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,71 @@
11
// generates the pkgx file based on the user configuration
2+
// @ts-ignore
3+
import data from '../../../../../pkgx.yaml'
4+
import { config } from '@stacksjs/config'
5+
import { runCommand } from '@stacksjs/cli'
6+
7+
if (!data)
8+
throw new Error('pkgx.yaml file not found')
9+
10+
if (data.dependencies['aws.amazon.com/cdk'] === undefined) {
11+
log.info('aws.amazon.com/cdk dependency not found in pkgx.yaml.')
12+
// throw an error unless its installed locally
13+
const result = await runCommand('which cdk')
14+
if (result.isErr())
15+
throw new Error('aws.amazon.com/cdk dependency not found in pkgx.yaml. To confirm, run `which cdk`')
16+
}
17+
18+
if (data.dependencies['aws.amazon.com/cli'] === undefined) {
19+
log.info('aws.amazon.com/cli dependency not found in pkgx.yaml.')
20+
const result = await runCommand('which aws')
21+
if (result.isErr())
22+
throw new Error('aws.amazon.com/cli dependency not found in pkgx.yaml. To confirm, run `which aws`')
23+
}
24+
25+
if (data.dependencies['bun.sh'] === undefined) {
26+
log.info('bun.sh dependency not found in pkgx.yaml.')
27+
// throw an error unless its installed locally
28+
const result = await runCommand('which aws')
29+
if (result.isErr())
30+
throw new Error('bun.sh dependency not found in pkgx.yaml. To confirm, run `which bun`')
31+
}
32+
33+
if (data.dependencies['info-zip.org/zip'] === undefined) {
34+
log.info('info-zip.org/zip dependency not found in pkgx.yaml.')
35+
// throw an error unless its installed locally
36+
const result = await runCommand('which zip')
37+
if (result.isErr())
38+
throw new Error('info-zip.org/zip dependency not found in pkgx.yaml. To confirm, run `which zip`')
39+
}
40+
41+
if (data.dependencies['info-zip.org/unzip'] === undefined) {
42+
log.info('info-zip.org/unzip dependency not found in pkgx.yaml.')
43+
// throw an error unless its installed locally
44+
const result = await runCommand('which unzip')
45+
if (result.isErr())
46+
throw new Error('info-zip.org/unzip dependency not found in pkgx.yaml. To confirm, run `which unzip`')
47+
}
48+
49+
if (data.dependencies['mailpit.axllent.org'] === undefined) {
50+
log.info('mailpit.axllent.org dependency not found in pkgx.yaml.')
51+
// throw an error unless its installed locally
52+
const result = await runCommand('which mailpit')
53+
if (result.isErr())
54+
throw new Error('mailpit.axllent.org dependency not found in pkgx.yaml. To confirm, run `which mailpit`')
55+
}
56+
57+
if (data.dependencies['redis.io'] === undefined) {
58+
log.info('redis.io dependency not found in pkgx.yaml.')
59+
// throw an error unless its installed locally
60+
const result = await runCommand('which redis')
61+
if (result.isErr())
62+
throw new Error('redis.io dependency not found in pkgx.yaml. To confirm, run `which redis`')
63+
}
64+
65+
if (config.database.default === 'sqlite' && data.dependencies['sqlite.org'] === undefined) {
66+
log.info('sqlite.org dependency not found in pkgx.yaml.')
67+
// throw an error unless its installed locally
68+
const result = await runCommand('which sqlite')
69+
if (result.isErr())
70+
throw new Error('sqlite.org dependency not found in pkgx.yaml. To confirm, run `which sqlite`')
71+
}

.stacks/core/cache/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@
5757
},
5858
"optionalDependencies": {
5959
"@aws-sdk/client-dynamodb": "^3.449.0",
60-
"@types/memjs": "^1.3.3",
61-
"memcached": "^2.2.2",
62-
"memjs": "^1.3.1",
63-
"redis": "^4.6.10"
60+
"ioredis": "^5.3.2"
6461
},
6562
"devDependencies": {
6663
"@stacksjs/development": "workspace:*"
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
export * as redis from './redis'
22
export * as dynamodb from './dynamodb'
3-
export * as memcached from './memcached'
4-
export * as upstash from './upstash'

.stacks/core/cache/src/drivers/memcached.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import { cache } from '@stacksjs/config'
2-
import { type RedisClientType, createClient } from 'redis'
3-
4-
export const client: RedisClientType = createClient({
5-
socket: {
6-
host: cache.drivers?.redis?.host,
7-
port: cache.drivers?.redis?.port,
8-
},
9-
password: '',
10-
})
2+
import Redis, { Command } from 'ioredis'
113

12-
// await client.connect()
13-
// client.on('error', (error) => {
14-
// console.error(error)
15-
// })
4+
export const client = new Redis({
5+
host: cache.drivers?.redis?.host,
6+
port: cache.drivers?.redis?.port,
7+
username: cache.drivers?.redis?.username,
8+
password: cache.drivers?.redis?.password,
9+
})
1610

1711
export async function set(key: string, value: any): Promise<void> {
1812
await client.set(key, value)
@@ -33,9 +27,11 @@ export async function del(key: string): Promise<void> {
3327
}
3428

3529
export async function flushAll(): Promise<void> {
36-
await client.sendCommand(['FLUSHALL', 'ASYNC'])
30+
const command = new Command('FLUSHALL', ['ASYNC'], { replyEncoding: 'utf-8' }, () => {})
31+
await client.sendCommand(command);
3732
}
3833

3934
export async function flushDB(): Promise<void> {
40-
await client.sendCommand(['FLUSHDB', 'ASYNC'])
35+
const command = new Command('FLUSHDB', ['ASYNC'], { replyEncoding: 'utf-8' }, () => {})
36+
await client.sendCommand(command)
4137
}

.stacks/core/cache/src/drivers/upstash.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

.stacks/core/cli/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 './src'
22

3-
const result = await runCommand('bun --bun build ./src/index.ts --outdir dist --external vite --external @antfu/install-pkg --external @stacksjs/types --external @stacksjs/logging --external prompts --external @stacksjs/utils --external @stacksjs/validation --external @stacksjs/error-handling --external ora --external kolorist --external cac --target bun', {
3+
const result = await runCommand('bun --bun build ./src/index.ts --outdir dist --external vite --external @antfu/install-pkg --external @stacksjs/types --external @stacksjs/tunnel --external @stacksjs/logging --external prompts --external @stacksjs/utils --external @stacksjs/validation --external @stacksjs/error-handling --external ora --external kolorist --external cac --target bun', {
44
cwd: import.meta.dir,
55
})
66

.stacks/core/cloud/deploy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import process from 'node:process'
33
import { config } from '@stacksjs/config'
44
import { ExitCode } from '@stacksjs/types'
55
import { env } from '@stacksjs/env'
6-
import * as cdk from 'aws-cdk-lib'
6+
import { App } from 'aws-cdk-lib'
77
import { Cloud } from './src/cloud'
88
import { getOrCreateTimestamp } from './src/helpers'
99
import type { CloudOptions } from './src/types'
1010

11-
const app = new cdk.App()
11+
const app = new App()
1212
const appEnv = config.app.env === 'local' ? 'dev' : config.app.env
1313
const appKey = config.app.key
1414
const domain = config.app.url

.stacks/core/config/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 --external @stacksjs/types --external @stacksjs/env --external @stacksjs/path --external @stacksjs/validation --external @stacksjs/path --external @vinejs/compiler --external pluralize --external @stacksjs/strings --external dinero.js --external @dinero.js/currencies --external validator --external @vinejs/vine --external @stacksjs/validation --target node', {
3+
const result = await runCommand('bun build ./src/index.ts --outdir dist --format esm --external @stacksjs/types --external @stacksjs/tunnel --external @stacksjs/env --external @stacksjs/path --external @stacksjs/validation --external @stacksjs/path --external @vinejs/compiler --external pluralize --external @stacksjs/strings --external dinero.js --external @dinero.js/currencies --external validator --external @vinejs/vine --external @stacksjs/validation --target node', {
44
cwd: import.meta.dir,
55
})
66

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const handler = {
2121
get: (target: Env, key: EnvKey) => {
2222
const value = target[key] as any
2323

24-
// if value is a string but only contains numbers, return it as a number
25-
if (typeof value === 'string' && /^\d+$/.test(value))
24+
// if value is a string but only contains numbers, and the key is not AWS_ACCOUNT_ID, return it as a number
25+
if (typeof value === 'string' && /^\d+$/.test(value) && key !== 'AWS_ACCOUNT_ID')
2626
return Number(value)
2727

2828
// if value is a string but only contains boolean values, return it as a boolean

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,32 @@ export function config(options: ServerOptions) {
1111
host: 'localhost',
1212
port: 3333,
1313
},
14+
1415
api: {
1516
host: 'localhost',
1617
port: 3334,
1718
},
19+
1820
admin: {
1921
host: 'localhost',
2022
port: 3335,
2123
},
24+
2225
library: { // component library
2326
host: 'localhost',
2427
port: 3336,
2528
},
29+
2630
desktop: {
2731
host: 'localhost',
2832
port: 3337,
2933
},
34+
3035
docs: {
3136
host: 'localhost',
3237
port: 3338,
3338
},
39+
3440
example: {
3541
host: 'localhost',
3642
port: 3339,
@@ -46,7 +52,7 @@ export function config(options: ServerOptions) {
4652
}
4753

4854
return {
49-
host: options.host || 'stacks.test',
55+
host: options.host || 'stacks.localhost',
5056
port: options.port || 3333,
5157
open: options.open || false,
5258
}

.stacks/core/tunnel/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 --target bun', {
3+
const result = await runCommand('bun build ./src/index.ts --outdir dist --external localtunnel --format esm --target bun', {
44
cwd: import.meta.dir,
55
})
66

.stacks/core/types/src/cache.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ export interface CacheOptions {
6767
* @example 6379
6868
*/
6969
port: number
70+
71+
/**
72+
* **Redis Username**
73+
*
74+
* This value determines the username that will be used to connect to the Redis server.
75+
*
76+
* @default string ""
77+
* @example "admin"
78+
*/
79+
username: string
80+
81+
/**
82+
* **Redis Password**
83+
*
84+
* This value determines the password that will be used to connect to the Redis server.
85+
*
86+
* @default string ""
87+
* @example "password"
88+
*/
89+
password: string
7090
}
7191

7292
memcached?: object

.stacks/core/vite/src/plugin/stacks.ts

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type StacksPluginOptions = {
1212
email?: boolean
1313
docs?: boolean
1414
config?: string // the vite config used
15+
withLocalhost?: boolean
1516
}
1617

1718
// https://github.com/hannoeru/vite-plugin-pages
@@ -59,6 +60,7 @@ export function stacks(options?: StacksPluginOptions): Plugin {
5960
}
6061

6162
const stacksVersion = `alpha-${version}`
63+
const withLocalhost = options && options.withLocalhost
6264

6365
console.log(` ${c.blue(c.bold('STACKS'))} ${c.blue(stacksVersion)}`)
6466

@@ -77,23 +79,69 @@ export function stacks(options?: StacksPluginOptions): Plugin {
7779
}
7880

7981
if (options && options.config?.includes('components')) {
80-
console.log(` ${c.green('➜') } ${c.bold('Components')}: ${c.green(urls.library)}`)
81-
console.log(` ${c.green('➜') } ${c.bold('Local')}: ${c.green(await localUrl({ type: 'library', localhost: true }))}`)
82+
if (withLocalhost)
83+
console.log(` ${c.green('➜') } ${c.bold('Local')}: ${c.green(await localUrl({ type: 'library', localhost: true }))}`)
84+
85+
console.log(` ${c.green('➜') } ${c.bold('Library')}: ${c.green(urls.library)}`)
8286
console.log(` ${c.green('➜') } ${c.bold('Network')}: ${c.green(await localUrl({ type: 'library', network: true }))}`)
8387
}
8488

85-
if (options && options.config?.includes('email'))
89+
if (options && options.config?.includes('email')) {
90+
if (withLocalhost)
91+
console.log(` ${c.green('➜') } ${c.bold('Local')}: ${c.green(await localUrl({ type: 'email', localhost: true }))}`)
92+
8693
console.log(` ${c.green('➜') } ${c.bold('Email')}: ${c.green(urls.email)}`)
87-
if (options && options.config?.includes('docs'))
94+
console.log(` ${c.green('➜') } ${c.bold('Network')}: ${c.green(await localUrl({ type: 'email', network: true }))}`)
95+
}
96+
97+
if (options && options.config?.includes('docs')) {
98+
if (withLocalhost)
99+
console.log(` ${c.green('➜') } ${c.bold('Local')}: ${c.green(await localUrl({ type: 'docs', localhost: true }))}`)
100+
88101
console.log(` ${c.green('➜') } ${c.bold('Docs')}: ${c.green(urls.docs)}`)
89-
if (options && options.config?.includes('inspect'))
102+
console.log(` ${c.green('➜') } ${c.bold('Network')}: ${c.green(await localUrl({ type: 'docs', network: true }))}`)
103+
}
104+
105+
if (options && options.config?.includes('inspect')) {
106+
if (withLocalhost)
107+
console.log(` ${c.green('➜') } ${c.bold('Local')}: ${c.green(await localUrl({ type: 'inspect', localhost: true }))}`)
108+
90109
console.log(` ${c.green('➜') } ${c.bold('Inspect')}: ${c.green(urls.inspect)}`)
91-
if (options && options.config?.includes('admin'))
110+
console.log(` ${c.green('➜') } ${c.bold('Network')}: ${c.green(await localUrl({ type: 'inspect', network: true }))}`)
111+
}
112+
113+
114+
if (options && options.config?.includes('admin')) {
115+
if (withLocalhost)
116+
console.log(` ${c.green('➜') } ${c.bold('Local')}: ${c.green(await localUrl({ type: 'admin', localhost: true }))}`)
117+
92118
console.log(` ${c.green('➜') } ${c.bold('Admin')}: ${c.green(urls.admin)}`)
93-
if (options && options.config?.includes('backend'))
119+
console.log(` ${c.green('➜') } ${c.bold('Network')}: ${c.green(await localUrl({ type: 'admin', network: true }))}`)
120+
}
121+
122+
if (options && options.config?.includes('backend')) {
123+
if (withLocalhost)
124+
console.log(` ${c.green('➜') } ${c.bold('Local')}: ${c.green(await localUrl({ type: 'backend', localhost: true }))}`)
125+
94126
console.log(` ${c.green('➜') } ${c.bold('Backend')}: ${c.green(urls.backend)}`)
95-
if (options && options.config?.includes('desktop'))
127+
console.log(` ${c.green('➜') } ${c.bold('Network')}: ${c.green(await localUrl({ type: 'backend', network: true }))}`)
128+
}
129+
130+
if (options && options.config?.includes('backend')) {
131+
if (withLocalhost)
132+
console.log(` ${c.green('➜') } ${c.bold('Local')}: ${c.green(await localUrl({ type: 'backend', localhost: true }))}`)
133+
134+
console.log(` ${c.green('➜') } ${c.bold('Backend')}: ${c.green(urls.backend)}`)
135+
console.log(` ${c.green('➜') } ${c.bold('Network')}: ${c.green(await localUrl({ type: 'backend', network: true }))}`)
136+
}
137+
138+
if (options && options.config?.includes('desktop')) {
139+
if (withLocalhost)
140+
console.log(` ${c.green('➜') } ${c.bold('Local')}: ${c.green(await localUrl({ type: 'desktop', localhost: true }))}`)
141+
96142
console.log(` ${c.green('➜') } ${c.bold('Desktop')}: ${c.green(urls.desktop)}`)
143+
console.log(` ${c.green('➜') } ${c.bold('Network')}: ${c.green(await localUrl({ type: 'desktop', network: true }))}`)
144+
}
97145
}
98146
},
99147
}

0 commit comments

Comments
 (0)