@@ -20,17 +20,27 @@ type Action = ActionPath | ActionName | string
20
20
export async function runAction ( action : Action , options ?: ActionOptions ) {
21
21
// check if action is a file anywhere in ./app/Actions/**/*.ts
22
22
// if it is, return and await the action
23
- const glob = new Bun . Glob ( '**/*.ts ' )
23
+ const glob = new Bun . Glob ( '**/*.{ts,js} ' )
24
24
const scanOptions = { cwd : p . userActionsPath ( ) , onlyFiles : true }
25
25
26
26
for await ( const file of glob . scan ( scanOptions ) ) {
27
- log . debug ( 'file' , file )
28
27
if ( file === `${ action } .ts` || file . endsWith ( `${ action } .ts` ) )
29
28
return ( ( await import ( /* @vite -ignore */ p . userActionsPath ( file ) ) ) . default as ActionType ) . handle ( )
30
29
30
+ if ( file === `${ action } .js` || file . endsWith ( `${ action } .js` ) )
31
+ return ( ( await import ( /* @vite -ignore */ p . userActionsPath ( file ) ) ) . default as ActionType ) . handle ( )
32
+
31
33
// if a custom model name is used, we need to check for it
32
- const a = await import ( /* @vite -ignore */ p . userActionsPath ( file ) )
33
- if ( a . name === action ) return await a . handle ( )
34
+ try {
35
+ const a = await import ( /* @vite -ignore */ p . userActionsPath ( file ) )
36
+ if ( a . name === action ) {
37
+ console . log ( 'a.name matches' , a . name )
38
+ return await a . handle ( )
39
+ }
40
+ } catch ( error ) {
41
+ console . log ( 'error' , error )
42
+ process . exit ( )
43
+ }
34
44
}
35
45
36
46
// or else, just run the action normally by assuming the action is core Action, stored in p.actionsPath
0 commit comments