(ceProps: PropertyGetter)
| 57 | } |
| 58 | |
| 59 | public async initialize(ceProps: PropertyGetter): Promise<void> { |
| 60 | const formatters = _.compact(ceProps('formatters', '').split(':')); |
| 61 | for (const formatter of formatters) { |
| 62 | logger.info(`Performing discovery of formatter named ${formatter}`); |
| 63 | const executable = ceProps<string>(`formatter.${formatter}.exe`); |
| 64 | const type = ceProps<string>(`formatter.${formatter}.type`); |
| 65 | if (!executable) { |
| 66 | logger.warn(`Formatter ${formatter} does not have a valid executable. Skipping...`); |
| 67 | continue; |
| 68 | } |
| 69 | if (!type) { |
| 70 | logger.warn(`Formatter ${formatter} does not have a valid type. Skipping...`); |
| 71 | continue; |
| 72 | } |
| 73 | const versionArgument = ceProps<string>(`formatter.${formatter}.version`, '--version'); |
| 74 | const versionRegExp = ceProps<string>(`formatter.${formatter}.versionRe`, '.*'); |
| 75 | const hasExplicitVersion = ceProps(`formatter.${formatter}.explicitVersion`, '') !== ''; |
| 76 | try { |
| 77 | const result = await exec.execute(executable, [versionArgument], {}); |
| 78 | const match = result.stdout.match(versionRegExp); |
| 79 | const formatterClass = getFormatterTypeByKey(type); |
| 80 | const styleList = ceProps<string>(`formatter.${formatter}.styles`, ''); |
| 81 | const styles = styleList === '' ? [] : styleList.split(':'); |
| 82 | // If there is an explicit version, grab it. Otherwise, try to filter the output |
| 83 | const version = hasExplicitVersion |
| 84 | ? ceProps<string>(`formatter.${formatter}.explicitVersion`) |
| 85 | : match |
| 86 | ? match[0] |
| 87 | : result.stdout; |
| 88 | const instance = new formatterClass({ |
| 89 | name: ceProps(`formatter.${formatter}.name`, executable), |
| 90 | exe: executable, |
| 91 | version, |
| 92 | styles, |
| 93 | type, |
| 94 | }); |
| 95 | this.registry.set(formatter, instance); |
| 96 | } catch (err: unknown) { |
| 97 | logger.warn(`Error while fetching tool info for ${executable}:`, {err}); |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | } |
no test coverage detected