MCPcopy
hub / github.com/QwikDev/qwik / scanForDocDirective

Function scanForDocDirective

scripts/docs_sync/main.ts:13–57  ·  view source on GitHub ↗
(file: string, lines: string[])

Source from the content-addressed store, hash-verified

11}
12
13async function scanForDocDirective(file: string, lines: string[]) {
14 const output: string[] = [];
15 let row = 0;
16 let write = false;
17 while (row < lines.length) {
18 const line = lines[row++];
19 output.push(line);
20 const match = /^(\s*)\/\/ <docs markdown="(.*)#(.*)">/.exec(line);
21 if (match) {
22 const prefix = match[1];
23 console.log('line', line, JSON.stringify(prefix));
24 const ref = match[2];
25 const section = match[3];
26 let bookRef = ref.replace(/\/\/hackmd.io\//, '//hackmd.io/@qwik-docs/BkxpSz80Y/%2F');
27 if (bookRef.indexOf('hackmd.io') !== -1) {
28 bookRef += '%3Fboth';
29 }
30 output.push(prefix + `// !!DO NOT EDIT THIS COMMENT DIRECTLY!!!`);
31 output.push(prefix + `// (edit ${bookRef}#${section} instead)`);
32 output.push(prefix + '/**');
33 (await resolveComment(dirname(file), ref, section)).forEach((longLine) =>
34 breakLongLine(longLine).forEach((line) =>
35 output.push(prefix + ' *' + (line ? ' ' + line : ''))
36 )
37 );
38 output.push(prefix + ' */');
39 while (row < lines.length) {
40 const line2 = lines[row++];
41 if (!isComment(line2)) {
42 throw new Error(
43 'Missing end `</doc>` tag. Got: ' + line2 + '\n' + file + '[' + row + ']'
44 );
45 }
46 if (line2.indexOf('// </docs>') != -1) {
47 output.push(line2);
48 break;
49 }
50 }
51 write = true;
52 }
53 }
54 if (write) {
55 await writeFileLines(file, output);
56 }
57}
58
59function isComment(line: string): boolean {
60 line = line.trim();

Callers 1

mainFunction · 0.85

Calls 5

writeFileLinesFunction · 0.90
resolveCommentFunction · 0.85
dirnameFunction · 0.85
breakLongLineFunction · 0.85
isCommentFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…