diff --git a/index.js b/index.js index 82c7008..c5758a9 100644 --- a/index.js +++ b/index.js @@ -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'); @@ -28,21 +27,16 @@ 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); @@ -50,33 +44,31 @@ async function main() { 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` }); }); } diff --git a/package.json b/package.json index b09c931..bf0dd31 100644 --- a/package.json +++ b/package.json @@ -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": {