()
| 78 | } |
| 79 | |
| 80 | async function main(): Promise<void> { |
| 81 | const args = minimist<Args>(process.argv.slice(2)) |
| 82 | const dryRun = args['dry-run'] === true |
| 83 | const workspaceRoot = getWorkspaceRoot(args) |
| 84 | const header = |
| 85 | '// Generated, DO NOT EDIT MANUALLY. To update, run "bazel run //:generate_package_tsconfigs"\n' |
| 86 | |
| 87 | process.stderr.write('Querying package tsconfig genrules...\n') |
| 88 | |
| 89 | const bazel = spawn( |
| 90 | 'bazel', |
| 91 | ['query', TSCONFIG_QUERY, '--output=streamed_jsonproto'], |
| 92 | {cwd: workspaceRoot, stdio: ['ignore', 'pipe', 'inherit']} |
| 93 | ) |
| 94 | const rl = createInterface({input: bazel.stdout}) |
| 95 | |
| 96 | const writes: Promise<void>[] = [] |
| 97 | let total = 0 |
| 98 | |
| 99 | for await (const line of rl) { |
| 100 | const result = parseTsconfigLine(line) |
| 101 | if (!result) { |
| 102 | continue |
| 103 | } |
| 104 | |
| 105 | total++ |
| 106 | |
| 107 | if (dryRun) { |
| 108 | process.stdout.write(`Would write: ${result.path}\n`) |
| 109 | } else { |
| 110 | const fullPath = join(workspaceRoot, result.path) |
| 111 | const json = result.content.endsWith('\n') |
| 112 | ? result.content |
| 113 | : `${result.content}\n` |
| 114 | writes.push(outputFile(fullPath, header + json)) |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | const exitCode = await new Promise<number | null>((resolve, reject) => { |
| 119 | bazel.on('error', reject) |
| 120 | bazel.on('close', code => resolve(code)) |
| 121 | }) |
| 122 | |
| 123 | if (exitCode !== 0) { |
| 124 | process.stderr.write(`bazel query failed with exit code ${exitCode}\n`) |
| 125 | process.exit(exitCode ?? 1) |
| 126 | } |
| 127 | |
| 128 | if (total === 0) { |
| 129 | process.stderr.write('No package tsconfig genrules found\n') |
| 130 | process.exit(1) |
| 131 | } |
| 132 | |
| 133 | await Promise.all(writes) |
| 134 | |
| 135 | const action = dryRun ? 'Would write' : 'Wrote' |
| 136 | process.stderr.write(`${action} ${total} tsconfig files\n`) |
| 137 | } |
no test coverage detected