Skip to content

Commit

Permalink
feat(icon): allow reading icon from assetc/icon.png (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed Feb 7, 2019
1 parent 4afaa67 commit 9e0fde3
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions packages/icon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,37 @@ module.exports = function nuxtIcon (options) {
this.nuxt.hook('build:before', hook)
}

const defaults = {
iconSrc: null,
iconFileName: 'icon.png',
sizes: [64, 120, 144, 152, 192, 384, 512],
targetDir: 'icons'
}

function generateIcons (moduleOptions) {
// Combine sources
const defaults = {
iconSrc: null,
iconFileName: 'icon.png',
sizes: [64, 120, 144, 152, 192, 384, 512],
targetDir: 'icons'
}
const options = Object.assign({}, defaults, this.options.icon, moduleOptions)
const iconSrc = options.iconSrc || path.resolve(this.options.srcDir, this.options.dir.static, options.iconFileName)

const { publicPath } = getRouteParams(this.options)

// Resolve iconSrc
let iconSrc

const iconSearchPath = [
options.iconSrc,
path.resolve(this.options.srcDir, this.options.dir.static, options.iconFileName),
path.resolve(this.options.srcDir, this.options.dir.assets, options.iconFileName)
]

for (const p of iconSearchPath) {
if (existsSync(p)) {
iconSrc = p
break
}
}

// Ensure icon file exists
if (!existsSync(iconSrc)) {
/* eslint-disable no-console */
return
}

Expand Down

0 comments on commit 9e0fde3

Please sign in to comment.