Skip to content

Commit 1b6956e

Browse files
committed
Make cache download windows friendly
1 parent c6dbe91 commit 1b6956e

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"cover": "babel-node node_modules/.bin/isparta cover --root src --report html node_modules/.bin/_mocha -- $npm_package_options_mocha",
4343
"coveralls": "babel-node node_modules/.bin/isparta cover --root src --report lcovonly node_modules/.bin/_mocha -- $npm_package_options_mocha && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
4444
"build": "npm run download && npm run build-public",
45-
"download": "sh scripts/download",
45+
"download": "babel-node src/api/cachedData/downloadCache.js src/api/cachedData/cache.json",
4646
"build-public": "scripts/build-public",
4747
"deploy": "scripts/build-public && scripts/deploy-public",
4848
"pretty": "node scripts/pretty.js",

scripts/download

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/api/cachedData/downloadCache.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-sync */
22

33
import { URL } from 'url';
4+
import { existsSync, writeFileSync } from 'fs';
45
import fetch from 'isomorphic-fetch';
56

67
/**
@@ -46,11 +47,24 @@ async function cacheResource(resourseName) {
4647
} while (url !== null);
4748
}
4849

49-
Promise.all(resources.map(cacheResource))
50-
.then(() => {
51-
console.log(JSON.stringify(cache, null, 2));
52-
})
53-
.catch(function(err) {
54-
console.error(err);
55-
});
50+
const outfile = process.argv[2];
51+
if (!outfile) {
52+
console.error('Missing ouput file!');
53+
process.exit(1);
54+
}
55+
56+
if (!existsSync(outfile)) {
57+
console.log('Downloading cache...');
58+
59+
Promise.all(resources.map(cacheResource))
60+
.then(() => {
61+
const data = JSON.stringify(cache, null, 2);
62+
writeFileSync(outfile, data, 'utf-8');
63+
console.log('Cached!');
64+
})
65+
.catch(function(err) {
66+
console.error(err);
67+
process.exit(1);
68+
});
69+
}
5670
/* eslint-enable no-console */

0 commit comments

Comments
 (0)