(projectPath: string, schema: string)
| 98 | } |
| 99 | |
| 100 | export async function generateEnums(projectPath: string, schema: string): Promise<void> { |
| 101 | const typesDir = path.join(projectPath, TYPE_ROOT_DIR); |
| 102 | const jsonObjects = getAllEnums(schema); |
| 103 | const enums = jsonObjects.map((r) => { |
| 104 | return { |
| 105 | name: r.name, |
| 106 | values: r.getValues().map((v) => v.name), |
| 107 | }; |
| 108 | }); |
| 109 | |
| 110 | if (enums.length !== 0) { |
| 111 | const enumsTemplate = { |
| 112 | props: { |
| 113 | enums, |
| 114 | }, |
| 115 | }; |
| 116 | try { |
| 117 | await renderTemplate(ENUM_TEMPLATE_PATH, path.join(typesDir, `enums.ts`), enumsTemplate); |
| 118 | exportTypes.enums = true; |
| 119 | } catch (e) { |
| 120 | throw new Error(`Codegen failed for enums.`, {cause: e}); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | export function processFields( |
| 126 | type: 'entity' | 'jsonField', |
no test coverage detected