(key, urls)
| 204 | } |
| 205 | |
| 206 | function addPlayerUrls(key, urls) { |
| 207 | logFoundUrls(key, urls, URL_TYPES.PLAYER); |
| 208 | |
| 209 | let file = fs.readFileSync(path.resolve('./src/pages/playerUrls.js'), 'utf8'); |
| 210 | |
| 211 | const comment = ` // auto-${key}-replace-dont-remove`; |
| 212 | |
| 213 | let data = ''; |
| 214 | let addedCount = 0; |
| 215 | const existingUrls = []; |
| 216 | for (const url of urls) { |
| 217 | if (!file.includes(url)) { |
| 218 | data += ` '*://${url}',\n`; |
| 219 | addedCount++; |
| 220 | } else { |
| 221 | existingUrls.push(url); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | if (existingUrls.length > 0) { |
| 226 | console.log(`[${key}] URLs already exist:\n ${existingUrls.join(',\n ')}`); |
| 227 | } |
| 228 | |
| 229 | if (addedCount > 0) { |
| 230 | data += comment; |
| 231 | file = file.replace(comment, data); |
| 232 | fs.writeFileSync(path.resolve('./src/pages/playerUrls.js'), file); |
| 233 | console.log(`[${key}] Added ${addedCount} new URLs.`); |
| 234 | } else { |
| 235 | console.log(`[${key}] No new URLs added.`); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | const URL_TYPES = { |
| 240 | PAGE: 'page', |
no test coverage detected