* Recursively generates namespace tree structure for transformers. * Creates nested namespaces for directory structures and type exports * for individual transformer files. * * @param input - The current level of the file tree to process * @param parents - Array of parent namespace na
(input: RecursiveFileTree, parents: string[])
| 109 | * @param parents - Array of parent namespace names for import naming |
| 110 | */ |
| 111 | function generateNamespaceTree(input: RecursiveFileTree, parents: string[]) { |
| 112 | Object.keys(input).forEach((key) => { |
| 113 | const value = input[key] |
| 114 | if (typeof value === 'string') { |
| 115 | const importName = `${parents.join('')}${key}Transformer` |
| 116 | importsBuffer.write(`import type ${importName} from '${value}'`) |
| 117 | buffer.write(`export type ${key} = InferData<${importName}>`) |
| 118 | buffer.write(`export namespace ${key} {`).indent() |
| 119 | buffer.write(`export type Variants = InferVariants<${importName}>`) |
| 120 | buffer.dedent().write('}') |
| 121 | } else { |
| 122 | buffer.write(`export namespace ${key} {`).indent() |
| 123 | generateNamespaceTree(value, [...parents, key]) |
| 124 | buffer.dedent().write(`}`) |
| 125 | } |
| 126 | }) |
| 127 | } |
| 128 | |
| 129 | generateNamespaceTree(transformersList, []) |
| 130 |
no outgoing calls
no test coverage detected