( userConfig?: LazyOrAsync<MaybeArray<UserConfig>>, logger = new Logger(), )
| 31 | * @param userConfig User provided {@link UserConfig} configuration(s). |
| 32 | */ |
| 33 | export async function createClient( |
| 34 | userConfig?: LazyOrAsync<MaybeArray<UserConfig>>, |
| 35 | logger = new Logger(), |
| 36 | ): Promise<ReadonlyArray<Context>> { |
| 37 | const resolvedConfig = typeof userConfig === 'function' ? await userConfig() : userConfig; |
| 38 | const userConfigs = resolvedConfig |
| 39 | ? resolvedConfig instanceof Array |
| 40 | ? resolvedConfig |
| 41 | : [resolvedConfig] |
| 42 | : []; |
| 43 | |
| 44 | let rawLogs = userConfigs.find((config) => getLogs(config.logs).level !== 'silent')?.logs; |
| 45 | if (typeof rawLogs === 'string') { |
| 46 | rawLogs = getLogs(rawLogs); |
| 47 | } |
| 48 | |
| 49 | let jobs: Configs['jobs'] = []; |
| 50 | |
| 51 | try { |
| 52 | checkNodeVersion(); |
| 53 | |
| 54 | const eventCreateClient = logger.timeEvent('createClient'); |
| 55 | |
| 56 | const eventConfig = logger.timeEvent('config'); |
| 57 | const resolved = await resolveJobs({ logger, userConfigs }); |
| 58 | const dependencies = resolved.dependencies; |
| 59 | jobs = resolved.jobs; |
| 60 | const printIntro = jobs.some((job) => job.config.logs.level !== 'silent'); |
| 61 | if (printIntro) printCliIntro(__dirname); |
| 62 | eventConfig.timeEnd(); |
| 63 | |
| 64 | const configErrors = jobs.flatMap((job) => |
| 65 | job.errors.map((error) => ({ error, jobIndex: job.index })), |
| 66 | ); |
| 67 | if (configErrors.length) { |
| 68 | throw new ConfigValidationError(configErrors); |
| 69 | } |
| 70 | |
| 71 | const outputs = await Promise.all( |
| 72 | jobs.map(async (job) => { |
| 73 | try { |
| 74 | return await pCreateClient({ |
| 75 | config: job.config, |
| 76 | dependencies, |
| 77 | jobIndex: job.index, |
| 78 | logger, |
| 79 | }); |
| 80 | } catch (error) { |
| 81 | if (error instanceof Error) { |
| 82 | throw new JobError('', { |
| 83 | error, |
| 84 | jobIndex: job.index, |
| 85 | }); |
| 86 | } |
| 87 | } |
| 88 | }), |
| 89 | ); |
| 90 | const contexts = outputs.filter((ctx): ctx is Context => ctx !== undefined); |
no test coverage detected