* @param {string} content * @returns {Promise }
(content)
| 157 | * @returns {Promise<string>} |
| 158 | */ |
| 159 | async function updateOptions(content) { |
| 160 | console.log('Listing options...'); |
| 161 | execSync('node cli.js --help > help.txt'); |
| 162 | const output = fs.readFileSync('help.txt'); |
| 163 | fs.unlinkSync('help.txt'); |
| 164 | const lines = output.toString().split('\n'); |
| 165 | const firstLine = lines.findIndex(line => line.includes('--version')); |
| 166 | lines.splice(0, firstLine + 1); |
| 167 | const lastLine = lines.findIndex(line => line.includes('--help')); |
| 168 | lines.splice(lastLine); |
| 169 | |
| 170 | /** |
| 171 | * @type {{ name: string, value: string }[]} |
| 172 | */ |
| 173 | const options = []; |
| 174 | for (let line of lines) { |
| 175 | if (line.startsWith(' --')) { |
| 176 | const l = line.substring(' --'.length); |
| 177 | const gapIndex = l.indexOf(' '); |
| 178 | const name = l.substring(0, gapIndex).trim(); |
| 179 | const value = l.substring(gapIndex).trim(); |
| 180 | options.push({ name, value }); |
| 181 | } else { |
| 182 | const value = line.trim(); |
| 183 | options[options.length - 1].value += ' ' + value; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | const table = []; |
| 188 | table.push(`| Option | Description |`); |
| 189 | table.push(`|--------|-------------|`); |
| 190 | for (const option of options) { |
| 191 | const prefix = option.name.split(' ')[0]; |
| 192 | const envName = optionEnvName(prefix); |
| 193 | table.push(`| --${option.name} | ${option.value}<br>*env* \`${envName}\` |`); |
| 194 | } |
| 195 | |
| 196 | if (process.env.PRINT_ENV) { |
| 197 | const envTable = []; |
| 198 | envTable.push(`| Environment |`); |
| 199 | envTable.push(`|-------------|`); |
| 200 | for (const option of options) { |
| 201 | const prefix = option.name.split(' ')[0]; |
| 202 | const envName = optionEnvName(prefix); |
| 203 | envTable.push(`| \`${envName}\` ${option.value} |`); |
| 204 | } |
| 205 | console.log(envTable.join('\n')); |
| 206 | } |
| 207 | |
| 208 | const startMarker = `<!--- Options generated by ${path.basename(__filename)} -->`; |
| 209 | const endMarker = `<!--- End of options generated section -->`; |
| 210 | return updateSection(content, startMarker, endMarker, table); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * @param {string} content |
no test coverage detected