From a4a08e34bd69abe9de89ea6d0f4d52c8616cb8a0 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Wed, 17 Apr 2019 08:38:54 -0700 Subject: [PATCH] Fix fatal error when building without a the_noun_project.auth file (re: #6193) --- build_data.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/build_data.js b/build_data.js index dac77d01a..bb993a125 100644 --- a/build_data.js +++ b/build_data.js @@ -21,15 +21,6 @@ const far = require('@fortawesome/free-regular-svg-icons').far; const fab = require('@fortawesome/free-brands-svg-icons').fab; fontawesome.library.add(fas, far, fab); -/* - * The Noun Project doesn't allow anonymous API access. New "tnp-" icons will - * not be downloaded without a the_noun_project.auth file with a json object: - * { - * "consumer_key": "xxxxxx", - * "consumer_secret": "xxxxxx" - * } - * */ -const nounAuth = JSON.parse(fs.readFileSync('./the_noun_project.auth', 'utf8')); const request = require('request').defaults({ maxSockets: 1 }); module.exports = function buildData() { @@ -685,6 +676,18 @@ function writeFaIcons(faIcons) { function writeTnpIcons(tnpIcons) { + /* + * The Noun Project doesn't allow anonymous API access. New "tnp-" icons will + * not be downloaded without a "the_noun_project.auth" file with a json object: + * { + * "consumer_key": "xxxxxx", + * "consumer_secret": "xxxxxx" + * } + * */ + var nounAuth; + if (fs.existsSync('./the_noun_project.auth')) { + nounAuth = JSON.parse(fs.readFileSync('./the_noun_project.auth', 'utf8')); + } var baseURL = 'http://api.thenounproject.com/icon/'; for (var key in tnpIcons) { var id = key.substring(4); @@ -694,7 +697,7 @@ function writeTnpIcons(tnpIcons) { if (fs.existsSync(localPath)) continue; if (!nounAuth) { - console.error('No authentication file found for The Noun Project with which to download the icon with id: ' + key); + console.error('No authentication file for The Noun Project. Cannot download icon: ' + key); return; }