index.js
/**
 * Fetch a language code sample from GitHub.
 * @param {Object} languageCodeSample The language code sample spec to fetch.
 */
Fetch a language code sample from GitHub.
@param {Object} languageCodeSample The language code sample spec to fetch.
Fetch a language code sample from GitHub . @param { Object } languageCodeSample The language code sample spec to fetch .
function fetchLanguageCodeSample(github, languageCodeSample) {
  return new Promise(function (resolve, reject) {
    var repository = repositories[languageCodeSample.repository];
    if (typeof repository === 'undefined') {
      reportError('Repository "' + languageCodeSample.repository + '" definition does not exist');
      process.exit(1); 
    }
    var path = languageCodeSample.code;
    var promises = path.map(function (currentPath) {
      return getGithubFileContent(github, repository.user, repository.name, repository.branch, currentPath);
    });
    Promise.all(promises).then(function (fileContents) {
      var fileContent = fileContents[0];
      for (var i = 1; i < fileContents.length; i++) {
        var separator = '\n\n\n\n';
        if (path[i].noSeparator) {
          separator = '\n\n';
        }
        fileContent += separator + fileContents[i];
      }
      fileContent = wrapCodeInPrettifyPre(fileContent, languageCodeSample.language);
      resolve(fileContent);
    }, function () {
      reportError('Failed to retrieve all files in: ' + (typeof path[0] === 'string' ? path[0] : path[0].file));
      reject();
    });
  });
}
function fetchLanguageCodeSample ( github , languageCodeSample ) { return new Promise ( function ( resolve , reject ) { var repository = repositories [ languageCodeSample . repository ] ; if ( typeof repository === 'undefined' ) { reportError ( 'Repository "' + languageCodeSample . repository + '" definition does not exist' ) ; process . exit ( 1 ) ; } var path = languageCodeSample . code ; var promises = path . map ( function ( currentPath ) { return getGithubFileContent ( github , repository . user , repository . name , repository . branch , currentPath ) ; } ) ; Promise . all ( promises ) . then ( function ( fileContents ) { var fileContent = fileContents [ 0 ] ; for ( var i = 1 ; i < fileContents . length ; i ++ ) { var separator = '\n\n\n\n' ; if ( path [ i ] . noSeparator ) { separator = '\n\n' ; } fileContent += separator + fileContents [ i ] ; } fileContent = wrapCodeInPrettifyPre ( fileContent , languageCodeSample . language ) ; resolve ( fileContent ) ; } , function ( ) { reportError ( 'Failed to retrieve all files in: ' + ( typeof path [ 0 ] === 'string' ? path [ 0 ] : path [ 0 ] . file ) ) ; reject ( ) ; } ) ; } ) ; }
Fetch a language code sample from GitHub.
Fetch a language code sample from GitHub .
// TODO: Cache github repos here // eslint-disable-line no-process-exit