#!/usr/bin/env node

const path = require('path');
const proc = require('child_process');
const startCase = require('lodash.startcase');

const baseDir = process.argv[2];

const files = proc.execFileSync(
  'find', [baseDir, '-type', 'f'], { encoding: 'utf8' }
).split('\n').filter(s => s !== '');

console.log('.API');

const links = files.map((file) => {
    const doc = file.replace(baseDir, '');
    const title = path.parse(file).name;

    return {
      xref: `* xref:${doc}[${startCase(title)}]`,
      title,
    };
});

// Case-insensitive sort based on titles (so 'token/ERC20' gets sorted as 'erc20')
const sortedLinks = links.sort(function (a, b) {
  return a.title.toLowerCase().localeCompare(b.title.toLowerCase());
});

for (const link of sortedLinks) {
   console.log(link.xref);
}

@@ -350,18 +350,16 @@
 e) =%3E %7B%0A
-  
   const 
@@ -393,18 +393,16 @@
  '');%0A  
- 
- 
 const ti
@@ -431,18 +431,16 @@
 .name;%0A%0A
-  
   return
@@ -446,18 +446,16 @@
 n %7B%0A    
-  
 xref: %60*
@@ -498,19 +498,15 @@
     
-  
 title,%0A
-  
   %7D;
@@ -751,17 +751,16 @@
 inks) %7B%0A
- 
   consol

Fix linter errors