-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
downloading fonts for offline use in the app
- Loading branch information
Showing
8 changed files
with
107 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,5 +38,5 @@ coverage/ | |
.nyc_output/ | ||
.raw-viewer-config.json | ||
temp/ | ||
third-party/exiftool/ | ||
third-party/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* eslint-disable no-console */ | ||
|
||
const { promisify } = require('util'); | ||
const stream = require('stream'); | ||
const pipeline = promisify(stream.pipeline); | ||
const path = require('path'); | ||
const fs = require('fs-extra'); | ||
const fetch = require('node-fetch'); | ||
|
||
const { fontsDir } = require('../lib/third-party.js'); | ||
|
||
const css = ` | ||
/* latin-ext */ | ||
@font-face { | ||
font-family: 'Roboto'; | ||
font-style: normal; | ||
font-weight: 400; | ||
src: url(KFOmCnqEu92Fr1Mu7GxKOzY.woff2) format('woff2'); | ||
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; | ||
} | ||
/* latin */ | ||
@font-face { | ||
font-family: 'Roboto'; | ||
font-style: normal; | ||
font-weight: 400; | ||
src: url(KFOmCnqEu92Fr1Mu4mxK.woff2) format('woff2'); | ||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; | ||
} | ||
/* latin */ | ||
@font-face { | ||
font-family: 'Roboto'; | ||
font-style: normal; | ||
font-weight: 700; | ||
font-display: swap; | ||
src: url(KFOlCnqEu92Fr1MmWUlfBBc4.woff2) format('woff2'); | ||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; | ||
} | ||
`; | ||
|
||
const fonts = { | ||
// roboto latin | ||
'KFOmCnqEu92Fr1Mu4mxK.woff2': 'https://fonts.gstatic.com/s/roboto/v19/KFOmCnqEu92Fr1Mu4mxK.woff2', | ||
// roboto latin-ext | ||
'KFOmCnqEu92Fr1Mu7GxKOzY.woff2': 'https://fonts.gstatic.com/s/roboto/v19/KFOmCnqEu92Fr1Mu7GxKOzY.woff2', | ||
// roboto latin bold | ||
'KFOlCnqEu92Fr1MmWUlfBBc4.woff2': 'https://fonts.gstatic.com/s/roboto/v19/KFOlCnqEu92Fr1MmWUlfBBc4.woff2' | ||
}; | ||
|
||
require('./lib.run.js')('fonts', async () => { | ||
await fs.ensureDir(fontsDir); | ||
await fs.outputFile(path.resolve(fontsDir, 'fonts.css'), css); | ||
|
||
for (let name in fonts) { | ||
const res = await fetch(fonts[name]); | ||
|
||
if (!res.ok) { | ||
throw new Error(`failed to fetch font "${name}": ${res.status} ${res.statusText}`); | ||
} | ||
|
||
await pipeline( | ||
res.body, | ||
fs.createWriteStream(path.join(fontsDir, name)) | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* eslint-disable no-console */ | ||
|
||
const chalk = require('chalk'); | ||
const figures = require('figures'); | ||
|
||
module.exports = (title, prom) => { | ||
const start = Date.now(); | ||
|
||
prom().then(() => { | ||
const end = Date.now(); | ||
console.log(`${chalk.green(figures.tick)} ${title} fetched successfully in ${end - start}ms`); | ||
}).catch(err => { | ||
const end = Date.now(); | ||
console.error(`${chalk.red(figures.cross)} error fetching ${title} in ${end - start}ms`); | ||
console.error(err); | ||
process.exitCode = 1; | ||
}); | ||
}; |