UNPKG

google-fonts-plugin

Version:

Webpack plugin that downloads fonts from Google Fonts and encodes them to base64.

34 lines 1.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const crypto_1 = require("crypto"); const fs_1 = require("fs"); const Plugin_1 = require("../Plugin/Plugin"); const findCacheDir = require("find-cache-dir"); class Cache { } exports.default = Cache; Cache.get = (key, encoding) => { const thunk = findCacheDir({ name: Plugin_1.default.getPluginName(), thunk: true }); if (!thunk || !fs_1.existsSync(thunk(key))) { return ''; } return fs_1.readFileSync(thunk(key), encoding); }; Cache.key = (requestUrl, format) => `${format}-${crypto_1.createHash('sha1') .update(requestUrl) .digest('hex')}`; Cache.save = (key, contents, encoding) => { const thunk = findCacheDir({ name: Plugin_1.default.getPluginName(), create: true, thunk: true }); if (!thunk) { return; } return fs_1.writeFileSync(thunk(key), contents, encoding); }; //# sourceMappingURL=Cache.js.map