Skip to content

Commit

Permalink
Merge pull request #122 from andersk/upgrade
Browse files Browse the repository at this point in the history
Upgrade dependencies
  • Loading branch information
kekee000 authored Nov 22, 2024
2 parents 21807ca + ad2941d commit 9bd9b08
Show file tree
Hide file tree
Showing 20 changed files with 212 additions and 230 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ npm-debug.log
node_modules
fonts/dest*
/coverage
.nyc_output
package-lock.json
test/ts/example.js
51 changes: 16 additions & 35 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@

/* eslint-env node */

'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');
import * as fs from 'fs';
import meow from 'meow';
import * as path from 'path';
import stdin from 'get-stdin';
import Fontmin from './index.js';
import _ from 'lodash';

var cli = meow({
importMeta: import.meta,
help: [
'Usage',
' $ fontmin <file> [<output>]',
Expand All @@ -37,35 +36,17 @@ var cli = meow({
' --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')
}, {
'boolean': [
'basic-text',
'show-time',
'deflate-woff',
'css-glyph',
'version'
],
'string': [
'text',
'font-family'
],
'alias': {
t: 'text',
b: 'basic-text',
d: 'deflate-woff',
T: 'show-time',
h: 'help',
v: 'version'
}
].join('\n'),
flags: {
basicText: { type: 'boolean', shortFlag: 'b' },
showTime: { type: 'boolean', shortFlag: 'T' },
deflateWoff: { type: 'boolean', shortFlag: 'd' },
cssGlyph: { type: 'boolean' },
text: { type: 'string', shortFlag: 't' },
fontFamily: { type: 'string' },
},
});

// version
if (cli.flags.version) {
console.log(require('./package.json').version);
process.exit(0);
}

function isFile(path) {
if (/^[^\s]+\.\w*$/.test(path)) {
return true;
Expand Down
49 changes: 34 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@

/* 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 * as bufferToVinyl from 'buffer-to-vinyl';
import vfs from 'vinyl-fs';

import * as util from './lib/util.js';
import mime from './lib/mime-types.js';

import glyph from './plugins/glyph.js';
import ttf2eot from './plugins/ttf2eot.js';
import ttf2woff from './plugins/ttf2woff.js';
import ttf2woff2 from './plugins/ttf2woff2.js';
import ttf2svg from './plugins/ttf2svg.js';
import css from './plugins/css.js';
import svg2ttf from './plugins/svg2ttf.js';
import svgs2ttf from './plugins/svgs2ttf.js';
import otf2ttf from './plugins/otf2ttf.js';

/**
* Initialize Fontmin
Expand Down Expand Up @@ -150,7 +163,8 @@ Fontmin.prototype.getFiles = function () {
return bufferToVinyl.stream(this._src[0]);
}

return vfs.src.apply(vfs, this.src());
var [src, options] = this.src();
return vfs.src(src, {encoding: false, ...options});
};

/**
Expand All @@ -171,16 +185,21 @@ Fontmin.plugins = [
];

// export pkged plugins
Fontmin.plugins.forEach(function (plugin) {
Fontmin[plugin] = require('./plugins/' + plugin);
});
Fontmin.glyph = glyph;
Fontmin.ttf2eot = ttf2eot;
Fontmin.ttf2woff = ttf2woff;
Fontmin.ttf2woff2 = ttf2woff2;
Fontmin.ttf2svg = ttf2svg;
Fontmin.css = css;
Fontmin.svg2ttf = svg2ttf;
Fontmin.svgs2ttf = svgs2ttf;
Fontmin.otf2ttf = otf2ttf;

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

// exports util, mime
module.exports.default = Fontmin;
module.exports.util = exports.util = require('./lib/util');
module.exports.mime = exports.mime = require('./lib/mime-types');
export { util, mime };
export default Fontmin;
Fontmin.util = util;
Fontmin.mime = mime;
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
27 changes: 10 additions & 17 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

/* eslint-env node */

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

/**
* getFontFolder
*
* @return {string} fontFolder
*/
function getFontFolder() {
export function getFontFolder() {
return path.resolve({
win32: '/Windows/fonts',
darwin: '/Library/Fonts',
Expand All @@ -29,7 +29,7 @@ function getFontFolder() {
* @param {string} path path
* @return {Array} fonts
*/
function getFonts() {
export function getFonts() {
return fs.readdirSync(getFontFolder());
}

Expand All @@ -42,7 +42,7 @@ function getFonts() {
* @param {string} str target text
* @return {string} pure text
*/
function getPureText(str) {
export function getPureText(str) {

// fix space
var emptyTextMap = {};
Expand Down Expand Up @@ -77,7 +77,7 @@ function getPureText(str) {
* @param {string} str target text
* @return {string} uniq text
*/
function getUniqText(str) {
export function getUniqText(str) {
return _.uniq(
str.split('')
).join('');
Expand All @@ -99,7 +99,7 @@ var basicText = String.fromCharCode.apply(this, _.range(33, 126));
* @param {Object} opts opts
* @return {string} subset text
*/
function getSubsetText(opts) {
export function getSubsetText(opts) {

var text = opts.text || '';

Expand All @@ -118,13 +118,6 @@ function getSubsetText(opts) {
* @param {string} str string
* @return {Array} unicodes
*/
function string2unicodes(str) {
export 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;
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "fontmin",
"version": "1.1.0",
"description": "Minify font seamlessly, font subsetter, webfont (eot, woff, svg) converter.",
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"keywords": [
Expand Down Expand Up @@ -31,47 +32,47 @@
"license": "MIT",
"repository": "ecomfe/fontmin",
"engines": {
"node": ">=12"
"node": ">=18"
},
"bin": {
"fontmin": "cli.js"
},
"scripts": {
"test": "mocha test/*.spec.js",
"coverage": "nyc mocha --reporter spec --check-leaks test/*.spec.js"
"coverage": "c8 mocha --reporter spec --check-leaks test/*.spec.js"
},
"exports": {
"require": "./index.js",
"import": "./index.js"
},
"dependencies": {
"@types/node": "^12.20.55",
"@types/node": "*",
"@types/through2": "^2.0.38",
"b3b": "^0.0.1",
"buffer-to-vinyl": "^1.0.0",
"code-points": "^2.0.0-1",
"concat-stream": "^2.0.0",
"fonteditor-core": "^2.4.0",
"get-stdin": "^8.0.0",
"get-stdin": "^9.0.0",
"is-otf": "^0.1.2",
"is-svg": "^4.2.1",
"is-svg": "^5.1.0",
"is-ttf": "^0.2.2",
"lodash": "^4.17.10",
"meow": "^9.0.0",
"meow": "^13.2.0",
"pako": "^2.0.3",
"replace-ext": "^2.0.0",
"stream-combiner": "^0.2.1",
"through2": "^4.0.2",
"ttf2woff2": "^4.0.1",
"vinyl-fs": "^3.0.3"
"ttf2woff2": "^6.0.1",
"vinyl-fs": "^4.0.0"
},
"devDependencies": {
"chai": "^4.1.2",
"c8": "^10.1.2",
"chai": "^5.1.2",
"gulp-clean": "^0.4.0",
"is-eot": "^1.0.0",
"is-woff": "^1.0.1",
"is-woff2": "^1.0.0",
"mocha": "^9.1.1",
"nyc": "^15.1.0"
"mocha": "^10.8.2"
}
}
19 changes: 10 additions & 9 deletions plugins/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
*/

/* 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 * as fs from 'fs';
import * as path from 'path';
import * as url from 'url';
import isTtf from 'is-ttf';
import through from 'through2';
import replaceExt from 'replace-ext';
import { b2a } from 'b3b';

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

/**
Expand Down Expand Up @@ -112,7 +113,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
23 changes: 10 additions & 13 deletions plugins/glyph.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@

/* 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 * as util from '../lib/util.js';

/**
* getSubsetGlyfs
Expand Down Expand Up @@ -56,7 +53,7 @@ function minifyFontObject(ttfObject, subset, plugin) {
}

// new TTF Object
var ttf = new TTF(ttfObject);
var ttf = new fonteditorCore.TTF(ttfObject);

// get target glyfs then set
ttf.setGlyf(getSubsetGlyfs(ttf, subset));
Expand Down Expand Up @@ -84,7 +81,7 @@ function minifyTtf(contents, opts) {
var ttfobj = contents;

if (Buffer.isBuffer(contents)) {
ttfobj = new TTFReader(opts).read(b2ab(contents));
ttfobj = new fonteditorCore.TTFReader(opts).read(b2ab(contents));
}

var miniObj = minifyFontObject(
Expand All @@ -94,7 +91,7 @@ function minifyTtf(contents, opts) {
);

var ttfBuffer = ab2b(
new TTFWriter(Object.assign({writeZeroContoursGlyfData: true}, opts)).write(miniObj)
new fonteditorCore.TTFWriter(Object.assign({writeZeroContoursGlyfData: true}, opts)).write(miniObj)
);

return {
Expand All @@ -116,7 +113,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
Loading

0 comments on commit 9bd9b08

Please sign in to comment.