11import { loadAllDefinitions } from "../src/helpers" ;
22import {
3+ ActionSdk ,
34 HerculesActionConfigurationDefinition ,
45 HerculesDataType , HerculesFlowType , HerculesRegisterFunctionParameter ,
56} from "@code0-tech/hercules" ;
67import { Project , SymbolFlags , Type } from "ts-morph" ;
8+ import { writeFileSync } from "fs"
79
810
911const state = {
@@ -14,8 +16,8 @@ const state = {
1416}
1517
1618
17- async function run ( ) {
18- await loadAllDefinitions ( {
19+ async function run ( ) : Promise < ActionSdk > {
20+ const sdk = {
1921 onError : ( ) => {
2022 } ,
2123 connect : ( ) => Promise . resolve ( [ ] ) ,
@@ -57,13 +59,19 @@ async function run() {
5759 return Promise . resolve ( )
5860 }
5961
60- } )
62+ } ;
63+ await loadAllDefinitions ( sdk )
64+
65+ return sdk
6166}
6267
63- run ( ) . then ( async ( ) => {
64- console . log ( `---
68+
69+ function generateDatatypes ( ) : string {
70+ let generatedDoc = ""
71+
72+ generatedDoc += `---
6573title: Datatypes
66- description: All data types registered by the GLS Action — field references and descriptions .
74+ description: All data types registered by the GLS Action.
6775---
6876import {TypeTable} from "fumadocs-ui/components/type-table";
6977
@@ -73,7 +81,8 @@ The GLS Action registers the following data types with the Hercules platform. Th
7381of the GLS functions and can be referenced in your flows.
7482
7583---
76- ` )
84+ `
85+
7786 state . dataTypes . forEach ( value => {
7887 value . type = `export type ${ value . identifier } = ${ value . type } `
7988 . replace ( / \| u n d e f i n e d / g, "" )
@@ -216,11 +225,152 @@ of the GLS functions and can be referenced in your flows.
216225
217226 const table = `<TypeTable type={{${ typeString } }}
218227/>`
219- console . log ( `# ${ key } ` )
220- console . log ( globalDocumentation || "\nNo documentation provided for this type." )
221- console . log ( )
222- console . log ( table )
228+ generatedDoc += `
229+ # ${ key } ${ globalDocumentation || "\nNo documentation provided for this type." }
230+
231+ ${ table }
232+ `
223233 }
224234 } )
235+ return generatedDoc
236+ }
237+
238+ interface Translation {
239+ code ?: string ;
240+ content ?: string ;
241+ }
242+
243+ interface FunctionDefinition {
244+ descriptions ?: Array < Translation > ;
245+ displayMessages ?: Array < Translation > ;
246+ identifier ?: string ;
247+ names ?: Array < Translation > ;
248+ parameterDefinitions ?: {
249+ nodes : {
250+ identifier : string ,
251+ descriptions : Array < Translation > ,
252+ names : Array < Translation >
253+ } [ ]
254+ } ;
255+ }
256+
257+ async function generateFunctions ( sdk : ActionSdk ) : Promise < string > {
258+ async function loadFunctions ( modules : Record < string , ( ) => Promise < unknown > > ) {
259+ for ( const path in modules ) {
260+
261+ const mod : any = await modules [ path ] ( ) ;
262+ if ( typeof mod . default === 'function' ) {
263+ try {
264+ await mod . default ( sdk ) ;
265+ } catch ( error ) {
266+ console . log ( `Error registering functions from ${ path } :` , error ) ;
267+ }
268+ }
269+ }
270+ }
271+
272+ let generatedDoc = `---
273+ title: Functions
274+ description: All functions registered by the GLS Action.
275+ ---
276+
277+ The GLS Action exposes ${ state . runtimeFunctions . length } functions grouped into three categories:
278+
279+ - **Builder functions** — Construct data objects (no API call)
280+ - **Shipment functions** — Create different types of GLS shipments (calls GLS API)
281+ - **API functions** — Query or modify shipments (calls GLS API)
282+
283+ ---
284+ `
285+ const functionGlobs = [
286+ import . meta. glob ( '../src/functions/utils/*.ts' ) ,
287+ import . meta. glob ( '../src/functions/services/*.ts' ) ,
288+ import . meta. glob ( '../src/functions/*.ts' )
289+ ]
290+ for ( let i = 0 ; i < functionGlobs . length ; i ++ ) {
291+ const modules = functionGlobs [ i ]
292+ state . runtimeFunctions = [ ]
293+ await loadFunctions ( modules )
294+
295+ switch ( i ) {
296+ case 0 : {
297+ generatedDoc += `
298+ ## Builder functions
299+ `
300+ break
301+ }
302+ case 1 : {
303+ generatedDoc += `
304+ ## Shipment functions
305+
306+ All shipment functions accept a common set of parameters in addition to their type-specific parameters. They call the GLS ShipIT API (\`POST /rs/shipments\`) and return a \`GLS_CREATE_PARCELS_RESPONSE\`.
307+
308+ **Common parameters for all shipment functions:**
309+
310+ | Parameter | Type | Required | Description |
311+ |-------------------|-------------------------------|----------|----------------------------------------------------|
312+ | \`shipment\` | GLS_SHIPMENT_WITHOUT_SERVICES | **Yes** | Shipment data (consignee, shipper, units, product) |
313+ | \`printingOptions\` | GLS_PRINTING_OPTIONS | **Yes** | Label format settings |
314+ | \`returnOptions\` | GLS_RETURN_OPTIONS | No | Whether to return print data and routing info |
315+ | \`customContent\` | GLS_CUSTOM_CONTENT | No | Custom logo and barcode settings |
316+
317+ ---
318+ `
319+ break
320+ }
321+ default : {
322+ generatedDoc += `
323+ ## API functions
324+ `
325+ }
326+ }
327+
328+ state . runtimeFunctions . forEach ( value => {
329+ const definition = value . definition ;
330+ const generateDefinition : FunctionDefinition = {
331+ descriptions : definition . description ,
332+ names : definition . name ,
333+ identifier : definition . runtimeName ,
334+ parameterDefinitions : {
335+ nodes : definition . parameters . map ( p => {
336+ return {
337+ names : p . name ,
338+ identifier : p . runtimeName ,
339+ descriptions : p . description
340+ }
341+ } )
342+ } ,
343+ displayMessages : definition . displayMessage
344+ }
345+
346+ generatedDoc += `
347+ ### \`${ definition . runtimeName } \`
348+
349+ ${ definition . documentation ?. at ( 0 ) . content || "" }
350+
351+ <FunctionCard definition={
352+ ${ JSON . stringify ( generateDefinition , null , 4 ) }
353+ } />
354+
355+ ---
356+ `
357+ } )
358+ }
359+
360+
361+ return generatedDoc
362+ }
225363
226- } )
364+ run ( ) . then ( async ( sdk ) => {
365+ // writeFileSync(
366+ // "../../docs/Actions/GLS/types.mdx",
367+ // generateDatatypes(),
368+ // "utf8"
369+ // )
370+
371+ writeFileSync (
372+ "../../docs/Actions/GLS/functions.mdx" ,
373+ await generateFunctions ( sdk ) ,
374+ "utf-8"
375+ )
376+ } )
0 commit comments