Skip to content

Commit

Permalink
Auto-create generation/source-data folder
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtuchkin committed Jun 7, 2020
1 parent d74d7f0 commit 440aa82
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
13 changes: 9 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Node.js stuff
node_modules
wiki
package-lock.json

# Editors
*~
*sublime-*
coverage
/.idea
package-lock.json
benchmarks/node_envs

# Development environment
/coverage
/benchmarks/node_envs
/generation/source-data
7 changes: 0 additions & 7 deletions generation/source-data/.gitignore

This file was deleted.

14 changes: 9 additions & 5 deletions generation/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ var request = require('request'),
// Common utilities used in scripts.

exports.getFile = function(url, cb) {
var fullpath = path.join(__dirname, "source-data", path.basename(url));
var sourceDataFolder = path.join(__dirname, "source-data");
var fullpath = path.join(sourceDataFolder, path.basename(url));
fs.readFile(fullpath, "utf8", function(err, text) {
if (!err) return cb(null, text);
if (err.code != "ENOENT") return cb(err);
request(url, errTo(cb, function(res, text) {
fs.writeFile(fullpath, text, errTo(cb, function() {
cb(null, text);
}));
request(url, errTo(cb, function(res, buf) {
fs.mkdir(sourceDataFolder, function(err) {
if (err && err.code != "EEXIST") return cb(err);
fs.writeFile(fullpath, buf, errTo(cb, function() {
cb(null, buf.toString());
}));
});
}));
});
}
Expand Down

0 comments on commit 440aa82

Please sign in to comment.