(str)
| 131 | * @param {string} str |
| 132 | */ |
| 133 | const parseRenderString = (str) => { |
| 134 | const parseArr = str |
| 135 | .trim() |
| 136 | .split('},') |
| 137 | .filter((o) => o.trim() != '{' && o.trim() != '}' && o.trim()); |
| 138 | const result = []; |
| 139 | let obj = {}; |
| 140 | const tagRegex = /(?<=(-------- )).*?(?=( --------)) /; |
| 141 | const methodRegex = /(?<=method:(\s*)\')[^\',]*/; |
| 142 | const urlRegex = /(?<=url:(\s*)(\`|\'|\"))[^(\`|\'|\"),]*/; |
| 143 | const keyRegex = /[^:\`,]*/; |
| 144 | const commentRegex = /(?<=\/\/)[^(\n)]*/; |
| 145 | parseArr.forEach((item) => { |
| 146 | if (tagRegex.test(item)) { |
| 147 | result.push(obj); |
| 148 | obj = {}; |
| 149 | obj.name = item.match(tagRegex)[0].trim(); |
| 150 | obj.description = ''; |
| 151 | obj.data = []; |
| 152 | } else { |
| 153 | try { |
| 154 | const method = methodRegex.test(item) ? item.match(methodRegex)[0].trim() : ''; |
| 155 | const url = urlRegex.test(item) ? item.match(urlRegex)[0].trim() : ''; |
| 156 | const key = keyRegex.test(item) ? item.match(keyRegex)[0].trim() : ''; |
| 157 | const comment = commentRegex.test(item) ? item.match(commentRegex)[0].trim() : ''; |
| 158 | Array.isArray(obj.data) && |
| 159 | obj.data.push({ |
| 160 | path: url, |
| 161 | operationId: key, |
| 162 | summary: comment, |
| 163 | method, |
| 164 | }); |
| 165 | } catch (err) { |
| 166 | logs(`${item}失败:`, err); |
| 167 | } |
| 168 | } |
| 169 | }); |
| 170 | return result.filter((o) => JSON.stringify(o) != '{}'); |
| 171 | }; |
| 172 | /** |
| 173 | * 处理并合并已存在的文件的内容 |
| 174 | * @param {string}path-文件地址 |
no test coverage detected