|
| 1 | +import {loadAllDefinitions} from "../src/helpers"; |
| 2 | +import { |
| 3 | + HerculesActionConfigurationDefinition, |
| 4 | + HerculesDataType, HerculesFlowType, HerculesRegisterFunctionParameter, |
| 5 | +} from "@code0-tech/hercules"; |
| 6 | + |
| 7 | + |
| 8 | +const state = { |
| 9 | + dataTypes: [] as HerculesDataType[], |
| 10 | + actionConfigurationDefinitions: [] as HerculesActionConfigurationDefinition[], |
| 11 | + runtimeFunctions: [] as HerculesRegisterFunctionParameter[], |
| 12 | + flowTypes: [] as HerculesFlowType[] |
| 13 | +} |
| 14 | + |
| 15 | + |
| 16 | +async function run() { |
| 17 | + await loadAllDefinitions({ |
| 18 | + onError: handler => { |
| 19 | + }, |
| 20 | + connect: options => Promise.resolve([]), |
| 21 | + dispatchEvent: (event, payload) => Promise.resolve(), |
| 22 | + getProjectActionConfigurations: () => [], |
| 23 | + config: { |
| 24 | + authToken: "", |
| 25 | + aquilaUrl: "", |
| 26 | + version: "", |
| 27 | + actionId: "" |
| 28 | + }, |
| 29 | + fullyConnected: () => false, |
| 30 | + registerDataTypes: (...dataTypes) => { |
| 31 | + state.dataTypes = [ |
| 32 | + ...dataTypes, |
| 33 | + ...state.dataTypes |
| 34 | + ] |
| 35 | + return Promise.resolve() |
| 36 | + }, |
| 37 | + registerConfigDefinitions: (...actionConfigurations) => { |
| 38 | + state.actionConfigurationDefinitions = [ |
| 39 | + ...actionConfigurations, |
| 40 | + ...state.actionConfigurationDefinitions |
| 41 | + ] |
| 42 | + return Promise.resolve() |
| 43 | + }, |
| 44 | + registerFunctionDefinitions: (...functionDefinitions) => { |
| 45 | + state.runtimeFunctions = [ |
| 46 | + ...functionDefinitions, |
| 47 | + ...state.runtimeFunctions |
| 48 | + ] |
| 49 | + return Promise.resolve() |
| 50 | + }, |
| 51 | + registerFlowTypes: (...flowTypes) => { |
| 52 | + return Promise.resolve() |
| 53 | + } |
| 54 | + |
| 55 | + }) |
| 56 | +} |
| 57 | + |
| 58 | +run().then(async () => { |
| 59 | + let typeContent = `--- |
| 60 | +title: Datatypes |
| 61 | +description: All data types registered by the GLS Action — field references and descriptions. |
| 62 | +--- |
| 63 | +
|
| 64 | +# GLS Action Types |
| 65 | +
|
| 66 | +The GLS Action registers the following data types with the Hercules platform. These types are used as inputs and outputs |
| 67 | +of the GLS functions and can be referenced in your flows. |
| 68 | +
|
| 69 | +--- |
| 70 | + ` |
| 71 | + |
| 72 | + state.dataTypes.forEach(value => { |
| 73 | + value.type = `export type ${value.identifier} = ${value.type}` |
| 74 | + .replace(/ \| undefined/g, "") |
| 75 | + .replace(/\/\*\*/g, "/**\n") |
| 76 | + .replace(/\*\//g, "\n**/") |
| 77 | + .replace( |
| 78 | + /(\w+)(\?)?:\s*(GLS_\w+);/g, |
| 79 | + (match, name, optionalMark, gls) => { |
| 80 | + if (optionalMark) { |
| 81 | + return `/** |
| 82 | + Optional. |
| 83 | + @fumadocsHref #type-table-temp.ts-${gls} |
| 84 | +**/ |
| 85 | +${name}: ${gls}`; |
| 86 | + } |
| 87 | + |
| 88 | + return `/** |
| 89 | + @fumadocsHref #type-table-temp.ts-${gls} |
| 90 | +**/ |
| 91 | +${name}: ${gls}`; |
| 92 | + } |
| 93 | + ); |
| 94 | + |
| 95 | + let array = false |
| 96 | + if (value.type.endsWith("[];")) { |
| 97 | + value.type = value.type.slice(0, -3) + ";" |
| 98 | + array = true |
| 99 | + } |
| 100 | + |
| 101 | + typeContent += ` |
| 102 | +# ${value.identifier}${array ? " (array)" : ""} |
| 103 | + |
| 104 | +<AutoTypeTable type={\` |
| 105 | + |
| 106 | +${value.type} |
| 107 | + |
| 108 | +\`} name="${value.identifier}"/> |
| 109 | +
|
| 110 | +` |
| 111 | + }) |
| 112 | + typeContent = typeContent.replace(" | undefined", "") |
| 113 | + |
| 114 | + console.log(typeContent) |
| 115 | +}) |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | + |
0 commit comments