Skip to content

Commit

Permalink
refactor: adopt named import/export system
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Starting from version 10 stable, you should use webfont via named import, like this: `import { webfont } from "webfont"`.
  • Loading branch information
Jimmy Andrade committed Jan 25, 2021
1 parent 0cdd549 commit 31adbc7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
6 changes: 2 additions & 4 deletions src/cli.js
Original file line number Diff line number Diff line change
@@ -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(
`
Expand Down Expand Up @@ -375,7 +373,7 @@ Promise.resolve()
cli.showHelp();
}

return standalone(options).then((result) => {
return webfont(options).then((result) => {
result.config = Object.assign(
{},
{
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import standalone from "./standalone";
import { webfont } from "./standalone";

export default standalone;
export { webfont } from "./standalone";
export default webfont;
26 changes: 10 additions & 16 deletions src/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -37,7 +37,7 @@ async function buildConfig(options) {
return config;
}

function getGlyphsData(files, options) {
const getGlyphsData = (files, options) => {
const metadataProvider =
options.metadataProvider ||
defaultMetadataProvider({
Expand Down Expand Up @@ -111,7 +111,7 @@ function getGlyphsData(files, options) {
});
}

function toSvg(glyphsData, options) {
const toSvg = (glyphsData, options) => {
let result = "";

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -323,3 +315,5 @@ export default async function (initialOptions) {

return result;
}

export default webfont;

0 comments on commit 31adbc7

Please sign in to comment.