Skip to content

Commit

Permalink
upgrade production deps to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
majodev committed Feb 4, 2023
1 parent 5f07206 commit 05251f0
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 199 deletions.
Binary file removed client/favicon.ico
Binary file not shown.
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@
"url": "https://github.com/majodev/google-webfonts-helper.git"
},
"dependencies": {
"archiver": "^1.3.0",
"async": "^0.9.0",
"compression": "^1.7.4",
"css": "^2.1.0",
"debug": "^2.2.0",
"ejs": "~0.8.4",
"express": "^4.18.2",
"lodash": "~2.4.1",
"mkdirp": "^0.5.0",
"morgan": "^1.10.0",
"serve-favicon": "~2.0.1",
"speakingurl": "^0.18.0"
"archiver": "5.3.1",
"async": "3.2.4",
"compression": "1.7.4",
"css": "3.0.0",
"debug": "4.3.4",
"ejs": "3.1.8",
"express": "4.18.2",
"lodash": "4.17.21",
"mkdirp": "2.1.3",
"morgan": "1.10.0",
"speakingurl": "14.0.1"
},
"devDependencies": {
"bower": "^1.3.8",
Expand Down
2 changes: 0 additions & 2 deletions server/config/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
'use strict';

var express = require('express');
var favicon = require('serve-favicon');
var morgan = require('morgan');
var compression = require('compression');
var path = require('path');
Expand All @@ -20,7 +19,6 @@ module.exports = function (app) {
app.use(compression());

if ('production' === env) {
app.use(favicon(path.join(config.root, 'public', 'favicon.ico')));
app.use(express.static(path.join(config.root, 'public')));
app.set('appPath', config.root + '/public');
app.use(morgan(':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length]'));
Expand Down
4 changes: 2 additions & 2 deletions server/logic/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function getFilterObject(font, subsetArr) {
});
} else {
_.each(font.subsets, function (subsetItem) {
filterObj[subsetItem] = _.contains(subsetArr, subsetItem);
filterObj[subsetItem] = _.includes(subsetArr, subsetItem);
});
}

Expand Down Expand Up @@ -288,7 +288,7 @@ function getFontFiles(fontItem, cb) {
_.mixin({
'findByValues': function (collection, property, values) {
return _.filter(collection, function (item) {
return _.contains(values, item[property]);
return _.includes(values, item[property]);
});
}
});
Expand Down
70 changes: 33 additions & 37 deletions server/logic/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,45 @@ function downloadFontFiles(fontItem, cb) {

var filePaths = [];

mkdirp(conf.CACHE_DIR, function(err) {
if (err) {
throw new Error("unable to create CACHE directory!" + err);
} else {
async.each(fontItem.variants, function(variantItem, variantCB) {
debug(_.keys(conf.USER_AGENTS));
async.each(_.keys(conf.USER_AGENTS), function(formatKey, typeCB) {
mkdirp.sync(conf.CACHE_DIR);

var filename = conf.CACHE_DIR + fontItem.id + "-" + fontItem.version + "-" + fontItem.storeID + "-" + variantItem.id + "." + formatKey;
async.each(fontItem.variants, function(variantItem, variantCB) {
debug(_.keys(conf.USER_AGENTS));
async.each(_.keys(conf.USER_AGENTS), function(formatKey, typeCB) {

if (!variantItem[formatKey]) {
// font format is not available for download...
console.warn(filename, "format not available for download", formatKey);
typeCB();
return;
}
var filename = conf.CACHE_DIR + fontItem.id + "-" + fontItem.version + "-" + fontItem.storeID + "-" + variantItem.id + "." + formatKey;

// download the file for type (filename now known)
downloadFile(variantItem[formatKey], filename, function() {
filePaths.push({
variant: variantItem.id, // variants and format are used to filter them out later!
format: formatKey,
path: filename
});
typeCB();
});
if (!variantItem[formatKey]) {
// font format is not available for download...
console.warn(filename, "format not available for download", formatKey);
typeCB();
return;
}

}, function(err) {
if (err) {
variantCB('variant failed: ' + variantItem.id + " err: " + err);
} else {
variantCB();
}
// download the file for type (filename now known)
downloadFile(variantItem[formatKey], filename, function() {
filePaths.push({
variant: variantItem.id, // variants and format are used to filter them out later!
format: formatKey,
path: filename
});
}, function(err) {
if (err) {
console.error("family failed: " + fontItem.id + " err: " + err);
throw new Error("family failed: " + fontItem.id + " err: " + err);
} else {
debug("family downloaded");
cb(filePaths);
}
typeCB();
});

}, function(err) {
if (err) {
variantCB('variant failed: ' + variantItem.id + " err: " + err);
} else {
variantCB();
}
});
}, function(err) {
if (err) {
console.error("family failed: " + fontItem.id + " err: " + err);
throw new Error("family failed: " + fontItem.id + " err: " + err);
} else {
debug("family downloaded");
cb(filePaths);
}
});

Expand Down
16 changes: 8 additions & 8 deletions server/logic/googleFontsAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var debug = require('debug')('gwfh:googleFontsAPI');

// build up fonts cache via google API...
var getFontsToDownload = _.once(function (googleAPIFontItems, cachedFonts, cb) {

var hostname = "www.googleapis.com";
var reqPath = '/webfonts/v1/webfonts?sort=popularity&key=';

Expand All @@ -20,22 +20,22 @@ var getFontsToDownload = _.once(function (googleAPIFontItems, cachedFonts, cb) {
headers: {
'Accept': 'application/json',
}
}, function(res) {
}, function (res) {

var output = '';

res.setEncoding('utf8');

res.on('data', function(chunk) {
res.on('data', function (chunk) {
output += chunk;
});

res.on('end', function() {
res.on('end', function () {

googleAPIFontItems = JSON.parse(output).items;

// populate our items
_.each(googleAPIFontItems, function(item, index) {
_.each(googleAPIFontItems, function (item, index) {

debug(index + " - " + item.family);

Expand All @@ -50,8 +50,8 @@ var getFontsToDownload = _.once(function (googleAPIFontItems, cachedFonts, cb) {
lastModified: item.lastModified,
popularity: index + 1,
// use latin per default, else first found font
defSubset: _.contains(item.subsets, 'latin') ? 'latin' : item.subsets[0],
defVariant: _.contains(item.variants, 'regular') ? 'regular' : item.variants[0]
defSubset: _.includes(item.subsets, 'latin') ? 'latin' : item.subsets[0],
defVariant: _.includes(item.variants, 'regular') ? 'regular' : item.variants[0]
});

});
Expand All @@ -62,7 +62,7 @@ var getFontsToDownload = _.once(function (googleAPIFontItems, cachedFonts, cb) {

});

req.on('error', function(e) {
req.on('error', function (e) {
console.error('Failed to load base google fonts list! Problem with request: ' + e.message + ' tried: ' + hostname + reqPath);
console.error(e);

Expand Down
6 changes: 3 additions & 3 deletions server/logic/subsetGen.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function getUniqueStoreID(uniqueCombArr) {
var storeID = '';
var lastItemIndex = uniqueCombArr.length - 1;

_.each(uniqueCombArr, function(uniqueItem, index) {
_.each(uniqueCombArr, function (uniqueItem, index) {
if (index < lastItemIndex) {
storeID += uniqueItem + "_";
} else {
Expand All @@ -53,8 +53,8 @@ function getDefaultSubsetObj(uniqueCombArr, inputArr) {
subsetMap: {}
};

_.each(inputArr, function(inputItem) {
urlStore.subsetMap[inputItem] = _.contains(uniqueCombArr, inputItem);
_.each(inputArr, function (inputItem) {
urlStore.subsetMap[inputItem] = _.includes(uniqueCombArr, inputItem);
});

return urlStore;
Expand Down
2 changes: 1 addition & 1 deletion server/logic/urlFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function fetchUrls(font, storeID, callback) {
id: variant
};

async.each(_.pairs(conf.USER_AGENTS), function(typeAgentPair, requestCB) {
async.each(_.toPairs(conf.USER_AGENTS), function(typeAgentPair, requestCB) {

cssFetcher(font.family + ":" + variant, cssSubsetString, typeAgentPair[0], typeAgentPair[1], function(err, resources) {
if (err) {
Expand Down
Loading

0 comments on commit 05251f0

Please sign in to comment.