Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix es modules #96

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ npm-debug.log
/node_modules
fonts/dest*
/coverage
/.nyc_output
59 changes: 29 additions & 30 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,35 @@

'use strict';

var fs = require('fs');
var meow = require('meow');
var path = require('path');
var stdin = require('get-stdin');
var Fontmin = require('./');
var _ = require('lodash');

var cli = meow({
help: [
'Usage',
' $ fontmin <file> [<output>]',
' $ fontmin <directory> [<output>]',
' $ fontmin <file> > <output>',
' $ cat <file> | fontmin > <output>',
'',
'Example',
' $ fontmin fonts/* build',
' $ fontmin fonts build',
' $ fontmin foo.ttf > foo-optimized.ttf',
' $ cat foo.ttf | fontmin > foo-optimized.ttf',
'',
'Options',
' -t, --text require glyphs by text',
' -b, --basic-text require glyphs with base chars',
' -d, --deflate-woff deflate woff',
' --font-family font-family for @font-face CSS',
' --css-glyph generate class for each glyf. default = false',
' -T, --show-time show time fontmin cost'
].join('\n')
}, {
import fs from 'fs';
import meow from 'meow';
import path from 'path';
import stdin from 'get-stdin';
import Fontmin from './index.js';
import _ from 'lodash';

var cli = meow([
'Usage',
' $ fontmin <file> [<output>]',
' $ fontmin <directory> [<output>]',
' $ fontmin <file> > <output>',
' $ cat <file> | fontmin > <output>',
'',
'Example',
' $ fontmin fonts/* build',
' $ fontmin fonts build',
' $ fontmin foo.ttf > foo-optimized.ttf',
' $ cat foo.ttf | fontmin > foo-optimized.ttf',
'',
'Options',
' -t, --text require glyphs by text',
' -b, --basic-text require glyphs with base chars',
' -d, --deflate-woff deflate woff',
' --font-family font-family for @font-face CSS',
' --css-glyph generate class for each glyf. default = false',
' -T, --show-time show time fontmin cost'
].join('\n'), {
importMeta: import.meta,
'boolean': [
'basic-text',
'show-time',
Expand Down
46 changes: 32 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@

/* eslint-env node */

var combine = require('stream-combiner');
var concat = require('concat-stream');
var EventEmitter = require('events').EventEmitter;
var inherits = require('util').inherits;
var bufferToVinyl = require('buffer-to-vinyl');
var vfs = require('vinyl-fs');
import combine from 'stream-combiner';
import concat from 'concat-stream';
import { EventEmitter } from 'events';
import { inherits } from 'util';
import bufferToVinyl from 'buffer-to-vinyl';
import vfs from 'vinyl-fs';
import util from './lib/util.js';
import mime from './lib/mime-types.js';

import pluginGlyph from './plugins/glyph.js';
import pluginTtf2eot from './plugins/ttf2eot.js';
import pluginTtf2woff from './plugins/ttf2woff.js';
import pluginTtf2woff2 from './plugins/ttf2woff2.js';
import pluginTtf2svg from './plugins/ttf2svg.js';
import pluginCss from './plugins/css.js';
import pluginSvg2ttf from './plugins/svg2ttf.js';
import pluginSvgs2ttf from './plugins/svgs2ttf.js';
import pluginOtf2ttf from './plugins/otf2ttf.js';

/**
* Initialize Fontmin
Expand Down Expand Up @@ -155,15 +167,21 @@ Fontmin.plugins = [
];

// export pkged plugins
Fontmin.plugins.forEach(function (plugin) {
Fontmin[plugin] = require('./plugins/' + plugin);
});
Fontmin.glyph = pluginGlyph;
Fontmin.ttf2eot = pluginTtf2eot;
Fontmin.ttf2woff = pluginTtf2woff;
Fontmin.ttf2woff2 = pluginTtf2woff2;
Fontmin.ttf2svg = pluginTtf2svg;
Fontmin.css = pluginCss;
Fontmin.svg2ttf = pluginSvg2ttf;
Fontmin.svgs2ttf = pluginSvgs2ttf;
Fontmin.otf2ttf = pluginOtf2ttf;

// exports util, mime
Fontmin.util = util;
Fontmin.mime = mime;

/**
* Module exports
*/
module.exports = Fontmin;

// exports util, mime
module.exports.util = exports.util = require('./lib/util');
module.exports.mime = exports.mime = require('./lib/mime-types');
export default Fontmin;
2 changes: 1 addition & 1 deletion lib/mime-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* eslint-env node */

module.exports = exports = {
export default {
'.*': 'application/octet-stream',
'ttf': 'application/font-sfnt',
'otf': 'application/font-sfnt',
Expand Down
15 changes: 5 additions & 10 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

/* eslint-env node */

var fs = require('fs');
var path = require('path');
var _ = require('lodash');
var codePoints = require('code-points');
import fs from 'fs';
import path from 'path';
import _ from 'lodash';
import codePoints from 'code-points';

/**
* getFontFolder
Expand Down Expand Up @@ -122,9 +122,4 @@ function string2unicodes(str) {
return _.uniq(codePoints(str));
}

exports.getFontFolder = getFontFolder;
exports.getFonts = getFonts;
exports.getPureText = getPureText;
exports.getUniqText = getUniqText;
exports.getSubsetText = getSubsetText;
exports.string2unicodes = string2unicodes;
export default { getFontFolder, getFonts, getPureText, getUniqText, getSubsetText, string2unicodes };
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.9.9",
"description": "Minify font seamlessly, font subsetter, webfont (eot, woff, svg) converter.",
"main": "index.js",
"type": "module",
"keywords": [
"font",
"webfont",
Expand Down Expand Up @@ -64,7 +65,7 @@
"is-eot": "^1.0.0",
"is-woff": "^1.0.1",
"is-woff2": "^1.0.0",
"mocha": "^9.1.1",
"mocha": "^9.1.3",
"nyc": "^15.1.0"
}
}
21 changes: 12 additions & 9 deletions plugins/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
*/

/* eslint-env node */
var _ = require('lodash');
var fs = require('fs');
var path = require('path');
var isTtf = require('is-ttf');
var through = require('through2');
var replaceExt = require('replace-ext');
var b2a = require('b3b').b2a;

import _ from 'lodash';
import fs from 'fs';
import path from 'path';
import isTtf from 'is-ttf';
import through from 'through2';
import replaceExt from 'replace-ext';
import { b2a } from 'b3b';

var dirname = path.dirname((new URL(import.meta.url)).pathname);

/**
* tpl
*
* @type {string}
*/
var tpl = fs.readFileSync(
path.resolve(__dirname, '../lib/font-face.tpl')
path.resolve(dirname, '../lib/font-face.tpl')
).toString('utf-8');

/**
Expand Down Expand Up @@ -112,7 +115,7 @@ function getFontFamily(fontInfo, ttf, opts) {
* @return {Object} stream.Transform instance
* @api public
*/
module.exports = function (opts) {
export default function (opts) {
opts = opts || {};

return through.ctor({
Expand Down
19 changes: 9 additions & 10 deletions plugins/glyph.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

/* eslint-env node */

var _ = require('lodash');
var isTtf = require('is-ttf');
var through = require('through2');
var TTF = require('fonteditor-core').TTF;
var TTFReader = require('fonteditor-core').TTFReader;
var TTFWriter = require('fonteditor-core').TTFWriter;
var b2ab = require('b3b').b2ab;
var ab2b = require('b3b').ab2b;
var util = require('../lib/util');
import _ from 'lodash';
import isTtf from 'is-ttf';
import through from 'through2';
import fonteditorCore from 'fonteditor-core';
import { b2ab, ab2b } from 'b3b';
import util from '../lib/util.js';

const { TTF, TTFReader, TTFWriter } = fonteditorCore;

/**
* getSubsetGlyfs
Expand Down Expand Up @@ -116,7 +115,7 @@ function minifyTtf(contents, opts) {
* @return {Object} stream.Transform instance
* @api public
*/
module.exports = function (opts) {
export default function (opts) {

opts = _.extend({hinting: true, trim: true}, opts);

Expand Down
20 changes: 10 additions & 10 deletions plugins/otf2ttf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

/* eslint-env node */

var isOtf = require('is-otf');
var through = require('through2');
var otf2ttfobject = require('fonteditor-core').otf2ttfobject;
var TTFWriter = require('fonteditor-core').TTFWriter;
var b2ab = require('b3b').b2ab;
var ab2b = require('b3b').ab2b;
var replaceExt = require('replace-ext');
var _ = require('lodash');
var util = require('../lib/util');
import isOtf from 'is-otf';
import through from 'through2';
import fonteditorCore from 'fonteditor-core';
import { b2ab, ab2b } from 'b3b';
import replaceExt from 'replace-ext';
import _ from 'lodash';
import util from '../lib/util.js';

const { otf2ttfobject, TTFWriter } = fonteditorCore;

/**
* otf2ttf fontmin plugin
Expand All @@ -22,7 +22,7 @@ var util = require('../lib/util');
* @return {Object} stream.Transform instance
* @api public
*/
module.exports = function (opts) {
export default function (opts) {

opts = _.extend({clone: false, hinting: true}, opts);

Expand Down
17 changes: 9 additions & 8 deletions plugins/svg2ttf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

/* eslint-env node */

var isSvg = require('is-svg');
var through = require('through2');
var TTFWriter = require('fonteditor-core').TTFWriter;
var svg2ttfobject = require('fonteditor-core').svg2ttfobject;
var ab2b = require('b3b').ab2b;
var replaceExt = require('replace-ext');
var _ = require('lodash');
import isSvg from 'is-svg';
import through from 'through2';
import { ab2b } from 'b3b';
import replaceExt from 'replace-ext';
import _ from 'lodash';
import fonteditorCore from 'fonteditor-core';

const { TTFWriter, svg2ttfobject } = fonteditorCore;

/**
* svg2ttf fontmin plugin
Expand All @@ -20,7 +21,7 @@ var _ = require('lodash');
* @return {Object} stream.Transform instance
* @api public
*/
module.exports = function (opts) {
export default function (opts) {

opts = _.extend({clone: true, hinting: true}, opts);

Expand Down
27 changes: 14 additions & 13 deletions plugins/svgs2ttf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@

/* eslint-env node */

var isSvg = require('is-svg');
var through = require('through2');
var path = require('path');
var replaceExt = require('replace-ext');
var ab2b = require('b3b').ab2b;
var _ = require('lodash');
var bufferToVinyl = require('buffer-to-vinyl');
var TTFWriter = require('fonteditor-core').TTFWriter;
var TTF = require('fonteditor-core').TTF;
var svg2ttfobject = require('fonteditor-core').svg2ttfobject;
var getEmptyttfObject = require('fonteditor-core/lib/ttf/getEmptyttfObject').default;
import isSvg from 'is-svg';
import through from 'through2';
import path from 'path';
import replaceExt from 'replace-ext';
import { ab2b } from 'b3b';
import _ from 'lodash';
import bufferToVinyl from 'buffer-to-vinyl';
import fonteditorCore from 'fonteditor-core';
import getEmptyttfObject from 'fonteditor-core/lib/ttf/getEmptyttfObject.js';

const getEmpty = getEmptyttfObject.default;
const { TTFWriter, TTF, svg2ttfobject } = fonteditorCore;

/**
* SvgFont
Expand Down Expand Up @@ -45,7 +46,7 @@ function SvgFont(name, opts) {
);

// empty ttfobj
var ttfobj = getEmptyttfObject();
var ttfobj = getEmpty();

// for save name
ttfobj.post.format = 2;
Expand Down Expand Up @@ -120,7 +121,7 @@ SvgFont.prototype.compile = function () {
* @return {Object} stream.Transform instance
* @api public
*/
module.exports = function (file, opts) {
export default function (file, opts) {

if (!file) {
throw new Error('Missing file option for fontmin-svg2ttf');
Expand Down
Loading