MCPcopy Index your code
hub / github.com/MALSync/MALSync / addChibiUrls

Function addChibiUrls

webpackConfig/autoUrls.mjs:159–204  ·  view source on GitHub ↗
(page, urls, mainName = 'main.ts')

Source from the content-addressed store, hash-verified

157}
158
159function addChibiUrls(page, urls, mainName = 'main.ts') {
160 logFoundUrls(page, urls, URL_TYPES.CHIBI);
161
162 let file = fs.readFileSync(
163 path.resolve(`src/pages-chibi/implementations/${page}/${mainName}`),
164 'utf8',
165 );
166
167 const matchRegex = /match:\s*\[(.*?)\]/s;
168 const matchMatch = file.match(matchRegex);
169 if (!matchMatch) {
170 throw new Error(`No match found in ${page} ${mainName}`);
171 }
172
173 const urlRegex = matchMatch[1].match(/'([^']+)'/g) || [];
174 const matchUrls = urlRegex.map(url => url.replace(/'/g, ''));
175
176 let addedCount = 0;
177 const existingUrls = [];
178 for (const url of urls) {
179 if (!matchUrls.includes(url)) {
180 matchUrls.push(url);
181 addedCount++;
182 } else {
183 existingUrls.push(url);
184 }
185 }
186
187 if (existingUrls.length > 0) {
188 console.log(`[${page}] URLs already exist:\n ${existingUrls.join(',\n ')}`);
189 }
190
191 if (addedCount > 0) {
192 const updatedFile = file.replace(
193 matchRegex,
194 `match: [${matchUrls.map(url => `'${url}'`).join(', ')}]`,
195 );
196 fs.writeFileSync(
197 path.resolve(`src/pages-chibi/implementations/${page}/${mainName}`),
198 updatedFile,
199 );
200 console.log(`[${page}] Added ${addedCount} new URLs.`);
201 } else {
202 console.log(`[${page}] No new URLs added.`);
203 }
204}
205
206function addPlayerUrls(key, urls) {
207 logFoundUrls(key, urls, URL_TYPES.PLAYER);

Callers 3

animekaiFunction · 0.85
batoFunction · 0.85
mangaparkFunction · 0.85

Calls 1

logFoundUrlsFunction · 0.85

Tested by

no test coverage detected