build-system/tasks/check-links.js
/**
 * Parses the list of files in argv and checks for dead links.
 *
 * @return {Promise} Used to wait until all async link checkers finish.
 */
Parses the list of files in argv and checks for dead links.
@return {Promise} Used to wait until all async link checkers finish.
Parses the list of files in argv and checks for dead links . @return { Promise } Used to wait until all async link checkers finish .
function checkLinks() {
  var markdownFiles = getMarkdownFiles();
  var linkCheckers = markdownFiles.map(function(markdownFile) {
    return runLinkChecker(markdownFile);
  });
  return BBPromise.all(linkCheckers)
  .then(function(allResults) {
    var deadLinksFound = false;
    var filesWithDeadLinks = [];
    allResults.map(function(results, index) {
      if (!fs.existsSync(markdownFiles[index])) {
        return;
      }
      var deadLinksFoundInFile = false;
      results.forEach(function (result) {
        if (isLinkToFileIntroducedByPR(result.link)) {
          return;
        }
        if(result.status === 'dead') {
          deadLinksFound = true;
          deadLinksFoundInFile = true;
          util.log('[%s] %s', chalk.red('✖'), result.link);
        } else if (!process.env.TRAVIS) {
          util.log('[%s] %s', chalk.green('✔'), result.link);
        }
      });
      if(deadLinksFoundInFile) {
        filesWithDeadLinks.push(markdownFiles[index]);
        util.log(
            util.colors.red('ERROR'),
            'Possible dead link(s) found in',
            util.colors.magenta(markdownFiles[index]));
      } else {
        util.log(
            util.colors.green('SUCCESS'),
            'All links in',
            util.colors.magenta(markdownFiles[index]), 'are alive.');
      }
    });
    if (deadLinksFound) {
        util.log(
            util.colors.red('ERROR'),
            'Please update dead link(s) in',
            util.colors.magenta(filesWithDeadLinks.join(',')),
            'or whitelist them in build-system/tasks/check-links.js');
        util.log(
            util.colors.yellow('NOTE'),
            'If the link(s) above are illustrative and aren\'t meant to work,',
            'surrounding them with backticks or <code></code> will exempt them',
            'from the link checker.');
        process.exit(1);
    } else {
        util.log(
            util.colors.green('SUCCESS'),
            'All links in all markdown files in this PR are alive.');
    }
  });
}
function checkLinks ( ) { var markdownFiles = getMarkdownFiles ( ) ; var linkCheckers = markdownFiles . map ( function ( markdownFile ) { return runLinkChecker ( markdownFile ) ; } ) ; return BBPromise . all ( linkCheckers ) . then ( function ( allResults ) { var deadLinksFound = false ; var filesWithDeadLinks = [ ] ; allResults . map ( function ( results , index ) { if ( ! fs . existsSync ( markdownFiles [ index ] ) ) { return ; } var deadLinksFoundInFile = false ; results . forEach ( function ( result ) { if ( isLinkToFileIntroducedByPR ( result . link ) ) { return ; } if ( result . status === 'dead' ) { deadLinksFound = true ; deadLinksFoundInFile = true ; util . log ( '[%s] %s' , chalk . red ( '✖'), r sult.l i nk); } else if ( ! process . env . TRAVIS ) { util . log ( '[%s] %s' , chalk . green ( '✔'), r sult.l i nk); } } ) ; if ( deadLinksFoundInFile ) { filesWithDeadLinks . push ( markdownFiles [ index ] ) ; util . log ( util . colors . red ( 'ERROR' ) , 'Possible dead link(s) found in' , util . colors . magenta ( markdownFiles [ index ] ) ) ; } else { util . log ( util . colors . green ( 'SUCCESS' ) , 'All links in' , util . colors . magenta ( markdownFiles [ index ] ) , 'are alive.' ) ; } } ) ; if ( deadLinksFound ) { util . log ( util . colors . red ( 'ERROR' ) , 'Please update dead link(s) in' , util . colors . magenta ( filesWithDeadLinks . join ( ',' ) ) , 'or whitelist them in build-system/tasks/check-links.js' ) ; util . log ( util . colors . yellow ( 'NOTE' ) , 'If the link(s) above are illustrative and aren\'t meant to work,' , 'surrounding them with backticks or <code></code> will exempt them' , 'from the link checker.' ) ; process . exit ( 1 ) ; } else { util . log ( util . colors . green ( 'SUCCESS' ) , 'All links in all markdown files in this PR are alive.' ) ; } } ) ; }
Parses the list of files in argv and checks for dead links.
Parses the list of files in argv and checks for dead links .
// Skip files that were deleted by the PR. // Skip links to files that were introduced by the PR.