gen-nav.js 786 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env node
  2. const path = require('path');
  3. const proc = require('child_process');
  4. const startCase = require('lodash.startcase');
  5. const baseDir = process.argv[2];
  6. const files = proc.execFileSync(
  7. 'find', [baseDir, '-type', 'f'], { encoding: 'utf8' }
  8. ).split('\n').filter(s => s !== '');
  9. console.log('.API');
  10. const links = files.map((file) => {
  11. const doc = file.replace(baseDir, '');
  12. const title = path.parse(file).name;
  13. return {
  14. xref: `* xref:${doc}[${startCase(title)}]`,
  15. title,
  16. };
  17. });
  18. // Case-insensitive sort based on titles (so 'token/ERC20' gets sorted as 'erc20')
  19. const sortedLinks = links.sort(function (a, b) {
  20. return a.title.toLowerCase().localeCompare(b.title.toLowerCase());
  21. });
  22. for (const link of sortedLinks) {
  23. console.log(link.xref);
  24. }