(
solution: string,
{ quiet }: { quiet?: boolean },
)
| 87 | } |
| 88 | |
| 89 | async function getProjectBuilderFactory( |
| 90 | solution: string, |
| 91 | { quiet }: { quiet?: boolean }, |
| 92 | ): Promise<(options: {[prop: string]: any}) => IProjectBuilder> { |
| 93 | if (solution in CodeGenerator.solutions) { |
| 94 | return CodeGenerator.solutions[solution as 'icejs' | 'rax']; |
| 95 | } |
| 96 | |
| 97 | const solutionPackageName = isLocalSolution(solution) |
| 98 | ? solution |
| 99 | : `${solution.startsWith('@') ? solution : `@alilc/lowcode-solution-${solution}`}`; |
| 100 | |
| 101 | if (!isLocalSolution(solution)) { |
| 102 | if (!quiet) { |
| 103 | console.log(`"${solution}" is not internal, installing it as ${solutionPackageName}...`); |
| 104 | } |
| 105 | |
| 106 | spawnSync('npm', ['i', solutionPackageName], { |
| 107 | stdio: quiet ? 'ignore' : 'inherit', |
| 108 | }); |
| 109 | } |
| 110 | |
| 111 | // eslint-disable-next-line @typescript-eslint/no-require-imports |
| 112 | const solutionExports = require(!isLocalSolution(solution) |
| 113 | ? solutionPackageName |
| 114 | : `${path.isAbsolute(solution) ? solution : path.join(process.cwd(), solution)}`); |
| 115 | |
| 116 | const projectBuilderFactory = |
| 117 | solutionExports.createProjectBuilder || |
| 118 | solutionExports.createAppBuilder || |
| 119 | solutionExports.default; |
| 120 | |
| 121 | if (typeof projectBuilderFactory !== 'function') { |
| 122 | throw new Error( |
| 123 | `"${solutionPackageName}" should export project builder factory via named export 'createProjectBuilder' or via default export`, |
| 124 | ); |
| 125 | } |
| 126 | |
| 127 | return projectBuilderFactory; |
| 128 | } |
| 129 | |
| 130 | function isLocalSolution(solution: string) { |
| 131 | return solution.startsWith('.') || solution.startsWith('/') || solution.startsWith('~'); |
no test coverage detected
searching dependent graphs…