MCPcopy
hub / github.com/SukkaW/Surge / processFile

Function processFile

Build/build-common.ts:57–99  ·  view source on GitHub ↗
(span: Span, sourcePath: string)

Source from the content-addressed store, hash-verified

55const $skip = Symbol('skip');
56
57function processFile(span: Span, sourcePath: string) {
58 return span.traceChildAsync(`process file: ${sourcePath}`, async () => {
59 const lines: string[] = [];
60
61 let title = '';
62 const descriptions: string[] = [];
63 let sgmodulePathname: string | null = null;
64
65 try {
66 let l: string | null = '';
67 for await (const line of readFileByLine(sourcePath)) {
68 if (line.startsWith(MAGIC_COMMAND_SKIP)) {
69 return $skip;
70 }
71
72 if (line.startsWith(MAGIC_COMMAND_TITLE)) {
73 title = line.slice(MAGIC_COMMAND_TITLE.length).trim();
74 continue;
75 }
76
77 if (line.startsWith(MAGIC_COMMAND_DESCRIPTION)) {
78 descriptions.push(line.slice(MAGIC_COMMAND_DESCRIPTION.length).trim());
79 continue;
80 }
81
82 if (line.startsWith(MAGIC_COMMAND_SGMODULE_MITM_HOSTNAMES)) {
83 sgmodulePathname = line.slice(MAGIC_COMMAND_SGMODULE_MITM_HOSTNAMES.length).trim();
84 continue;
85 }
86
87 l = processLine(line);
88 if (l) {
89 lines.push(l);
90 }
91 }
92 } catch (e) {
93 console.error('Error processing', sourcePath);
94 console.trace(e);
95 }
96
97 return [title, descriptions, lines, sgmodulePathname] as const;
98 });
99}
100
101async function transform(parentSpan: Span, sourcePath: string, relativePath: string) {
102 const extname = path.extname(sourcePath);

Callers 1

transformFunction · 0.85

Calls 2

readFileByLineFunction · 0.90
processLineFunction · 0.90

Tested by

no test coverage detected