(msg: { solution: string; schema: IPublicTypeProjectSchema; flattenResult?: boolean })
| 14 | self.postMessage({ type: 'ready' }); |
| 15 | |
| 16 | async function run(msg: { solution: string; schema: IPublicTypeProjectSchema; flattenResult?: boolean }) { |
| 17 | try { |
| 18 | print('begin run...'); |
| 19 | self.postMessage({ type: 'run:begin' }); |
| 20 | |
| 21 | const { solution } = msg; |
| 22 | if (!solution) { |
| 23 | throw new Error('solution is required'); |
| 24 | } |
| 25 | |
| 26 | const createAppBuilder = CodeGen.solutions[solution as 'icejs' | 'rax']; |
| 27 | if (typeof createAppBuilder !== 'function') { |
| 28 | throw new Error(`solution '${solution}' is invalid`); |
| 29 | } |
| 30 | |
| 31 | const appBuilder = createAppBuilder(); |
| 32 | |
| 33 | print('generating from schema: %o', msg.schema); |
| 34 | |
| 35 | const result = await appBuilder.generateProject(msg.schema); |
| 36 | |
| 37 | print('generated result: %o', result); |
| 38 | |
| 39 | const finalResult = msg.flattenResult |
| 40 | ? CodeGen.utils.resultHelper.flattenResult(result) |
| 41 | : result; |
| 42 | |
| 43 | if (msg.flattenResult) { |
| 44 | print('flatten result: %o', finalResult); |
| 45 | } |
| 46 | |
| 47 | self.postMessage({ |
| 48 | type: 'run:end', |
| 49 | result: finalResult, |
| 50 | }); |
| 51 | } catch (e) { |
| 52 | printErr(`${e}`); |
| 53 | self.postMessage({ |
| 54 | type: 'run:error', |
| 55 | errorMsg: `${(e as Error | null)?.message || e}`, |
| 56 | errorDetail: `${e}`, |
| 57 | }); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | function print(text: string, ...args: any[]) { |
| 62 | console.debug(`[code-generator/worker]: ${text}`, ...args); |
no test coverage detected