MCPcopy Create free account
hub / github.com/DIYgod/RSSHub / processFile

Function processFile

scripts/workflow/format-description.ts:221–265  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

219}
220
221async function processFile(filePath: string): Promise<void> {
222 const sourceText = await fs.readFile(filePath, 'utf8');
223 if (!sourceText.includes('description')) {
224 return;
225 }
226
227 const sourceFile = typescript.createSourceFile(filePath, sourceText, typescript.ScriptTarget.Latest, false, filePath.endsWith('.tsx') ? typescript.ScriptKind.TSX : typescript.ScriptKind.TS);
228
229 const edits = collectDescriptionEdits(sourceFile);
230 if (edits.length === 0) {
231 return;
232 }
233
234 edits.sort((a, b) => b.start - a.start);
235
236 let result = sourceText;
237 let changed = false;
238
239 const formattedResults = await Promise.all(
240 edits.map(async (edit) => {
241 if (!edit.raw.trim()) {
242 return { edit, formatted: null as string | null };
243 }
244 const file = await processor.process(edit.raw);
245 return {
246 edit,
247 formatted: String(file).replace(/\n+$/, ''),
248 };
249 })
250 );
251
252 for (const { edit, formatted } of formattedResults) {
253 if (!formatted || formatted === edit.raw) {
254 continue;
255 }
256
257 const replacement = '`' + escapeTemplateLiteral(formatted) + '`'; // oxlint handles unncessary single line template literals.
258 result = result.slice(0, edit.start) + replacement + result.slice(edit.end);
259 changed = true;
260 }
261
262 if (changed) {
263 await fs.writeFile(filePath, result, 'utf8');
264 }
265}
266
267function isRouteFile(filePath: string): boolean {
268 const abs = path.resolve(filePath);

Callers 1

mainFunction · 0.85

Calls 3

collectDescriptionEditsFunction · 0.85
escapeTemplateLiteralFunction · 0.85
sliceMethod · 0.80

Tested by

no test coverage detected