Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kdydesign/fontagon
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.5
Choose a base ref
...
head repository: kdydesign/fontagon
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.0.6
Choose a head ref
  • 3 commits
  • 11 files changed
  • 1 contributor

Commits on Apr 22, 2020

  1. docs: update usage

    kdydesign committed Apr 22, 2020
    Copy the full SHA
    780dd5f View commit details
  2. Copy the full SHA
    fe4cba4 View commit details
  3. chore(release): 1.0.6

    kdydesign committed Apr 22, 2020
    Copy the full SHA
    7a40b5f View commit details
Showing with 117 additions and 40 deletions.
  1. +7 −0 CHANGELOG.md
  2. +51 −3 README.md
  3. +1 −1 lib/build.clear.js
  4. +2 −1 lib/build.options.js
  5. +11 −2 lib/index.js
  6. +7 −6 lib/renderer/index.js
  7. +5 −7 lib/renderer/render-fonts.js
  8. +12 −12 lib/renderer/render-style.js
  9. +16 −7 lib/utils/files.js
  10. +4 −0 lib/utils/logger.js
  11. +1 −1 package.json
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.0.6](https://github.com/kdydesign/fontagon/compare/v1.0.5...v1.0.6) (2020-04-22)


### Bug Fixes

* **lib:** modify export error ([fe4cba4](https://github.com/kdydesign/fontagon/commit/fe4cba452270646ab4c3730d1bb26aa2bd494616))

### [1.0.4](https://github.com/kdydesign/fontagon/compare/v1.0.3...v1.0.4) (2020-04-22)

### [1.0.2](https://github.com/kdydesign/fontagon/compare/v1.0.1...v1.0.2) (2020-04-22)
54 changes: 51 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -15,9 +15,10 @@ It is a new and updated module that refers to [webfonts-generator](https://www.n


Features:
* Supported font formats: WOFF2, WOFF, EOT, TTF and SVG.
* Supports the product built with css, sass, less, and stylus.
* Supported font formats: `WOFF2`, `WOFF`, `EOT`, `TTF` and `SVG`.
* Supports the product built with `css`, `sass`, `less`, and `stylus`.
* Custom templates are available.
* Support for `ligature`

## Infos
- [📖 **Release Notes**](./CHANGELOG.md)
@@ -30,7 +31,11 @@ npm install fontagon
```

## Usage
Create a file to build svg.

```javascript
// index.js

const Fontagon = require('fontagon')

Fontagon({
@@ -51,6 +56,38 @@ Fontagon({
})
```

Modify package.json's npm script or run a build file generated through the nodejs.
```json
{
"scripts": {
"build:fontagon": "node build/index.js"
}
}
```

```sh
$ npm run build:fontagon
```

Now use the build output. You only need to insert the `style sheet`.

```html
<link rel="stylesheet" type="text/css" href="dist/fontagon-icons.css">
```
```javascript
import '../dist/fontagon-icons.css'
```

**Fontagon** generates svg by `class` and supports `ligature`. just put the name of the svg.

```html
<i class="fontagon-icons ft-icon">SVG FILE NAME</i>
<i class="fontagon-icons ft-icon ft-SVG FILE NAME"></i>
```

The above results are the same.


## Options

### `files`
@@ -60,20 +97,23 @@ List of SVG files.
* Default: `[]`
* *required*

<br>

### `dist`
Directory for generated font files.

* Type: `String`
* Default: `'dist/`
* Default: `'dist/'`

<br>

### `fontName`
Specify a font name and the default name for the font file.

* Type: `String`
* Default: `'fontagon-icons'`

<br>

### `style`
stylesheet file generation type.
@@ -82,6 +122,7 @@ stylesheet file generation type.
* Default: `'all'`
* options: `'css', 'sass', 'less', 'stylus'`

<br>

### `styleTemplate`
Specify a custom style template.
@@ -104,6 +145,7 @@ it is merged with the default option and processed.
}
```

<br>

### `classOptions`
Additional options for CSS templates, that extends default options.
@@ -120,27 +162,31 @@ or **'classPrefix'** as a sub class factor of the stylesheet.
}
```

<br>

### `order`
Order of `src` values in `font-face` in CSS file.

* Type: `Array`
* Default: `['eot', 'woff2', 'woff', 'ttf', 'svg']`

<br>

### `rename`
Function that takes path of file and return name of icon.

* Type: `Function`
* Default: basename of file

<br>

### `startCodepoint`
Starting codepoint. Defaults to beginning of unicode private area.

* Type: `Number`
* Default: `0xF101`

<br>

### `codepoints`
Specific codepoints for certain icons.
@@ -150,6 +196,7 @@ Icons without codepoints will have codepoints incremented from `startCodepoint`
* Type: `Object`
* Default: `{}`

<br>

### `formatOptions`
Specific per format arbitrary options to pass to the generator
@@ -172,6 +219,7 @@ format and matching generator:
- `woff` - [ttf2woff](https://github.com/fontello/ttf2woff).
- `eot` - [ttf2eot](https://github.com/fontello/ttf2eot).

<br>

### `writeFiles`
It is possible to not create files and get generated fonts in object to write them to files later.
2 changes: 1 addition & 1 deletion lib/build.clear.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ const path = require('path')
const rimraf = require('rimraf')
const { logger } = require('./utils/logger')

export function buildClean (dist) {
module.exports = function buildClean (dist) {
rimraf.sync(path.resolve(__dirname, `../${dist}/*`))
logger.log('🚽 Cleaned build artifacts.\n')
}
3 changes: 2 additions & 1 deletion lib/build.options.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const path = require('path')

/**
* template
* Default Template Options
*
* @returns {{css: *, scss: *, html: *}}
*/
function getTemplates () {
13 changes: 11 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
/**
* Fontagon
*
* Dev.DY <kdydesign@gmail.com>
* issue: https://github.com/kdydesign/fontagon/issues
*
* MIT Lisence
*/

const path = require('path')
const _ = require('lodash')

const { defaultOpts, classOptions } = require('./build.options')
const { writeResult, flattenFiles } = require('./utils/files')
const { buildClean } = require('./build.clear')
const buildClean = require('./build.clear')
const { renderFonts } = require('./renderer')
const { name, version } = require('../package.json')

@@ -41,7 +50,7 @@ function initFontagon (_opts) {
}

/**
* Fontagon
* Create a new instance of Fontagon
*
* @param _opts
* @returns {Promise<unknown>}
13 changes: 7 additions & 6 deletions lib/renderer/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import renderFonts from './render-fonts.js'
import renderCss from './render-style.js'
/**
* Render module exported
*/

export {
renderFonts,
renderCss
}
const renderFonts = require('./render-fonts.js')
const renderCss = require('./render-style.js')

module.exports = { renderFonts, renderCss }
12 changes: 5 additions & 7 deletions lib/renderer/render-fonts.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Create a font file with svg
*/

const fs = require('fs')
const Q = require('q')
const _ = require('lodash')
@@ -95,13 +99,7 @@ const generators = {
}
}

/**
* renderFonts
*
* @param _opts
* @returns {*|Promise<void>|PromiseLike<any>|Promise<any>}
*/
export default function (_opts) {
module.exports = function (_opts) {
logger.log(`${logColor.bgRed.black('[BUILD: FONT]')} font name is ${logColor.cyan(_opts.fontName)}.`)

const genTasks = {}
24 changes: 12 additions & 12 deletions lib/renderer/render-style.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Render as style sheet
*/

const fs = require('fs')
const crypto = require('crypto')
const handlebars = require('handlebars')
@@ -7,10 +11,10 @@ const _ = require('lodash')
const { logger, logColor } = require('../utils/logger')

/**
* calcHash
* creating hash
*
* @param options
* @returns {PromiseLike<ArrayBuffer>}
* @returns {string}
*/
function calcHash (options) {
const hash = crypto.createHash('md5')
@@ -25,11 +29,12 @@ function calcHash (options) {
}

/**
* makeSrc
* Create a font path for style sheet
*
* @param options
* @param styleCode
* @param urls
* @returns {string}
* @returns {any}
*/
function makeSrc (options, styleCode, urls) {
const templates = {
@@ -57,9 +62,10 @@ function makeSrc (options, styleCode, urls) {
}

/**
* makeCtx
* Create content codepoint
*
* @param options
* @param styleCode
* @param urls
* @returns {*}
*/
@@ -99,13 +105,7 @@ function makeUrls (options) {
return _.zipObject(options.types, urls)
}

/**
* export
* @param options
* @param urls
* @returns {*}
*/
export default function (options, styleCode) {
module.exports = function (options, styleCode) {
const styleSheet = options.styleTemplate[styleCode]

logger.log(`${logColor.bgBlue.black(`[BUILD: ${styleCode.toUpperCase()}]`)} Path of CSS template: ${logColor.cyan(styleSheet)}`)
23 changes: 16 additions & 7 deletions lib/utils/files.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Create font file and style sheet file
*/

const fs = require('fs')
const path = require('path')
const _ = require('lodash')
@@ -7,10 +11,10 @@ const mkdirp = require('mkdirp')
const { renderCss } = require('../renderer')

/**
* writeFile
* Create File
*
* @param content
* @param dest
* @param dist
*/
function writeFile (content, dist) {
mkdirp.sync(path.dirname(dist))
@@ -19,7 +23,7 @@ function writeFile (content, dist) {
}

/**
* writeStyle
* creating style sheet file
*
* @param options
*/
@@ -40,12 +44,12 @@ function writeStyle (options) {
}

/**
* writeResult
* Entry point for file generation
*
* @param fonts
* @param options
*/
export function writeResult (fonts, options) {
function writeResult (fonts, options) {
_.forEach(fonts, (content, type) => {
const filepath = path.join(options.dist, `${options.fontName}.${type}`)

@@ -64,12 +68,12 @@ export function writeResult (fonts, options) {
}

/**
* flattenFiles
* Process files from 'files'
*
* @param options
* @returns {[]}
*/
export function flattenFiles (options) {
function flattenFiles (options) {
const files = []

options.files.forEach((path) => {
@@ -78,3 +82,8 @@ export function flattenFiles (options) {

return files
}

module.exports = {
writeResult,
flattenFiles
}
4 changes: 4 additions & 0 deletions lib/utils/logger.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Modules related to Logs
*/

const consola = require('consola')
const { bgBlue, bgRed, cyan, red, blue } = require('chalk')

Loading