Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
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
20 changes: 18 additions & 2 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const fs = require('fs');
const path = require('path');
const fetch = require('isomorphic-fetch');
const sortby = require('lodash.sortby');
const request = require('sync-request');
const ora = require('ora');
const chalk = require('chalk');

const endpoint = 'https://www.cryptocompare.com/api/data/coinlist/';
const ghBaseUrl = 'https://raw.githubusercontent.com/crypti/cryptocurrencies/master/images';

const spinner = ora('Building currencies').start();
spinner.color = 'magenta';
Expand All @@ -23,14 +25,28 @@ fetch(endpoint)
*/
sorted.forEach((currency, index) => {
const {Name, CoinName, ImageUrl} = currency;
symbols[Name] = CoinName;
symbols[Name] = {
name: CoinName
};

// download the image for future use
if (ImageUrl) {
symbols[Name].imageUrl = `${ghBaseUrl}/${Name}.png`;

spinner.text = `${chalk.gray(index)} ${Name}`;
spinner.render();

const extension = ImageUrl.split('.').pop();
const ImageFile = `${Name}.${extension}`;
const ImagePath = path.join('images', ImageFile);

if (fs.existsSync(ImagePath)) {
Copy link
Copy Markdown
Member

@radiovisual radiovisual Jan 13, 2018

Choose a reason for hiding this comment

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

maybe we need to add a --force flag to the build then, because this checks for an existing image, but sometimes the icons change, and we will want a way to grab the updated images. We could get fancy with checksums, but it might be overkill.

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.

Yes that's what I was thinking, a force flag should be beneficial.

spinner.text = `${ImageFile} detected, skipping`;
return;
}

const res = request('get', `https://www.cryptocompare.com${ImageUrl}`);
fs.writeFileSync(`images/${Name}.${ImageUrl.split('.').pop()}`, res.getBody());
fs.writeFileSync(ImagePath, res.getBody());
imagesSaved += 1;
}
});
Expand Down
Loading