Skip to content

Commit c67fd68

Browse files
committed
chore: wip
chore: wip
1 parent 3b6e6fb commit c67fd68

File tree

6 files changed

+47
-18
lines changed

6 files changed

+47
-18
lines changed

storage/framework/core/actions/src/helpers/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function runAction(action: string, options?: ActionOptions): Promis
1717
if (!hasAction(action))
1818
return err(handleError(`The specified action "${action}" does not exist`))
1919

20-
const opts = buddyOptions()
20+
const opts = parseOptions()
2121
const path = p.relativeActionsPath(`${action}.ts`)
2222
const cmd = `bun --bun ${path} ${opts}`
2323
const optionsWithCwd = {
@@ -51,7 +51,6 @@ export async function runActions(actions: string[], options?: ActionOptions) {
5151
return err(`The specified action "${action}" does not exist`)
5252
}
5353

54-
// TODO: need to solve this error
5554
const opts = buddyOptions()
5655

5756
const o = {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export function release(buddy: CLI) {
2323
log.warn('Dry run enabled. No changes will be made.')
2424

2525
const startTime = await intro('buddy release')
26-
const result = await runAction(Action.Release, { ...options, stdin: 'inherit' })
26+
const result = await runAction(Action.Release, {
27+
stdin: 'inherit',
28+
...options,
29+
})
2730

2831
if (result.isErr()) {
2932
log.error('Failed to release', result.error)

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ interface ParsedArgv {
77
}
88
}
99

10-
function isLongOption(arg: string): boolean {
10+
function isLongOption(arg?: string): boolean {
11+
if (!arg)
12+
return false
13+
1114
return arg.startsWith('--')
1215
}
1316

@@ -32,33 +35,37 @@ function parseValue(value: string): string | boolean | number {
3235
function parseLongOption(arg: string, argv: string[], index: number, options: { [k: string]: string | boolean | number }): number {
3336
const [key, value] = arg.slice(2).split('=')
3437
if (value !== undefined) {
35-
options[key] = parseValue(value)
38+
options[key as string] = parseValue(value)
3639
}
37-
else if (index + 1 < argv.length && !argv[index + 1].startsWith('-')) {
38-
options[key] = argv[index + 1]
40+
else if (index + 1 < argv.length && !argv[index + 1]!.startsWith('-')) {
41+
options[key as string] = argv[index + 1] as string
3942
index++
4043
}
4144
else {
42-
options[key] = true
45+
options[key as string] = true
4346
}
4447
return index
4548
}
4649

4750
function parseShortOption(arg: string, argv: string[], index: number, options: { [k: string]: string | boolean | number }): number {
4851
const [key, value] = arg.slice(1).split('=')
4952

50-
if (value !== undefined) {
53+
// Check if key is undefined and handle it
54+
if (key === undefined)
55+
return index
56+
57+
if (value !== undefined && key !== undefined) {
5158
for (let j = 0; j < key.length; j++)
52-
options[key[j]] = parseValue(value)
59+
options[key[j] as string] = parseValue(value)
5360
}
5461
else {
5562
for (let j = 0; j < key.length; j++) {
56-
if (index + 1 < argv.length && j === key.length - 1 && !argv[index + 1].startsWith('-')) {
57-
options[key[j]] = parseValue(argv[index + 1])
63+
if (index + 1 < argv.length && j === key.length - 1 && !argv[index + 1]!.startsWith('-')) {
64+
options[key[j] as string] = parseValue(argv[index + 1]!)
5865
index++
5966
}
6067
else {
61-
options[key[j]] = true
68+
options[key[j] as string] = true
6269
}
6370
}
6471
}
@@ -75,6 +82,8 @@ export function parseArgv(argv?: string[]): ParsedArgv {
7582

7683
for (let i = 0; i < argv.length; i++) {
7784
const arg = argv[i]
85+
if (!arg)
86+
continue
7887
if (isLongOption(arg))
7988
i = parseLongOption(arg, argv, i, options)
8089
else if (isShortOption(arg))
@@ -102,11 +111,14 @@ export function parseOptions(options?: CliOptions): object {
102111
if (!options) {
103112
options = {}
104113
const args = process.argv.slice(2)
114+
105115
for (let i = 0; i < args.length; i++) {
106116
const arg = args[i]
117+
107118
if (arg?.startsWith('--')) {
108119
const key = arg.substring(2) // remove the --
109120
const camelCaseKey = key.replace(/-([a-z])/gi, g => (g[1] ? g[1].toUpperCase() : '')) // convert kebab-case to camelCase
121+
110122
if (i + 1 < args.length && (args[i + 1] === 'true' || args[i + 1] === 'false')) { // if the next arg is a boolean
111123
options[camelCaseKey] = args[i + 1] === 'true' // set the value to the boolean
112124
i++
@@ -116,6 +128,7 @@ export function parseOptions(options?: CliOptions): object {
116128
}
117129
}
118130
}
131+
119132
return options
120133
}
121134

@@ -134,6 +147,10 @@ export function parseOptions(options?: CliOptions): object {
134147
return options
135148
}
136149

150+
// interface BuddyOptions {
151+
// dryRun?: boolean
152+
// verbose?: boolean
153+
// }
137154
export function buddyOptions(options?: any): string {
138155
if (!options) {
139156
options = process.argv.slice(2)
@@ -143,10 +160,12 @@ export function buddyOptions(options?: any): string {
143160
if (options[0] && !options[0].startsWith('-'))
144161
options.shift()
145162
}
163+
146164
if (options?.verbose) {
147165
log.debug('process.argv', process.argv)
148166
log.debug('process.argv.slice(2)', process.argv.slice(2))
149167
log.debug('options inside buddyOptions', options)
150168
}
169+
151170
return options.join(' ')
152171
}

storage/framework/core/router/src/router.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { RedirectCode, Route, RouteGroupOptions, StatusCode } from '@stacksjs/types'
2-
import { projectPath } from '@stacksjs/path'
2+
import { path as p, projectPath } from '@stacksjs/path'
33

44
export interface RouterInterface {
5-
get: (url: Route['url'], callback: Route['callback']) => this
5+
get: (url: Route['url'], callback: Route['callback']) => Promise<this>
66
post: (url: Route['url'], callback: Route['callback']) => this
77
view: (url: Route['url'], callback: Route['callback']) => this
88
redirect: (url: Route['url'], callback: Route['callback'], status?: RedirectCode) => this
@@ -46,7 +46,14 @@ export class Router implements RouterInterface {
4646
})
4747
}
4848

49-
public get(path: Route['url'], callback: Route['callback']): this {
49+
public async get(path: Route['url'], callback: Route['callback']): Promise<this> {
50+
// check if callback is a string and if it is, then import that module path and use the default.handle function as the callback
51+
if (typeof callback === 'string') {
52+
// import the module and use the default.handle function as the callback
53+
const actionModule = await import(p.actionsPath(`${callback}.ts`))
54+
callback = actionModule.default.handle
55+
}
56+
5057
this.addRoute('GET', path, callback, 200)
5158
return this
5259
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BunFile } from 'bun'
22

3-
type ArrayBufferView = TypedArray | DataView
3+
type ArrayBufferView = NodeJS.TypedArray | DataView
44

55
export type { Subprocess, SyncSubprocess } from 'bun'
66
export type Readable =

storage/framework/core/types/src/router.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'before'
3434

3535
export type RouteCallback = (params?: Record<string, any>) => any | string | object
3636

37+
type ActionName = string
3738
export interface Route {
3839
name: string
3940
uri: string
4041
url: string // used synonymously with uri
4142
method: HttpMethod
4243
pattern: RegExp
43-
callback: RouteCallback
44+
callback: RouteCallback | ActionName
4445
paramNames: string[]
4546
middleware?: string | string[]
4647
statusCode?: StatusCode

0 commit comments

Comments
 (0)