Skip to content

Commit f7c4787

Browse files
committed
Update documentation generation process and enhance type definitions
1 parent 531b632 commit f7c4787

33 files changed

Lines changed: 3028 additions & 28 deletions

.github/workflows/test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ jobs:
1717
- run: npm run build
1818
- run: npm run lint
1919
- run: npm run test
20+
- name: Validate generated documentation
21+
run: |
22+
npm run generate:docs
23+
if ! git diff --quiet; then
24+
git --no-pager diff
25+
exit 1
26+
fi

actions/gls-action/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"lint": "eslint .",
1111
"test": "vitest run",
1212
"start": "node dist/main.js",
13-
"docs:generate": "npm run build && node dist/generateTypes.js > ../../docs/Actions/GLS/types.mdx"
13+
"generate:docs": "npm run build && node dist/generateDocs.js"
1414
},
1515
"dependencies": {
1616
"ts-morph": "^27.0.2"

actions/gls-action/scripts/generateTypes.ts renamed to actions/gls-action/scripts/generateDocs.ts

Lines changed: 162 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {loadAllDefinitions} from "../src/helpers";
22
import {
3+
ActionSdk,
34
HerculesActionConfigurationDefinition,
45
HerculesDataType, HerculesFlowType, HerculesRegisterFunctionParameter,
56
} from "@code0-tech/hercules";
67
import {Project, SymbolFlags, Type} from "ts-morph";
8+
import {writeFileSync} from "fs"
79

810

911
const 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 += `---
6573
title: 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
---
6876
import {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
7381
of 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(/ \| undefined/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+
})

actions/gls-action/src/functions/cancelShipment.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ export default (sdk: ActionSdk) => {
77
{
88
definition: {
99
runtimeName: "cancelShipment",
10+
displayMessage: [
11+
{
12+
code: "en-US",
13+
content: "Cancel shipment"
14+
}
15+
],
1016
name: [
1117
{
1218
code: "en-US",

actions/gls-action/src/functions/getAllowedServices.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export default (sdk: ActionSdk) => {
1212
{
1313
definition: {
1414
runtimeName: "getAllowedServices",
15+
displayMessage: [
16+
{
17+
code: "en-US",
18+
content: "Get allowed services"
19+
}
20+
],
1521
name: [
1622
{
1723
code: "en-US",

actions/gls-action/src/functions/getEndOfDayReport.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export default (sdk: ActionSdk) => {
88
{
99
definition: {
1010
runtimeName: "getEndOfDayReport",
11+
displayMessage: [
12+
{
13+
code: "en-US",
14+
content: "Get end of day report"
15+
}
16+
],
1117
name: [
1218
{
1319
code: "en-US",

actions/gls-action/src/functions/reprintParcel.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export default (sdk: ActionSdk) => {
1212
{
1313
definition: {
1414
runtimeName: "reprintParcel",
15+
displayMessage: [
16+
{
17+
code: "en-US",
18+
content: "Reprint parcel"
19+
}
20+
],
1521
name: [
1622
{
1723
code: "en-US",

actions/gls-action/src/functions/services/createAddresseeOnlyShipment.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ export default (sdk: ActionSdk) => {
1515
{
1616
definition: {
1717
runtimeName: "createAddresseeOnlyShipment",
18+
displayMessage: [
19+
{
20+
code: "en-US",
21+
content: "Create addressee only shipment"
22+
}
23+
],
1824
name: [
1925
{
2026
code: "en-US",
@@ -44,4 +50,5 @@ export default (sdk: ActionSdk) => {
4450
}
4551
},
4652
)
47-
}
53+
}
54+

actions/gls-action/src/functions/services/createDeliveryAtWorkShipment.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ export default (sdk: ActionSdk) => {
1515
{
1616
definition: {
1717
runtimeName: "createDeliveryAtWorkShipment",
18+
displayMessage: [
19+
{
20+
code: "en-US",
21+
content: "Create delivery at work shipment"
22+
}
23+
],
1824
name: [
1925
{
2026
code: "en-US",

actions/gls-action/src/functions/services/createDeliveryNextWorkingDayShipment.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ export default (sdk: ActionSdk) => {
1515
{
1616
definition: {
1717
runtimeName: "createDeliveryNextWorkingDayShipment",
18+
displayMessage: [
19+
{
20+
code: "en-US",
21+
content: "Create delivery next working day shipment"
22+
}
23+
],
1824
name: [
1925
{
2026
code: "en-US",

0 commit comments

Comments
 (0)