( fileExtension: string, unparsedConfig: string )
| 157 | } |
| 158 | |
| 159 | function parseConfigFile( |
| 160 | fileExtension: string, |
| 161 | unparsedConfig: string |
| 162 | ): LabelInfo[] { |
| 163 | let parsed: LabelInfo[] |
| 164 | |
| 165 | if (['.yaml', '.yml'].includes(fileExtension)) { |
| 166 | // Parse YAML file |
| 167 | log.info('Parsing YAML file...') |
| 168 | parsed = yaml.load(unparsedConfig) as LabelInfo[] |
| 169 | try { |
| 170 | throwConfigError(parsed) |
| 171 | } catch (e) { |
| 172 | log.error(JSON.stringify(parsed, null, 2), false) |
| 173 | throw 'Parsed YAML file is invalid:\n' + e |
| 174 | } |
| 175 | } else if (fileExtension == '.json') { |
| 176 | // Try to parse JSON file |
| 177 | log.info('Parsing JSON file...') |
| 178 | try { |
| 179 | parsed = JSON.parse(unparsedConfig) |
| 180 | } catch { |
| 181 | throw "Couldn't parse JSON config file, check for syntax errors." |
| 182 | } |
| 183 | |
| 184 | try { |
| 185 | throwConfigError(parsed) |
| 186 | } catch (e) { |
| 187 | log.error(JSON.stringify(parsed, null, 2), false) |
| 188 | throw 'Parsed JSON file is invalid:\n' + e |
| 189 | } |
| 190 | } else { |
| 191 | throw `Invalid file extension: ${fileExtension}` |
| 192 | } |
| 193 | |
| 194 | return parsed |
| 195 | } |
| 196 | |
| 197 | async function readRemoteConfigFile(fileURL: string): Promise<LabelInfo[]> { |
| 198 | startGroup('Reading remote config file...') |
no test coverage detected