(cmd, mapFn)
| 18 | const SINCE = args.positionals[0] || '12 months ago'; |
| 19 | |
| 20 | async function runGitCommand(cmd, mapFn) { |
| 21 | const childProcess = cp.spawn('/bin/sh', ['-c', cmd], { |
| 22 | cwd: new URL('..', import.meta.url), |
| 23 | encoding: 'utf8', |
| 24 | stdio: ['inherit', 'pipe', 'inherit'], |
| 25 | }); |
| 26 | const lines = readline.createInterface({ |
| 27 | input: childProcess.stdout, |
| 28 | }); |
| 29 | const errorHandler = new Promise( |
| 30 | (_, reject) => childProcess.on('error', reject), |
| 31 | ); |
| 32 | let returnValue = mapFn ? new Set() : ''; |
| 33 | await Promise.race([errorHandler, Promise.resolve()]); |
| 34 | // If no mapFn, return the value. If there is a mapFn, use it to make a Set to |
| 35 | // return. |
| 36 | for await (const line of lines) { |
| 37 | await Promise.race([errorHandler, Promise.resolve()]); |
| 38 | if (mapFn) { |
| 39 | const val = mapFn(line); |
| 40 | if (val) { |
| 41 | returnValue.add(val); |
| 42 | } |
| 43 | } else { |
| 44 | returnValue += line; |
| 45 | } |
| 46 | } |
| 47 | return Promise.race([errorHandler, Promise.resolve(returnValue)]); |
| 48 | } |
| 49 | |
| 50 | // Get all commit contributors during the time period. |
| 51 | const contributors = await runGitCommand( |
no test coverage detected
searching dependent graphs…