Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// print all text
console.log('Converted words : ' + removeDupicateText(allText),'(' + wordCount(allText) + ')');
// convert file type
var fontmin = new Fontmin()
.src(fontsSource)
.use(Fontmin.glyph({
text: allText
}))
.use(ttf2woff2({
clone: true
})) // add woff2
.dest(outputPath)
.use(Fontmin.ttf2eot())
.use(Fontmin.ttf2woff({
deflate: true
}))
.use(Fontmin.ttf2svg());
imagemin([outputPath + '*.svg'], outputPath + 'optimize', {
use: [svgo()]
}).then(() => {
console.log('Convert finished'); // Finished
});
fontmin.run(function(err, files) {
if (err) {
throw err;
}
});
}
catch (err) {
return false;
}
};
if (src.length > 1 && !isFile(src[src.length - 1])) {
dest = src[src.length - 1];
src.pop();
}
// start fontmin
new Fontmin()
.src(src)
.use(Fontmin.svgs2ttf(fmOpts.fontFamily, fmOpts))
.use(Fontmin.ttf2eot(fmOpts))
.use(Fontmin.ttf2woff(fmOpts))
.use(Fontmin.ttf2svg(fmOpts))
.use(Fontmin.css(fmOpts))
.use(dump(fmOpts))
.dest(dest || 'output')
.run((err, files, stream) => {
if (err) {
log(err);
process.exit(1);
}
files.forEach(file => {
log(`created: ${file.path}`);
});
var fmOpts = extend({}, opts);
// for css font path
fmOpts.fontPath = ['.', opts.dest, ''].join('/');
// font css font family
fmOpts.fontFamily = font.name || font.basename;
var stream = storage.src(font.srcPath)
.pipe(Fontmin.glyph({
text: font.text
})())
.pipe(streamRename({
basename: font.hash
}))
.pipe(Fontmin.ttf2eot(fmOpts)())
.pipe(Fontmin.ttf2woff(fmOpts)())
.pipe(Fontmin.ttf2svg(fmOpts)())
.pipe(Fontmin.css(fmOpts)())
.pipe(storage.dest(opts.dest));
stream.on('error', callback);
stream.pipe(concat(callback.bind(null, null)));
}
export function generateFonts(done) {
const fontmin = new Fontmin()
.src(`${config.src}/styles/fonts/*.{ttf,otf}`)
.use(Fontmin.otf2ttf({
clone: true
}))
.use(Fontmin.ttf2eot({
clone: true
}))
.use(Fontmin.ttf2woff({
clone: true
}))
.use(Fontmin.ttf2svg({
clone: true
}))
.dest(`${config.dist}/styles/fonts`);
return fontmin.run((err) => {
if (err) {
console.log(err);
}
done();
});
export function generateFonts(done) {
const fontmin = new Fontmin()
.src(`${config.src}/styles/fonts/*.ttf`)
.use(Fontmin.ttf2eot({
clone: true
}))
.use(Fontmin.ttf2woff({
clone: true
}))
.use(Fontmin.ttf2svg({
clone: true
}))
.dest(`${config.dist}/styles/fonts`);
return fontmin.run(
function(err, files, stream) {
done();
if (err) {
console.log(err);
}
.then(function (hintedTtf) {
var input = fs.readFileSync(hintedTtf);
fs.writeFileSync('fonts/core-icons.woff2', ttf2woff2(input));
return Promise.all([
runFontminJob(new Fontmin().src(hintedTtf).dest(destPath).use(Fontmin.ttf2eot())),
runFontminJob(new Fontmin().src(hintedTtf).dest(destPath).use(Fontmin.ttf2woff()))
])
})
.catch(function (err) {
var text = opts.text || '';
if (text && opts.chineseOnly) {
text = text.replace(/[^\u4e00-\u9fa5]/g, '');
}
opts.text = text;
var fontmin = new Fontmin()
.src(file.contents)
.use(rename({
path: file.path
}))
.use(Fontmin.glyph(opts))
.use(Fontmin.ttf2eot())
.use(Fontmin.ttf2woff())
.use(Fontmin.ttf2svg())
.use(Fontmin.css(opts));
if (opts.use) {
opts.use.forEach(fontmin.use.bind(fontmin));
}
var fileStream = this;
fontmin.run(function (err, files) {
if (err) {
cb(new gutil.PluginError('gulp-fontmin:', err, {fileName: file.path}));
return;
}