| 165 | } |
| 166 | |
| 167 | export function createStatsNoter(props: PropertyGetter): IStatsNoter { |
| 168 | const config = props('compilationStatsNotifier', 'None()'); |
| 169 | const match = config.match(/^([^(]+)\(([^)]*)\)$/); |
| 170 | if (!match) throw new Error(`Unable to parse '${config}'`); |
| 171 | const params = match[2].split(','); |
| 172 | |
| 173 | const type = match[1]; |
| 174 | switch (type) { |
| 175 | case 'None': { |
| 176 | if (params.length !== 1) throw new Error(`Bad params: ${config}`); |
| 177 | return new NullStatsNoter(); |
| 178 | } |
| 179 | case 'S3': { |
| 180 | if (params.length === 0 || params.length > 4) |
| 181 | throw new Error(`Bad params: ${config} - expected S3(bucket, path?, region?, flushTime?)`); |
| 182 | let durationMs: number | undefined; |
| 183 | if (params[3]) { |
| 184 | const parsed = ms(params[3]); |
| 185 | if (!parsed) |
| 186 | throw new Error( |
| 187 | `Bad params: ${config} - expected S3(bucket, path?, region?, flushTime?), bad flush time`, |
| 188 | ); |
| 189 | durationMs = parsed; |
| 190 | } |
| 191 | return new StatsNoter(params[0], params[1], params[2], durationMs); |
| 192 | } |
| 193 | } |
| 194 | throw new Error(`Unknown stats type '${type}'`); |
| 195 | } |