(path: string, outPath: string)
| 70 | } |
| 71 | |
| 72 | export function packageJSONtoMd(path: string, outPath: string) { |
| 73 | let obj: any; |
| 74 | try { |
| 75 | const txt = fs.readFileSync(path); |
| 76 | obj = JSON.parse(txt.toString()); |
| 77 | } |
| 78 | catch (e) { |
| 79 | console.error(`Error: Could not open/read file ${path}`, e); |
| 80 | return 1; |
| 81 | } |
| 82 | const dbgSections = obj?.contributes?.debuggers; |
| 83 | if (!dbgSections) { |
| 84 | console.error(`No "debuggers" found in file ${path}`); |
| 85 | return 1; |
| 86 | } |
| 87 | for (const dbgSection of dbgSections) { |
| 88 | const attrs = dbgSection.configurationAttributes; |
| 89 | const attach = attrs?.attach?.properties; |
| 90 | const launch = attrs?.launch?.properties; |
| 91 | if (!attach) { |
| 92 | console.error('"attach" properties not found'); |
| 93 | return 1; |
| 94 | } |
| 95 | if (!launch) { |
| 96 | console.error('"launch" properties not found'); |
| 97 | return 1; |
| 98 | } |
| 99 | let attachProps = Object.keys(attach); |
| 100 | let launchProps = Object.keys(launch); |
| 101 | const common = {}; |
| 102 | for (const prop of launchProps) { |
| 103 | if (attach[prop]?.deprecated || launch[prop]?.deprecated) { |
| 104 | delete launch[prop]; |
| 105 | delete attach[prop]; |
| 106 | continue; |
| 107 | } |
| 108 | if (attachProps.findIndex((str) => str === prop) !== -1) { |
| 109 | common[prop] = launch[prop]; |
| 110 | if (launch[prop].description !== attach[prop].description) { |
| 111 | console.warn(`Warning: Description does not match for property ${prop} between attach and launch`); |
| 112 | } |
| 113 | delete launch[prop]; |
| 114 | delete attach[prop]; |
| 115 | } |
| 116 | } |
| 117 | attachProps = Object.keys(attach).sort(); |
| 118 | launchProps = Object.keys(launch).sort(); |
| 119 | const commonProps = Object.keys(common).sort(); |
| 120 | const allProps = attachProps.concat(launchProps).concat(commonProps).sort(); |
| 121 | // console.log('launch', launchProps); |
| 122 | // console.log('attach', attachProps); |
| 123 | // console.log('common', commonProps); |
| 124 | try { |
| 125 | const stream = fs.createWriteStream(outPath); |
| 126 | writeHeader(stream); |
| 127 | stream.write('| Attribute | Type | Launch/ Attach | Description |\n'); |
| 128 | stream.write('| --------- | ---- | ---------------- | ----------- |\n'); |
| 129 | for (const prop of allProps) { |
no test coverage detected