(functionNames, inputPath, outputPath, outputRoot)
| 661 | * @param {String} outputRoot Path to /docs/reference |
| 662 | */ |
| 663 | export function iteratePath (functionNames, inputPath, outputPath, outputRoot) { |
| 664 | if (!fs.existsSync(outputPath)) { |
| 665 | mkdirp.sync(outputPath) |
| 666 | } |
| 667 | const functions = collectDocs(functionNames, inputPath) |
| 668 | let issues = [] |
| 669 | for (const fn of Object.values(functions)) { |
| 670 | issues = issues.concat(fn.issues) |
| 671 | const markdown = generateMarkdown(fn.doc, functions) |
| 672 | fs.writeFileSync(outputPath + '/' + fn.name + '.md', markdown) |
| 673 | } |
| 674 | |
| 675 | /** |
| 676 | * Helper function to generate a markdown list entry for a function. |
| 677 | * Used to generate both alphabetical and categorical index pages. |
| 678 | * @param {string} name Function name |
| 679 | * @returns {string} Returns a markdown list entry |
| 680 | */ |
| 681 | function functionEntry (name) { |
| 682 | const fn = functions[name] |
| 683 | let syntax = SYNTAX[name] || (fn.doc && fn.doc.syntax && fn.doc.syntax[0]) || name |
| 684 | syntax = syntax |
| 685 | // .replace(/^math\./, '') |
| 686 | .replace(/\s+\/\/.*$/, '') |
| 687 | .replace(/;$/, '') |
| 688 | if (syntax.length < 40) { |
| 689 | syntax = syntax.replace(/ /g, ' ') |
| 690 | } |
| 691 | |
| 692 | let description = '' |
| 693 | if (fn.doc.description) { |
| 694 | description = fn.doc.description.replace(/\n/g, ' ').split('.')[0] + '.' |
| 695 | } |
| 696 | |
| 697 | return '[' + syntax + '](functions/' + name + '.md) | ' + description |
| 698 | } |
| 699 | |
| 700 | /** |
| 701 | * Change the first letter of the given string to upper case |
| 702 | * @param {string} text |
| 703 | */ |
| 704 | function toCapital (text) { |
| 705 | return text[0].toUpperCase() + text.slice(1) |
| 706 | } |
| 707 | |
| 708 | const order = ['core', 'construction', 'expression'] // and then the rest |
| 709 | function categoryIndex (entry) { |
| 710 | const index = order.indexOf(entry) |
| 711 | return index === -1 ? Infinity : index |
| 712 | } |
| 713 | function compareAsc (a, b) { |
| 714 | return a > b ? 1 : (a < b ? -1 : 0) |
| 715 | } |
| 716 | function compareCategory (a, b) { |
| 717 | const indexA = categoryIndex(a) |
| 718 | const indexB = categoryIndex(b) |
| 719 | return (indexA > indexB) ? 1 : (indexA < indexB ? -1 : compareAsc(a, b)) |
| 720 | } |
no test coverage detected
searching dependent graphs…