From 31adbc7faa974c3d5a1ba9ffd4a5944bcab4fae8 Mon Sep 17 00:00:00 2001 From: Jimmy Andrade Date: Mon, 25 Jan 2021 16:54:47 -0300 Subject: [PATCH] refactor: adopt named import/export system BREAKING CHANGE: Starting from version 10 stable, you should use webfont via named import, like this: `import { webfont } from "webfont"`. --- src/cli.js | 6 ++---- src/index.js | 5 +++-- src/standalone.js | 26 ++++++++++---------------- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/cli.js b/src/cli.js index e160dfce..83eb76b9 100755 --- a/src/cli.js +++ b/src/cli.js @@ -1,10 +1,8 @@ -#!/usr/bin/env node - import path from "path"; import fs from "fs"; import meow from "meow"; import resolveFrom from "resolve-from"; -import standalone from "./standalone"; +import { webfont } from "./standalone"; const cli = meow( ` @@ -375,7 +373,7 @@ Promise.resolve() cli.showHelp(); } - return standalone(options).then((result) => { + return webfont(options).then((result) => { result.config = Object.assign( {}, { diff --git a/src/index.js b/src/index.js index e74f969e..33b86926 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,4 @@ -import standalone from "./standalone"; +import { webfont } from "./standalone"; -export default standalone; +export { webfont } from "./standalone"; +export default webfont; diff --git a/src/standalone.js b/src/standalone.js index c2fa77ca..bb010a5c 100644 --- a/src/standalone.js +++ b/src/standalone.js @@ -16,7 +16,7 @@ import ttf2woff from "ttf2woff"; import wawoff2 from "wawoff2"; import xml2js from "xml2js"; -async function buildConfig(options) { +const buildConfig = async (options) => { let searchPath = process.cwd(); let configPath = null; @@ -37,7 +37,7 @@ async function buildConfig(options) { return config; } -function getGlyphsData(files, options) { +const getGlyphsData = (files, options) => { const metadataProvider = options.metadataProvider || defaultMetadataProvider({ @@ -111,7 +111,7 @@ function getGlyphsData(files, options) { }); } -function toSvg(glyphsData, options) { +const toSvg = (glyphsData, options) => { let result = ""; return new Promise((resolve, reject) => { @@ -152,23 +152,15 @@ function toSvg(glyphsData, options) { }); } -function toTtf(buffer, options) { - return Buffer.from(svg2ttf(buffer, options).buffer); -} +const toTtf = (buffer, options) => Buffer.from(svg2ttf(buffer, options).buffer) -function toEot(buffer) { - return Buffer.from(ttf2eot(buffer).buffer); -} +const toEot = (buffer) => Buffer.from(ttf2eot(buffer).buffer) -function toWoff(buffer, options) { - return Buffer.from(ttf2woff(buffer, options).buffer); -} +const toWoff = (buffer, options) => Buffer.from(ttf2woff(buffer, options).buffer) -function toWoff2(buffer) { - return wawoff2.compress(buffer); -} +const toWoff2 = (buffer) => wawoff2.compress(buffer) -export default async function (initialOptions) { +export const webfont = async (initialOptions) => { if (!initialOptions || !initialOptions.files) { throw new Error("You must pass webfont a `files` glob"); } @@ -323,3 +315,5 @@ export default async function (initialOptions) { return result; } + +export default webfont;