Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use fs.access instead of fs.existsSync
  • Loading branch information
lpinca committed Nov 11, 2015
commit fdedf38a1ccc570ca5ce30e4bf72a0927fa119b1
36 changes: 18 additions & 18 deletions scripts/tasks/download.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

var github = require('octonode')
var client = github.client()
var evRepo = client.repo('nodejs/evangelism')
const github = require('octonode')
const https = require('https')
const path = require('path')
const fs = require('fs')

var https = require('https')
var path = require('path')
var 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:
* ================
Expand All @@ -18,24 +18,24 @@ var fs = require('fs')
*/

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

let localPath = path.join(__dirname, '..', '..', 'locale', 'en', 'blog', 'weekly-updates', name)
if (fs.existsSync(localPath)) {
console.log(`Weekly Update ${name} exists. (No SHA check, yet.)`)
return
}
fs.access(filePath, function (err) {
if (!err) {
console.log(`Weekly Update ${filePath} exists. (No SHA check, yet.)`)
return
}

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

var outputFile = fs.createWriteStream(localPath)
https.get(downloadUrl, function (response) {
response.pipe(outputFile)
https.get(file.download_url, function (response) {
console.log(`Weekly Update ${filePath} downloaded.`)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thefourtheye If you feel strong about using only "Download completed.", I'll change this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually should have been

response.on('end', () => console.log(`Weekly Update ${filePath} downloaded.`))

response.pipe(fs.createWriteStream(filePath))
})
})
}

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