|
1
|
import outdent from "outdent" |
|
2
|
import fs from "fs/promises" |
|
3
|
import path from "path" |
|
4
|
import { generateModule } from "../utils" |
|
5
|
|
|
6
|
export async function generateVirtualCellRendererModule( |
|
7
|
sources: Set<string>, |
|
8
|
pluginMode = false |
|
9
|
) { |
|
10
|
const imports: string[] = [] |
|
11
|
|
|
12
|
// Check which sources have the cell-renderers.tsx file |
|
13
|
for (const source of sources) { |
|
14
|
const cellRenderersPath = path.join(source, "cell-renderers.tsx") |
|
15
|
try { |
|
16
|
await fs.access(cellRenderersPath) |
|
17
|
// File exists, add import for side effects |
|
18
|
imports.push(`import "${cellRenderersPath}"`) |
|
19
|
} catch { |
|
20
|
// File doesn't exist, skip |
|
21
|
} |
|
22
|
} |
|
23
|
|
|
24
|
const code = outdent` |
|
25
|
${imports.join("\n")} |
|
26
|
|
|
27
|
${ |
|
28
|
pluginMode |
|
29
|
? `const cellRendererModule = {}` |
|
30
|
: `export default {}` |
|
31
|
} |
|
32
|
` |
|
33
|
|
|
34
|
return generateModule(code) |
|
35
|
} |