'use strict'

const github = require('octonode')
const https = require('https')
const path = require('path')
const fs = require('fs')

const basePath = path.join(__dirname, '..', '..', 'locale', 'en', 'blog', 'weekly-updates')
const repo = github.client().repo('nodejs/evangelism')

/* Currently proof-of-concept work. Outstanding:
 * ================
 * - [ ] gulpify
 * - [ ] add to local boot process or trigger at key times
 * - [ ] support other content patterns (meeting notes, release notes, etc.)
 * - [ ] support similar patterns for other locales
 * - [ ] prepend predictable markdown metadata on download
 */

function checkOrFetchFile (file) {
  const filePath = path.join(basePath, file.name)

  fs.access(filePath, function (err) {
    if (!err) {
      console.log(`Weekly Update ${filePath} exists. (No SHA check, yet.)`)
      return
    }

    console.log(`Weekly Update ${filePath} does not exist. Downloading.`)

    https.get(file.download_url, function (response) {
      console.log(`Weekly Update ${filePath} downloaded.`)

      const ws = fs.createWriteStream(filePath)
      ws.on('error', function (err) {
        console.error(err.stack)
      })
      response.pipe(ws)
    }).on('error', function (err) {
      console.error(err.stack)
    })
  })
}

repo.contents('weekly-updates', function (err, files) {
  if (err) { throw err }
  files.forEach(checkOrFetchFile)
})

@@ -721,31 +721,25 @@
 ilePath,
- function
  (err)
+ =%3E
  %7B%0A    i
@@ -952,25 +952,16 @@
 oad_url,
- function
  (respon
@@ -968,69 +968,12 @@
 se) 
-%7B%0A      console.log(%60Weekly Update $%7BfilePath%7D downloaded.%60)%0A
+=%3E %7B
 %0A   
@@ -1042,32 +1042,16 @@
 r', 
-function (err) %7B%0A       
+(err) =%3E
  con
@@ -1075,16 +1075,94 @@
 ack)
+)%0A
 %0A      
-%7D
+response.on('end', () =%3E console.log(%60Weekly Update $%7BfilePath%7D downloaded.%60)
 )%0A  
@@ -1206,30 +1206,16 @@
 r', 
-function (err) %7B%0A     
+(err) =%3E
  con
@@ -1235,22 +1235,16 @@
 r.stack)
-%0A    %7D
 )%0A  %7D)%0A%7D
@@ -1280,17 +1280,8 @@
 es',
- function
  (er
@@ -1289,16 +1289,19 @@
 , files)
+ =%3E
  %7B%0A  if 

Use arrow functions