(
manifest: string,
patterns: {[key: string]: RegExp | undefined}
)
| 188 | } |
| 189 | |
| 190 | export function extractFromTs( |
| 191 | manifest: string, |
| 192 | patterns: {[key: string]: RegExp | undefined} |
| 193 | ): {[key: string]: string | string[] | null} { |
| 194 | const result: {[key: string]: string | string[] | null} = {}; |
| 195 | // TODO should extract then validate value type ? |
| 196 | // check what the following char is after key |
| 197 | const arrKeys = ['endpoint', 'topics']; |
| 198 | const nestArr = ['dataSources', 'handlers']; |
| 199 | for (const key in patterns) { |
| 200 | if (!nestArr.includes(key)) { |
| 201 | const regExp = patterns[key]; |
| 202 | assert(regExp, `Pattern for ${key} is not defined`); |
| 203 | const match = manifest.match(regExp); |
| 204 | |
| 205 | if (arrKeys.includes(key) && match) { |
| 206 | const inputStr = match[1].replace(/`/g, '"'); |
| 207 | const jsonOutput = JSON5.parse(inputStr); |
| 208 | result[key] = Array.isArray(jsonOutput) ? jsonOutput : [jsonOutput]; |
| 209 | } else { |
| 210 | result[key] = match ? match[1] : null; |
| 211 | } |
| 212 | } else { |
| 213 | result[key] = extractArrayValueFromTsManifest(manifest, key); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | return result; |
| 218 | } |
| 219 | |
| 220 | export function splitArrayString(arrayStr: string): string[] { |
| 221 | // Remove the starting and ending square brackets |
no test coverage detected