lib/generate.js
/**
 * The main function for this process; loads all patterns/feeds from the
 * specified feeds and kicks off the recursive tile generation
 */
The main function for this process; loads all patterns/feeds from the
specified feeds and kicks off the recursive tile generation
The main function for this process ; loads all patterns / feeds from the specified feeds and kicks off the recursive tile generation
function loadFeedsAndGenerateTiles () {
  const feedIds = config.feeds
  let patterns = []
  let stops = []
  const addFeedAndProceed = (processedFeed, i, done) => {
    patterns = patterns.concat(processedFeed.patterns)
    stops = stops.concat(processedFeed.stops)
    if (i < feedIds.length - 1) {
      loadNextFeed(i + 1, done)
    } else {
      done()
    }
  }
  const loadNextFeed = (i, done) => {
    console.log(`Checking cache for ${feedIds[i]}`)
    const filepath = `./cache/${feedIds[i]}.json`
    if (fs.existsSync(filepath)) {
      console.log('- found, reading from cache..')
      const feedData = JSON.parse(fs.readFileSync(filepath))
      addFeedAndProceed(processFeed(feedData), i, done)
    } else {
      console.log('- not found, querying GTFS API..')
      queryFeed(feedIds[i]).then(processedFeed => {
        addFeedAndProceed(processedFeed, i, done)
      })
    }
  }
  loadNextFeed(0, () => {
    console.log('total patterns processed: ' + patterns.length)
    console.log('total stops processed: ' + stops.length)
    processTile(0, 0, 0, patterns, stops) 
  })
}
function loadFeedsAndGenerateTiles ( ) { const feedIds = config . feeds let patterns = [ ] let stops = [ ] const addFeedAndProceed = ( processedFeed , i , done ) => { patterns = patterns . concat ( processedFeed . patterns ) stops = stops . concat ( processedFeed . stops ) if ( i < feedIds . length - 1 ) { loadNextFeed ( i + 1 , done ) } else { done ( ) } } const loadNextFeed = ( i , done ) => { console . log ( ` ${ feedIds [ i ] } ` ) const filepath = ` ${ feedIds [ i ] } ` if ( fs . existsSync ( filepath ) ) { console . log ( '- found, reading from cache..' ) const feedData = JSON . parse ( fs . readFileSync ( filepath ) ) addFeedAndProceed ( processFeed ( feedData ) , i , done ) } else { console . log ( '- not found, querying GTFS API..' ) queryFeed ( feedIds [ i ] ) . then ( processedFeed => { addFeedAndProceed ( processedFeed , i , done ) } ) } } loadNextFeed ( 0 , ( ) => { console . log ( 'total patterns processed: ' + patterns . length ) console . log ( 'total stops processed: ' + stops . length ) processTile ( 0 , 0 , 0 , patterns , stops ) } ) }
The main function for this process; loads all patterns/feeds from the
 specified feeds and kicks off the recursive tile generation
The main function for this process ; loads all patterns / feeds from the specified feeds and kicks off the recursive tile generation
// helper function to add processed routes/stops and move on to next feed // helper function to load a single feed, trying cache first, then API // kick off the loading process with the first feed // all feeds loaded // start at the 'root' tile