archived/link-validator-with-monorepo-links.js
/**
 * Validates monorepo README links that point back to the docs.
 * Reads a list of READMEs from the monorepo-readmes file.
 */
Validates monorepo README links that point back to the docs.
Reads a list of READMEs from the monorepo-readmes file.
Validates monorepo README links that point back to the docs . Reads a list of READMEs from the monorepo - readmes file .
async function loadMonorepoReadmes() {
  console.log(
    'Reading README files from GitHub. Will only check those with links to docs.api3.org, please wait...'
  );
  const data = readFileSync('./docs/.vuepress/dist/monorepo-readmes-sync', {
    encoding: 'utf8',
    flag: 'r',
  });
  let readmeArr = data.split(/\r?\n/);
  let cnt = 1;
  for (let i = 0; i < readmeArr.length; i++) {
    if (readmeArr[i].length > 6) {
      await callGitHub(readmeArr[i], cnt);
      cnt++;
    }
  }
  process.stdout.moveCursor(0, -1); 
  process.stdout.clearLine(1); 
  async function callGitHub(url, cnt) {
    try {
      console.log(cnt + '.', url);
      axios.defaults.timeout = 10000;
      const response = await axios.get(url);
      const linksArr = oust(response.data, 'links');
      for (let i = 0; i < linksArr.length; i++) {
        if (linksArr[i].indexOf('docs.api3.org/') > -1) {
          linksObj[linksArr[i]] = 'monorepo readmeUrl: ' + url;
        }
      }
      await new Promise((resolve) => setTimeout(resolve, 200));
      process.stdout.moveCursor(0, -1); 
      process.stdout.clearLine(1); 
    } catch (error) {
      process.stdout.write(
        colors.bold.red('Failed to get README from monorepo:', url, '\n')
      );
    }
  }
}
async function loadMonorepoReadmes ( ) { console . log ( 'Reading README files from GitHub. Will only check those with links to docs.api3.org, please wait...' ) ; const data = readFileSync ( './docs/.vuepress/dist/monorepo-readmes-sync' , { encoding : 'utf8' , flag : 'r' , } ) ; let readmeArr = data . split ( / \r?\n / ) ; let cnt = 1 ; for ( let i = 0 ; i < readmeArr . length ; i ++ ) { if ( readmeArr [ i ] . length > 6 ) { await callGitHub ( readmeArr [ i ] , cnt ) ; cnt ++ ; } } process . stdout . moveCursor ( 0 , - 1 ) ; process . stdout . clearLine ( 1 ) ; async function callGitHub ( url , cnt ) { try { console . log ( cnt + '.' , url ) ; axios . defaults . timeout = 10000 ; const response = await axios . get ( url ) ; const linksArr = oust ( response . data , 'links' ) ; for ( let i = 0 ; i < linksArr . length ; i ++ ) { if ( linksArr [ i ] . indexOf ( 'docs.api3.org/' ) > - 1 ) { linksObj [ linksArr [ i ] ] = 'monorepo readmeUrl: ' + url ; } } await new Promise ( ( resolve ) => setTimeout ( resolve , 200 ) ) ; process . stdout . moveCursor ( 0 , - 1 ) ; process . stdout . clearLine ( 1 ) ; } catch ( error ) { process . stdout . write ( colors . bold . red ( 'Failed to get README from monorepo:' , url , '\n' ) ) ; } } }
Validates monorepo README links that point back to the docs.
Validates monorepo README links that point back to the docs .
// Empty or short lines in file // up one line // from cursor to end // Pause because calling GitHub rapidly upsets them. // up one line // from cursor to end