tasks/fontmin.js
function taskFontmin() {
    // prase options
    let opts    = this.options()
    let data    = this.data
    let destdir = opts.dest    || './'
    let basedir = opts.basedir || './'
    let src     = grunt.file.expand(data.src)
    let fonts   = grunt.file.expand(join(basedir, this.target))
    let getText = opts.getText!==undefined ? opts.getText : (content)=>html2text.fromString(content)
    let type='woff', typeOpts=true

    // check if more than one output option is specified
    if ( !atMostDefined(data, 1, 'woff', 'css') )
        throw new Error('Multiple output type defined!')

    // set type, typeOpts
    if (data.woff!==undefined) { type='woff' }
    if (data.css!==undefined)  { type='css'; typeOpts=data.css }

    // string of unique characters(glyphs) to be included in minimized font
    let uniqGlyphs =
        src.map( path => grunt.file.read(path) )
           .map( getText )
           .join()
           .split('')
           .sort().reduce( nodup(), [] )   // remove duplicate characters
           .join('')


    fonts.forEach( path => {
        // create output ArrayBuffer
        let ttf = readToTTF(path)
        let stripped = glyphStrip(ttf, uniqGlyphs)
        let output = ttfToOutput(stripped, type, typeOpts)

        // solve dest path, write output
        let destPath = join(destdir, getOutputFilename(path,type))
        grunt.file.write(destPath, toBuffer(output))

        // output information
        grunt.log.writeln(basename(path)+' => '+type+' '
            +chalk.green(stripped.glyf.length)+' glyphs, '
            +chalk.green(output.byteLength)+' bytes')
    } )

}
function taskFontmin() {
    // prase options
    let opts    = this.options()
    let data    = this.data
    let destdir = opts.dest    || './'
    let basedir = opts.basedir || './'
    let src     = grunt.file.expand(data.src)
    let fonts   = grunt.file.expand(join(basedir, this.target))
    let getText = opts.getText!==undefined ? opts.getText : (content)=>html2text.fromString(content)
    let type='woff', typeOpts=true

    // check if more than one output option is specified
    if ( !atMostDefined(data, 1, 'woff', 'css') )
        throw new Error('Multiple output type defined!')

    // set type, typeOpts
    if (data.woff!==undefined) { type='woff' }
    if (data.css!==undefined)  { type='css'; typeOpts=data.css }

    // string of unique characters(glyphs) to be included in minimized font
    let uniqGlyphs =
        src.map( path => grunt.file.read(path) )
           .map( getText )
           .join()
           .split('')
           .sort().reduce( nodup(), [] )   // remove duplicate characters
           .join('')


    fonts.forEach( path => {
        // create output ArrayBuffer
        let ttf = readToTTF(path)
        let stripped = glyphStrip(ttf, uniqGlyphs)
        let output = ttfToOutput(stripped, type, typeOpts)

        // solve dest path, write output
        let destPath = join(destdir, getOutputFilename(path,type))
        grunt.file.write(destPath, toBuffer(output))

        // output information
        grunt.log.writeln(basename(path)+' => '+type+' '
            +chalk.green(stripped.glyf.length)+' glyphs, '
            +chalk.green(output.byteLength)+' bytes')
    } )

}
function taskFontmin ( ) { // prase options let opts = this . options ( ) let data = this . data let destdir = opts . dest || './' let basedir = opts . basedir || './' let src = grunt . file . expand ( data . src ) let fonts = grunt . file . expand ( join ( basedir , this . target ) ) let getText = opts . getText !== undefined ? opts . getText : ( content ) => html2text . fromString ( content ) let type = 'woff' , typeOpts = true // check if more than one output option is specified if ( ! atMostDefined ( data , 1 , 'woff' , 'css' ) ) throw new Error ( 'Multiple output type defined!' ) // set type, typeOpts if ( data . woff !== undefined ) { type = 'woff' } if ( data . css !== undefined ) { type = 'css' ; typeOpts = data . css } // string of unique characters(glyphs) to be included in minimized font let uniqGlyphs = src . map ( path => grunt . file . read ( path ) ) . map ( getText ) . join ( ) . split ( '' ) . sort ( ) . reduce ( nodup ( ) , [ ] ) // remove duplicate characters . join ( '' ) fonts . forEach ( path => { // create output ArrayBuffer let ttf = readToTTF ( path ) let stripped = glyphStrip ( ttf , uniqGlyphs ) let output = ttfToOutput ( stripped , type , typeOpts ) // solve dest path, write output let destPath = join ( destdir , getOutputFilename ( path , type ) ) grunt . file . write ( destPath , toBuffer ( output ) ) // output information grunt . log . writeln ( basename ( path ) + ' => ' + type + ' ' + chalk . green ( stripped . glyf . length ) + ' glyphs, ' + chalk . green ( output . byteLength ) + ' bytes' ) } ) }
grunt task function
grunt task function