Skip to content

Commit fdedf38

Browse files
committed
Use fs.access instead of fs.existsSync
1 parent b51762b commit fdedf38

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

scripts/tasks/download.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict'
22

3-
var github = require('octonode')
4-
var client = github.client()
5-
var evRepo = client.repo('nodejs/evangelism')
3+
const github = require('octonode')
4+
const https = require('https')
5+
const path = require('path')
6+
const fs = require('fs')
67

7-
var https = require('https')
8-
var path = require('path')
9-
var fs = require('fs')
8+
const basePath = path.join(__dirname, '..', '..', 'locale', 'en', 'blog', 'weekly-updates')
9+
const repo = github.client().repo('nodejs/evangelism')
1010

1111
/* Currently proof-of-concept work. Outstanding:
1212
* ================
@@ -18,24 +18,24 @@ var fs = require('fs')
1818
*/
1919

2020
function checkOrFetchFile (file) {
21-
let name = file.name
22-
let downloadUrl = file.download_url
21+
const filePath = path.join(basePath, file.name)
2322

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

30-
console.log(`Weekly Update ${name} does not exist. Downloading.`)
29+
console.log(`Weekly Update ${filePath} does not exist. Downloading.`)
3130

32-
var outputFile = fs.createWriteStream(localPath)
33-
https.get(downloadUrl, function (response) {
34-
response.pipe(outputFile)
31+
https.get(file.download_url, function (response) {
32+
console.log(`Weekly Update ${filePath} downloaded.`)
33+
response.pipe(fs.createWriteStream(filePath))
34+
})
3535
})
3636
}
3737

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

0 commit comments

Comments
 (0)