File tree Expand file tree Collapse file tree 10 files changed +62
-2
lines changed Expand file tree Collapse file tree 10 files changed +62
-2
lines changed Original file line number Diff line number Diff line change
1
+ import process from 'node:process'
2
+ import { listRoutes } from '@stacksjs/router'
3
+ import { log } from '@stacksjs/logging'
4
+
5
+ // first, reset the database, if it exists
6
+ const result = await listRoutes ( )
7
+
8
+ if ( result ?. isErr ( ) ) {
9
+ console . error ( result . error )
10
+ log . error ( 'Route lists failed' , result . error )
11
+ process . exit ( 1 )
12
+ }
13
+
14
+ process . exit ( 0 )
Original file line number Diff line number Diff line change @@ -64,6 +64,7 @@ async function main() {
64
64
cmd . make ( buddy )
65
65
cmd . migrate ( buddy )
66
66
cmd . release ( buddy )
67
+ cmd . route ( buddy )
67
68
cmd . seed ( buddy )
68
69
cmd . setup ( buddy )
69
70
cmd . test ( buddy )
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ export * from './ports'
22
22
export * from './prepublish'
23
23
export * from './projects'
24
24
export * from './release'
25
+ export * from './route'
25
26
export * from './seed'
26
27
export * from './setup'
27
28
export * from './test'
Original file line number Diff line number Diff line change
1
+ import process from 'node:process'
2
+ import { runAction } from '@stacksjs/actions'
3
+ import { intro , outro } from '@stacksjs/cli'
4
+ import { Action } from '@stacksjs/enums'
5
+ import { ExitCode } from '@stacksjs/types'
6
+ import type { CLI , MigrateOptions } from '@stacksjs/types'
7
+
8
+ export function route ( buddy : CLI ) {
9
+ const descriptions = {
10
+ route : 'Lists your routes' ,
11
+ }
12
+
13
+ buddy
14
+ . command ( 'route:list' , descriptions . route )
15
+ . action ( async ( options : MigrateOptions ) => {
16
+ const perf = await intro ( 'buddy route:list' )
17
+ const result = await runAction ( Action . RouteList , options )
18
+
19
+ if ( result . isErr ( ) ) {
20
+ await outro (
21
+ 'While running the migrate command, there was an issue' ,
22
+ { startTime : perf , useSeconds : true } ,
23
+ result . error ,
24
+ )
25
+ process . exit ( )
26
+ }
27
+
28
+
29
+ await outro ( `Successfully listed routes` )
30
+
31
+ process . exit ( ExitCode . Success )
32
+ } )
33
+ }
Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ export enum Action {
85
85
LintFix = 'lint/fix' ,
86
86
Prepublish = 'prepublish' ,
87
87
Release = 'release' , // ✅
88
+ RouteList = 'route/list' , // ✅
88
89
ShowFeatureTestReport = 'show-feature-test-report' ,
89
90
Test = 'test' ,
90
91
TestUi = 'test-ui' ,
Original file line number Diff line number Diff line change @@ -2,3 +2,4 @@ export * from './middleware'
2
2
export * from './request'
3
3
export * from './server'
4
4
export * from './router'
5
+ export * from './utils'
Original file line number Diff line number Diff line change @@ -216,6 +216,7 @@ export class Router implements RouterInterface {
216
216
return this . routes
217
217
}
218
218
219
+
219
220
private setGroupPrefix ( prefix : string , options : RouteGroupOptions = { } ) {
220
221
if ( prefix !== '' ) {
221
222
prefix = `/${ this . groupPrefix } /${ prefix } ` . replace ( / \/ \/ / g, '/' ) // remove double slashes in case there are any
@@ -292,8 +293,6 @@ export class Router implements RouterInterface {
292
293
293
294
path = `${ this . apiPrefix } ${ this . groupPrefix } /${ path } `
294
295
295
- console . log ( path )
296
-
297
296
// if path ends in "/", then remove it
298
297
// e.g. triggered when route is "/"
299
298
return path . endsWith ( '/' ) ? path . slice ( 0 , - 1 ) : path
Original file line number Diff line number Diff line change
1
+ import { ok } from '@stacksjs/error-handling'
2
+ import { route } from './router'
3
+
4
+ export async function listRoutes ( ) {
5
+ const routeLists = await route . getRoutes ( )
6
+
7
+ console . table ( routeLists )
8
+
9
+ return ok ( '' )
10
+ }
You can’t perform that action at this time.
0 commit comments