Skip to content

Commit

Permalink
Fixed icon breaking iisues
Browse files Browse the repository at this point in the history
If not all versions are loaded then some icons fail to load. Now downloads all versions
  • Loading branch information
jonbarrow committed Jun 15, 2019
1 parent 0e03fd1 commit f148b54
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
44 changes: 18 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const url = require('url');
const path = require('path');
const fs = require("fs");
const got = require('got');
const prompts = require('prompts');
const Spinnies = require('spinnies');
const AdmZip = require('adm-zip');
const async = require('async');
Expand All @@ -28,55 +27,48 @@ main();
async function main() {
spinnies.add('loading-versions', { text: 'Loading Font Awesome 5 versions' });
const versions = await getFA5Versions();
const latestVersion = versions[0];
spinnies.succeed('loading-versions', { text: 'Loaded Font Awesome 5 versions' });
if (!versions || !versions[0]) {
spinnies.fail('loading-versions', { text: 'Failed to load Font Awesome 5 versions' });
return;
}

const {version} = await prompts([
{
type: 'select',
name: 'version',
message: 'Select a version',
choices: versions.map(version => ({ title: `v${version}`, value: version })),
}
]);
spinnies.succeed('loading-versions', { text: 'Loaded Font Awesome 5 versions' });

if (!version) return;
const latestVersion = versions[0];

spinnies.add('ripping-start', { text: `Ripping FA5 v${version}` });
spinnies.add('ripping-start', { text: `Ripping FA5 v${latestVersion}` });

const zip = new AdmZip();
const css = await got.get(`${FA_PRO_ASSET_BASE}/releases/v${latestVersion}/css/pro.min.css`, GOT_OPTIONS);
GOT_OPTIONS.headers.Referer = `${FA_PRO_ASSET_BASE}/releases/v${latestVersion}/css/pro.min.css`;
GOT_OPTIONS.encoding = null;

const fontUrls = css.body
.match(fontUrlRegex).map(url => url.replace('url(', '').replace(')', '').replace('../../..', FA_PRO_ASSET_BASE))
.filter(url => url.includes(version));
.match(fontUrlRegex).map(url => url.replace('url(', '').replace(')', '').replace('../../..', FA_PRO_ASSET_BASE));;

const cssFile = css.body
.replace(/https:\/\/kit-free.fontawesome.com\/algo\/1/g, '..')
.replace(/..\/..\/..\/algo\/1/g, '..')
.replace(/webfonts/g, 'fonts');

const cssFile = css.body.replace(/https:\/\/kit-free.fontawesome.com\/algo\/1/g, '..').replace(/..\/..\/..\/algo\/1/g, '..');
zip.addFile('css/all.css', Buffer.from(cssFile));

async.each(fontUrls, (fontUrl, callback) => {

const fileName = path.basename(url.parse(fontUrl).pathname);
spinnies.add(fontUrl, { text: `Downloading ${fileName} from ${fontUrl}` });

got(fontUrl, GOT_OPTIONS)
.then(response => {;
const data = response.body;

zip.addFile(`fonts/${fileName}`, data);

spinnies.succeed(fontUrl, { text: `Added file ${fileName} to zip` });
.then(response => {
zip.addFile(`fonts/${fileName}`, response.body);

callback();
})
.catch(() => {
spinnies.fail(fontUrl, { text: `Failed to add file ${fileName} to zip!` })
callback();
});
}, () => {
fs.writeFileSync(`${__dirname}/fa5-v${version}.zip`, zip.toBuffer());
spinnies.succeed('ripping-start', { text: `Ripped FA5 v${version}. Saved to ${__dirname}/fa5-v${version}.zip` });
fs.writeFileSync(`${__dirname}/fa5-v${latestVersion}.zip`, zip.toBuffer());
spinnies.succeed('ripping-start', { text: `Ripped FA5 v${latestVersion}. Saved to ${__dirname}/fa5-v${latestVersion}.zip` });
});
}

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"adm-zip": "^0.4.11",
"async": "^3.0.1",
"got": "^9.0.0",
"prompts": "^2.1.0",
"spinnies": "git+https://github.com/RedDuckss/spinnies.git"
},
"devDependencies": {
Expand Down

0 comments on commit f148b54

Please sign in to comment.