MCPcopy Index your code
hub / github.com/adonisjs/core / generateNamespaceTree

Function generateNamespaceTree

src/utils.ts:111–127  ·  view source on GitHub ↗

* 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[])

Source from the content-addressed store, hash-verified

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

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected