@@ -2,8 +2,6 @@ import {ZodError, ZodObject} from "zod";
22import { createAuxiliaryTypeStore , printNode , zodToTs } from "zod-to-ts" ;
33import ts from "typescript" ;
44import axios from "axios" ;
5- import * as path from "node:path" ;
6- import { readdir , stat } from "fs/promises" ;
75import {
86 HerculesRuntimeFunctionDefinition ,
97 HerculesFunctionContext ,
@@ -37,7 +35,6 @@ import {
3735 ShipmentRequestData ,
3836 ShipmentRequestDataSchema
3937} from "./types/requests/shipmentRequest" ;
40- import { fileURLToPath } from 'url' ;
4138
4239
4340export const DEFAULT_SIGNATURE_FOR_SERVICES = "shipment: GLS_SHIPMENT, printingOptions: GLS_PRINTING_OPTIONS, returnOptions?: GLS_RETURN_OPTIONS, customContent?: GLS_CUSTOM_CONTENT"
@@ -306,32 +303,17 @@ export async function postShipmentHelper(context: HerculesFunctionContext, servi
306303 }
307304}
308305
309- const __filename = fileURLToPath ( import . meta. url ) ;
310- const __dirname = path . dirname ( __filename ) ;
311-
312306export async function loadAllDefinitions ( sdk : ActionSdk ) {
313- const baseDir = path . resolve ( __dirname , "definitions" ) ;
314- await loadFromDirectory ( baseDir , sdk ) ;
315- }
316-
317- async function loadFromDirectory ( dir : string , sdk : ActionSdk ) {
318- const entries = await readdir ( dir ) ;
319-
320- for ( const entry of entries ) {
321- const fullPath = path . join ( dir , entry ) ;
322- const stats = await stat ( fullPath ) ;
307+ const modules = import . meta. glob ( './definitions/**/*.ts' ) ;
323308
324- if ( stats . isDirectory ( ) ) {
325- await loadFromDirectory ( fullPath , sdk ) ;
326- } else if ( entry . endsWith ( ".ts" ) && ! entry . endsWith ( ".test.ts" ) ) {
327- const mod = await import ( fullPath ) ;
309+ for ( const path in modules ) {
310+ const mod : any = await modules [ path ] ( ) ;
328311
329- if ( typeof mod . register === "function" ) {
330- try {
331- await mod . register ( sdk ) ;
332- } catch ( error ) {
333- console . log ( `Error registering functions from file ${ entry } :` , error ) ;
334- }
312+ if ( typeof mod . register === 'function' ) {
313+ try {
314+ await mod . register ( sdk ) ;
315+ } catch ( error ) {
316+ console . log ( `Error registering functions from ${ path } :` , error ) ;
335317 }
336318 }
337319 }
0 commit comments