| 21 | } |
| 22 | |
| 23 | async generateWorkspaceFiles() { |
| 24 | this.workspace = new Workspace(yarnList()); |
| 25 | const filesToGenerate: [ |
| 26 | Path, |
| 27 | (prev: string) => string, |
| 28 | BuiltInParserName?, |
| 29 | ][] = [ |
| 30 | [this.workspace.join('tsconfig.json'), this.genProjectTsConfig, 'json'], |
| 31 | [ |
| 32 | this.workspace |
| 33 | .getPackage('@affine-tools/utils') |
| 34 | .join('src/workspace.gen.ts'), |
| 35 | this.genWorkspaceInfo, |
| 36 | 'typescript', |
| 37 | ], |
| 38 | [this.workspace.join('.oxlintrc.json'), this.genOxlintConfig, 'json'], |
| 39 | ...this.workspace.packages |
| 40 | .filter(p => p.isTsProject) |
| 41 | .map( |
| 42 | p => |
| 43 | [ |
| 44 | p.join('tsconfig.json'), |
| 45 | this.genPackageTsConfig.bind(this, p), |
| 46 | 'json', |
| 47 | ] as any |
| 48 | ), |
| 49 | ]; |
| 50 | |
| 51 | for (const [path, content, formatter] of filesToGenerate) { |
| 52 | this.logger.info(`Generating: ${path}`); |
| 53 | const previous = readFileSync(path.value, 'utf-8'); |
| 54 | let file = content(previous); |
| 55 | if (formatter) { |
| 56 | file = await this.format(file, formatter); |
| 57 | } |
| 58 | writeFileSync(path.value, file); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | format(content: string, parser: BuiltInParserName) { |
| 63 | const config = JSON.parse( |