* Splits command execution using a glob string on parallelized CircleCI builds. * * If no parallelization is detected, simply returns the command as-is. * If parallelization is detected, uses the glob to add an argument to the * command by passing it through an optional callback function. * *
(command, glob, callback = (s) => s)
| 28 | * @return {string} the CLI command that should be executed. |
| 29 | */ |
| 30 | function maybeParallelizeCommand(command, glob, callback = (s) => s) { |
| 31 | if (!circleciIsParallelized()) { |
| 32 | return command; |
| 33 | } |
| 34 | |
| 35 | const tempFileName = tempy.file(); |
| 36 | timedExecOrDie( |
| 37 | `circleci tests glob ${glob} | circleci tests run --command=">${tempFileName} xargs echo -n"` |
| 38 | ); |
| 39 | const globAndRunResults = fs.readFileSync(tempFileName, {encoding: 'utf-8'}); |
| 40 | |
| 41 | return `${command} ${callback(globAndRunResults)}`; |
| 42 | } |
| 43 | |
| 44 | module.exports = {maybeParallelizeCommand}; |
no test coverage detected